Created
February 1, 2012 06:03
-
-
Save sleepynate/1715403 to your computer and use it in GitHub Desktop.
backbone events wat
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
| it("derps when using a space in an event name", function() { | |
| var callback = jasmine.createSpy('-Custom Event Callback-'); | |
| obj.bind('all', callback); | |
| obj.trigger("foo bar"); | |
| expect(callback.callCount).toBe(1); | |
| expect(callback.mostRecentCall.args[0]).toBe('foo bar'); | |
| }); |
In the case of
person.bind("change:name change:location", callback);the callback will fire two times and the arguments will contain the model and changed value of each field
ie:
callback(model, name);
callback(model, location);
Author
Yea check out the expectation in larry's project: https://github.com/larrymyers/backbone-koans/blob/master/js/koans/aboutEvents.js#L66
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, so binding works with space-separated events but triggering is still a singular operation. That makes sense because arguments from .trigger are passed along to the function that was bound. Triggering two events at once doesn't seem like it would be something that would be frequently done and even if you wanted to you would have no way to determine which arguments were passed to the callback. (By convention backbone passes the model instance AND the changed attribute[singular] to the callback).