uzairfarooq / arrive

Watch for DOM elements creation and removal
MIT License
869 stars 99 forks source link

unbindArrive by selector doesn't work #54

Closed Kesantielu closed 7 years ago

Kesantielu commented 7 years ago

Example: document.arrive('.some_class', {existing: true}, function () { if (some_trigger) document.unbindArrive('.some_class') }

After unbinding event still fires.

uzairfarooq commented 7 years ago

Is it possible that the if (some_trigger) statement never becomes true?

Asking because we have test cases for unbindArrive function and all those test cases are passing so either the bug occur in some very specific case or some issue with your code.

Kesantielu commented 7 years ago

I added console.log() before unbinding to make sure with some_trigger works. A record appears in the log, but arrive event fires again...

Kesantielu commented 7 years ago

While debugging I found that length of _eventsBucket is 0 when unbindArrive calling.

uzairfarooq commented 7 years ago

Hmm...thanks. Will look into it over the coming weekend. I think it might be related to synchronous callback. Can you try unbind within a timer, like this setTimeout(function (){document.unbindArrive('.some_class')}, 1)

englishextra commented 7 years ago

@Kesantielu It's very likely, that you might want to move your flag variable some_trigger in the parent scope—just to the parent scope of your current logic.