Adds onFirstListener and onNoListener callbacks#4040
Closed
DomBlack wants to merge 1 commit intojashkenas:masterfrom
Closed
Adds onFirstListener and onNoListener callbacks#4040DomBlack wants to merge 1 commit intojashkenas:masterfrom
DomBlack wants to merge 1 commit intojashkenas:masterfrom
Conversation
These callbacks allow anything extending `Backbones.Events` to be notified when something starts listening to it, and when nothing is left listening to it. Because of `internalOn` this is hard to implement in user land. The use case for this is if you had a Model presenting the output of an expensive continuous calculation (say real time Stock Prices or a timer). The `onFirstListener` function can be used to start your expensive calculation, as you only care about it while the something is listening to changes in it. When that item stops listening to changes in it, `onNoListeners` will trigger, allowing you to clean up your code (unsubscribe the stock price, or stop the timer or even stop listening to another Event).
1ad8931 to
350b816
Compare
Collaborator
|
Thanks but no thanks. Feel free to do this in your own project if you need it |
Author
|
NP. I have but I ended up having to do this in Backbone because of #3615 once that PR is merged, this can be done in user land. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These callbacks allow anything extending
Backbones.Eventsto benotified when something starts listening to it, and when nothing
is left listening to it.
Because of
internalOnthis is hard to implement in user land.Use Case
The use case for this is if you had a Model presenting the output of
an expensive continuous calculation (say real time Stock Prices or
a timer).
The
onFirstListenerfunction can be used to start your expensivecalculation, as you only care about it while the something is listening
to changes in it.
When that item stops listening to changes in it,
onNoListenerswilltrigger, allowing you to clean up your code (unsubscribe the stock price,
or stop the timer or even stop listening to another Event).