Comments (7)
Flexibility is what I had in mind. I like the idea of adding both the once
and off
functions rather than one or the other.
I think i'll start working on it soon. Appreciate the input!
from ready.
As it stands now, no there is not a way to disconnect the ready listener, sorry.
I would suggest using a class name or data attribute unique to the element(s) that you are observing. Once the listener is dispatched for that particular selector, just ensure no other elements matching that selector are added to the DOM. That should give you the result you're looking for.
I will, however, leave this issue open as I consider adding this functionality.
from ready.
Great, the unique ID was my thought too, though I wasn't sure whether there might be a perceptible cost to having an increasing number of open ready()'sβeven if I know nothing else will emerge in the DOM to trigger them.
Another way to think about it would be to have a flag that makes a ready a one use only (e.g. finds first instance of the element, triggers the callback, and disconnects).
from ready.
I wouldn't worry about performance, only one mutation observer is used no matter how many times you open a ready listener. Although it's not ideal to have the mutation observer open when no more ready callbacks are expected.
I don't mind your suggestion, maybe something like ready.once
for one offs would be an easy solution? I was also thinking ready.off('.foo')
to explicitly remove a listener for a particular selector might be a good idea?
from ready.
I see on the single observer; very nice. ready.off('foo')
is probably more flexible, as it allows 1-n uses?
from ready.
Of course! Thank you for the code. I had my own clunky MutationObserver going, but you made it elegant and simple to use.
from ready.
Made the change, it's not quite what we discussed here, instead I opted for a simpler solution. Now, the ready function returns a function that you can call to remove the listener. Refer to the updated readme for an example.
Thanks again.
from ready.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ready.