874
edits
(Added related materials section) |
(→Modules: added observer-service module docs) |
||
| Line 144: | Line 144: | ||
The module's interface is the same as that specified in [[Labs/Jetpack/JEP/25|JEP 25]]. | The module's interface is the same as that specified in [[Labs/Jetpack/JEP/25|JEP 25]]. | ||
=== <tt>observer-service</tt> === | |||
The <tt>observer-service</tt> module provides access to the application-wide observer service singleton. | |||
For a list of common observer topics across a variety of Mozilla-based applications, see [https://developer.mozilla.org/en/Observer_Notifications Observer Notifications]. | |||
==== Observer Callbacks ==== | |||
Observer callbacks are of the following form: | |||
function callback(subject, data) { | |||
/* ... Respond to the event notification ... */ | |||
} | |||
In the above example, <tt>subject</tt> is any JavaScript object, as is <tt>data</tt>. The particulars of what the two contain are specific to the notification topic. | |||
==== Functions ==== | |||
<tt>observer-service.'''add'''(''topic'', ''callback'')</tt> | |||
Adds an observer callback to be triggered whenever a notification matching the string ''topic'' is broadcast throughout the application. | |||
<tt>observer-service.'''remove'''(''topic'', ''callback'')</tt> | |||
Unsubscribes ''callback'' from being triggered whenever a notification matching the string ''topic'' is broadcast throughout the application. | |||
<tt>observer-service.'''notify'''(''topic'', ''subject'', ''data'')</tt> | |||
Broadcasts a notification event with the given topic string, passing ''subject'' and ''data'' to all applicable observers in the application. | |||
=== <tt>timer</tt> === | === <tt>timer</tt> === | ||
edits