HTML and CSS Reference
In-Depth Information
observe: observe,
hasObserver: hasObserver,
notify: notify
11.7 Observing Arbitrary Events
The current observable implementation is a little limited in that it only keeps
a single list of observers. This means that in order to observe more than one
event, observers have to determine what event occurred based on heuristics on
the data they receive. We will refactor the observable to group observers by event
names. Event names are arbitrary strings that the observable may use at its own
11.7.1 Supporting Events in observe
To support events, the observe method now needs to accept a string argument
in addition to the function argument. The new observe will take the event as its
first argument. As we already have several tests calling the observe method, we
can start by updating the test case. Add a string as first argument to any call to
observe as seen in Listing 11.42.
Listing 11.42 Updating calls to observe
TestCase("ObservableAddObserverTest", {
/* ... */
"test should store functions": function () {
/* ... */
this.observable.observe("event", observers[0]);
this.observable.observe("event", observers[1]);
/* ... */
/* ... *
TestCase("ObservableNotifyObserversTest", {
/* ... */
"test should call all observers": function () {
Search WWH ::

Custom Search