Closed pgherveou closed 12 years ago
@pgherveou There is not currently. I am still figuring out what kind of unobserving there should be. I have been situations where I want to effectively block the channel while making changes to it and it unblocks when a user confirms the changes (e.g. via a save button). Otherwise changes would be happening automatically under the hood, but those changes may be unconfirmed.
What scenarios would you use this functionality? I realize it needs to exist, but I am just mulling over a proper implementation.
Well actually I didn't really need it in my last case But let's say you have a list of user and a detail view where you can edit user properties. You could use Synapse to bind the current model to the form, but every time you pick a user in a list you probably want to unbind current model before observing a new one. what do you think ?
Yep, that is a clear use case (if fact I have done that plenty of times before using jQuery..). Thanks.
Also.. please check out the new docs I have been writing up: http://bruth.github.com/synapse/docs/ They still need a lot of work, but it is much more clear as what is going on.
very nice, good job I let you know if I find some mistypings
So my first pass for an API looks like this:
stopObserving
- stops observing from all subjects (unbinds all event handlers under the hood)pauseObserving
- pauses observing from all subjects (keeps the event handlers bound)resumeObserving
- resumes any paused observingsThere are equivalent methods for notifiers (e.g. stopNotifying
). By default, these methods are applied to all of their corresponding objects. To target a specific object, simply pass in a Synapse object representing the target. A test from the suite.
var input = new Synapse('<input />');
var span = new Synapse('<span />');
var h1 = new Synapse('<h1 />');
span.observe(input);
h1.observe(input);
input.set('value', 'hello world!');
// mimic the event
input.raw.trigger('keyup');
// ensure the data propagated
equal(span.get('text'), 'hello world!');
// pause observing
span.pauseObserving();
input.set('value', 'foobar');
// mimic the event
input.raw.trigger('keyup');
// h1 still updates
equal(h1.get('text'), 'foobar');
equal(span.get('text'), 'hello world!');
// resume observing of all weak refs
span.resumeObserving();
input.pauseNotifying();
// mimic the event
input.raw.trigger('keyup');
// ensure the value still hasn't changed
equal(span.get('text'), 'hello world!');
input.resumeNotifying();
// mimic the event
input.raw.trigger('keyup');
// the value has now updated
equal(span.get('text'), 'foobar');
// detach all event handlers
span.stopObserving();
equal(input.raw.data('events'), undefined);
Looks good Waiting for the commits !
Implemented in 899e763c16
I see there is a offEventHandler in the hooks modules But is there any public api available at the moment to unobserve a Synapsed object ?