You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docsource/07_Events.md
+31-21Lines changed: 31 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,37 @@ An implementation is optimized for the large amount of relatively small subscrip
8
8
9
9
Events is a mixin, giving the object the ability to bind and trigger custom named events. Events do not have to be declared before they are bound, and may take passed arguments.
10
10
11
+
#### eventsSource.trigger(event, [*args])
12
+
13
+
Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.
14
+
15
+
### High-level listening API
16
+
17
+
All high-level event subscriptions are stopped automatically on the listener's disposal, and thus does not introduce memory leaks.
18
+
19
+
This is the preferable listening API and must be used in all application code.
20
+
21
+
#### listener.listenTo(other, event, callback)
22
+
Tell an object to listen to a particular event on an other object. The advantage of using this form, instead of other.on(event, callback, object), is that listenTo allows the object to keep track of the events, and they can be removed all at once later on. The callback will always be called with object as context.
Tell an object to stop listening to events. Either call stopListening with no arguments to have the object remove all of its registered callbacks ... or be more precise by telling it to remove just the events it's listening to on a specific object, or a specific event, or just a specific callback.
Just like listenTo, but causes the bound callback to fire only once before being removed.
37
+
38
+
### Low-level listening API
39
+
40
+
This API is more efficient but requires manual action to stop the subscribtion. Must be used with care.
41
+
11
42
#### eventSource.on(event, callback, [context])
12
43
13
44
Bind a callback function to an object. The callback will be invoked whenever the event is fired. If you have a large number of different events on a page, the convention is to use colons to namespace them: "poll:start", or "change:selection". The event string may also be a space-delimited list of several events...
@@ -51,30 +82,9 @@ Remove a previously-bound callback function from an object. If no context is spe
51
82
52
83
Note that calling `model.off()`, for example, will indeed remove all events on the model — including events that Backbone uses for internal bookkeeping.
53
84
54
-
#### eventsSource.trigger(event, [*args])
55
-
56
-
Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.
Just like on, but causes the bound callback to fire only once before being removed. Handy for saying "the next time that X happens, do this". When multiple events are passed in using the space separated syntax, the event will fire once for every event you passed in, not once for a combination of all events
Tell an object to listen to a particular event on an other object. The advantage of using this form, instead of other.on(event, callback, object), is that listenTo allows the object to keep track of the events, and they can be removed all at once later on. The callback will always be called with object as context.
Tell an object to stop listening to events. Either call stopListening with no arguments to have the object remove all of its registered callbacks ... or be more precise by telling it to remove just the events it's listening to on a specific object, or a specific event, or just a specific callback.
0 commit comments