Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull getContentRect() into it's own module? #4

Closed
spalger opened this issue Dec 11, 2016 · 2 comments
Closed

Pull getContentRect() into it's own module? #4

spalger opened this issue Dec 11, 2016 · 2 comments

Comments

@spalger
Copy link

spalger commented Dec 11, 2016

Do you think it would make sense to expose the getContentRect() algorithm implemented here as it's own module? There seems to be a fair amount of logic related to ensuring cross-browser compatibility that I would rather not replicate.

@spalger
Copy link
Author

spalger commented Dec 11, 2016

The reason I ask, which might be accomplished a better way:

I'm trying to selectively ignore resize notifications that are caused by a specific function/block.

const eventBus = new EventEmitter();
const el = document.createElement('div');

const observer = new ResizeObserver(() => {
  if (someCondition()) {
    eventBus.emit('resize')
  }
})

observer.observe(el);

modifySizeWithoutTriggeringResize(() => {
  // modifications to the size of the element can be made within this function
  // and will not trigger a "resize" event on the event bus
  $(el).height(100);
});

In order to accomplish this I am thinking that I will:

  1. Run the function passed to modifyWithoutTriggeringResize() to completion
  2. Create an expectedContentRects map, mapping all tracked elements to their current contentRect
  3. On the next notification from the ResizeObserver, ignore any resize entry with a contentRect that matches the rect in the expectedContentRects map.
  4. If all resize entries are ignored, do not emit the "resize" event on the bus.

@spalger
Copy link
Author

spalger commented Dec 12, 2016

Decided to use the same function to get the size of the element before the notification and within the notification so that I'm not reliant on the implementation here. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant