adobe-webplatform / eve

Custom events…
http://dmitry.baranovskiy.com/eve/
Apache License 2.0
316 stars 110 forks source link

simpler 'unbind' with scope (string) instead of function #3

Open gr2m opened 12 years ago

gr2m commented 12 years ago

Hey Dimitry,

I do highly respect your JavaScripts and maybe my suggestion is nonsense, I'd be happy for a hint what you would do.

Here's my scenario:

I have several models that subscribe to events from a socket. With eve, the binding would look like:

eve.on('change/Model_xyz', function() { ... })

There are tons of bindings all around the place. My understanding is that I could not simply unbind the particular event above, I'd need to wrap the anonymous function into some method (e.g. Model.make_stuff) and then pass this method when I do an unbind, correct?

eve.unbind('change/Model_xyz', Model.make_stuff)

I wonder if it would make sense to extend the implementation of eve, so that I could use a simple string to scope a bind/unbind. It my example, it would look like:

eve.on('change/Model_xyz', function() { ... }, 'unique_id_here')
eve.unbind('change/Model_xyz', 'unique_id_here')

What do you think? Does that make any sense to you?