Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds onFirstListener and onNoListener callbacks #4040

Closed

Conversation

DomBlack
Copy link

@DomBlack DomBlack commented Jun 8, 2016

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.

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 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).

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).
@DomBlack DomBlack force-pushed the feature-onListenerChange branch from 1ad8931 to 350b816 Compare June 8, 2016 11:32
@akre54 akre54 added the wontfix label Jun 9, 2016
@akre54
Copy link
Collaborator

akre54 commented Jun 9, 2016

Thanks but no thanks. Feel free to do this in your own project if you need it

@akre54 akre54 closed this Jun 9, 2016
@DomBlack
Copy link
Author

DomBlack commented Jun 9, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants