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

Add Events#listenToOnce #2049

Merged
merged 3 commits into from
Jan 25, 2013
Merged

Conversation

gsamokovarov
Copy link
Contributor

As per discussion in #2045, I implemented oneTimeListenTo, an inversion-of-control version of once. @caseywebdev and @tgriesser voted for the name listenToOnce, but I went with oneTimeListenTo as it sounds clearer to me, but its up for discussion. If you guys like listenToOnce or some other name, I can change it.

Edit:

Changed the name from oneTimeListenTo to onceListenTo. Its still up for discussion, though.

Edit:

Changed to listenToOnce as per the comments.

@philfreo
Copy link
Contributor

I'd prefer listenToOnce (or even onceListenTo) so it parallels once, rather than using "oneTime"

@AjaxSolutions
Copy link

Using 'once' in the method name is more consistent and shorter.

@tbranyen
Copy link
Collaborator

Here we go again with a thread about naming, but I'd prefer listenToOnce :-p

@gsamokovarov
Copy link
Contributor Author

Fair enough. I like onceListenTo its easier to type and it keeps the once reference in there.

@tgriesser
Copy link
Collaborator

I'm with @tbranyen and @philfreo on listenToOnce

@gsamokovarov
Copy link
Contributor Author

I still kinda want to keep the to at the end. Its consistent with how listenTo reads in code. But if most of you like listenToOnce, so be it 😄

@akre54
Copy link
Collaborator

akre54 commented Dec 29, 2012

also pitching in with @tbranyen and @philfreo. I think the semantics of listenToOnce aren't that awkward (or are at least much less awkward than onceListenTo)

@gsamokovarov
Copy link
Contributor Author

Have to agree with you. onceListenTo sounds kind of ambiguous. Will wait for the other guys to chime in before amending the last commit.

@caseywebdev
Copy link
Collaborator

👍 listenToOnce

@eastridge
Copy link
Contributor

+1 listenToOnce

@gsamokovarov
Copy link
Contributor Author

listenToOnce it is 😄

@philfreo
Copy link
Contributor

👍 on this (or some other way to easily clean up once events)

@Yahasana
Copy link

listenOnce 💯

@caseywebdev
Copy link
Collaborator

It needs the To to imply the first argument 😉

@grydstedt
Copy link

+1 listenToOnce!

@gsamokovarov
Copy link
Contributor Author

Rebased this one, so it can be applied cleanly to the current tree.

@tgriesser
Copy link
Collaborator

@jashkenas - any opinion on this one? It does make the Event listeners symmetrical...

@jashkenas
Copy link
Owner

Fun implementation and nice API symmetry, but I'm a little concerned if anyone will actually find it useful. Would y'all use this?

@philfreo
Copy link
Contributor

@jashkenas yes -- with listenTo now it's much more rare for me to have to manually cleanup listeners in View#remove now. But there's no automatic way to do that with once events (which I do use), and this fixes that

@dgbeck
Copy link

dgbeck commented Jan 18, 2013

I have not yet found occation for "once" events. A chained interaction perhaps where the second part depends on first, like choosing item from popup menu?

@akre54
Copy link
Collaborator

akre54 commented Jan 18, 2013

I have once in a number of places where I want the callback removed after the event has been triggered, before the once event was introduced, I had at least a dozen places in code with code like

foo.on('closePopup', function() {
  doSomething();
  foo.off('closePopup')
});

a listenToOnce event would be a great help for me.

@tbranyen
Copy link
Collaborator

Found myself needing this today:

this.listenToOnce(this.filters, "change", function() {
  this.filters.add(new Filter.Model());
});

I don't want to add a new filter every single time one has changed, I only ever add one once.

@ricogallo
Copy link

@jashkenas I'm going to use this like that:

this.listenToOnce(this.model, signedEvent, function() {
  // do stuff;
});

👍

jashkenas added a commit that referenced this pull request Jan 25, 2013
@jashkenas jashkenas merged commit 4d6b813 into jashkenas:master Jan 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.