uzairfarooq / arrive

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

Fire only once, total #79

Open BawdyInkSlinger opened 3 years ago

BawdyInkSlinger commented 3 years ago

I don't think the { onceOnly: boolean } option works the way i want. I think it applies to each element it finds in the selector. I don't want this, I want something that I don't think the library can do: I want the observer to fire only once, regardless of how many elements I set it on.

e.g.,

$(document).arrive("li", { fireOnce: true}, function() {
   // tell me the FIRST TIME a li element shows up.
});

This is useful because I don't want to fire it until a li is visible on the page, but I also don't want to run the body of the function more than once.

Honestly, this and a lot of other useful features could be used if the API let you pass in a jquery instead of a string.

$(document).arrive($("li").first(), function() {
   // tell me the FIRST TIME a li element shows up.
});

Of course, the library is a black box to me, and I don't know if that's a feasible implementation.

T35R6braPwgDJKq commented 3 years ago

I have the same problem as well

document.arrive(".class", {fireOnAttributesModification:true,existing:true,onceOnly:true}, function() {
    document.unbindArrive(".class")
    console.log('only called once')
});

Unfortunately it is called for each element of class "class"

jsabrooke commented 3 years ago

I found this because I wanted to make sure that it was fired once for each element matching the selector.

The suggestion would be a non-obvious breaking change if changing the functionality of onceOnly, so if implemented it should be a new parameter, or at least make it an obvious breaking change by renaming onceOnly to onceOnlyPerElement and adding a new parameter for the new functionality.

DATEx2 commented 8 months ago

Any news with this?