fxos-components/dom-scheduler

Attaching a 'scroll' event on more than one element doen't work

wilsonpage opened this issue · 10 comments

Attaching a 'scroll' event on more than one element doen't work

@etiennesegonzac can't look at this now. Might get a chance tomorrow. At first glance I think it's because you're using Object like Map, like object[element] = 'foo', which isn't supported.

I could swear we had a test for this...
I can probably get to it today if you're not already working on it.

Oh, looks like there might be an incomprehension.
It's supposed to add only 1 listener, and then coalesce the calls to all the handlers.
https://github.com/etiennesegonzac/dom-scheduler/blob/88ee16878124221b9ff023245c56df89bcc19cef/test/dom-scheduler-test.js#L132-L148

Do you have an issue where a direct block is not called @wilsonpage?

We don't want to add multiple listeners (from the scheduler) since we're going to coalesce the events anyway in a requestAnimationFrame, but we do want to call all the direct blocks that were attached.

I understand that we don't want to add more than one handler to each element for the same event type, but this regards adding the same handler to different elements.

In this case, the el2 hander never gets called:

scheduler.attachDirect(el1, 'scroll', ...);
scheduler.attachDirect(el2, 'scroll', ...);

Ahah, ok I read the test correctly this time :) sending a patch!

ahah, indeed, it works if you make el2 a span in your test :)
"[object HTMLDivElement]" isn't that great of a uniq key..

I'm laughing but I'm a bit ashamed, thanks for figuring out the issue and writing the test @wilsonpage ! By far the hardest part of fixing this.

I'm laughing but I'm a bit ashamed, thanks for figuring out the issue and writing the test @wilsonpage ! By far the hardest part of fixing this.

Ha, I'm sure I still owe you for the many mistakes you've caught in my code!