A utility object that implements the observer design pattern. It maintains a list of functions to call when an event occurs.
Required scripts
The Observer object requires:
/*{{ javascript("jslib/observer.js") }}*/
Summary
Creates and returns an Observer object.
Syntax
var observer = Observer.create();
Summary
Add a function to the list of functions to call when the event occurs. The function can only be registered once.
The functions should take a single argument, i.e. callback(data);
Using closure is useful pattern to allow additional state to be associated with the function.
Syntax
observer.subscribe(callback);
Summary
Remove a previously registered function.
Syntax
observer.unsubscribe(callback);
Summary
Remove all previously registered functions.
Syntax
observer.unsubscribeAll();
Summary
Calls all the subscribed functions with the passed in data.
Syntax
observer.notify(data);