I’ve updated the Observers JS module with a number of changes. In particular, it’s now possible to specify a this object when adding an observer that is a method, so instead of doing this:
let MyObserver = {
onFoo: function(subject) {...},
onBar: function(subject) {...},
onBaz: function(subject) {...},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
observe: function(subject, topic, data) {
switch(topic) {
case "foo":
this.onFoo(subject);
break;
case "bar":
this.onBar(subject);
break;
case "baz":
this.onBaz(subject);
break;
}
}
}
Observers.add("foo", MyObserver);
Observers.add("bar", MyObserver);
Observers.add("baz", MyObserver);
You can do this:
let MyObserver = {
onFoo: function(subject) {...},
onBar: function(subject) {...},
onBaz: function(subject) {...}
}
Observers.add("foo", MyObserver.onFoo, MyObserver);
Observers.add("bar", MyObserver.onBar, MyObserver);
Observers.add("baz", MyObserver.onBaz, MyObserver);
Other changes include a couple of bug fixes and some backwards-incompatible API improvements. See the documentation for all the details (including steps to update from the previous version of the module).