fakePublisher.js | |
---|---|
| |
A fake implemetation for publishing. Use only for development purpose. | var root = this
, fakePublisher;
if (typeof exports !== 'undefined') {
fakePublisher = exports;
} else {
fakePublisher = root.fakePublisher = {};
}
fakePublisher.VERSION = '0.5.0'; |
create new publisher instance | fakePublisher.createPublisher = function(options) {
return new Publisher(options);
}; |
Publisher | var Publisher = function(options) {
this.published = [];
this.subscriptions = [];
};
Publisher.prototype = { |
subscribe: subscribes for all events.
| subscribe: function(callback) {
this.subscriptions.push({callback: callback});
}, |
publish: publishes the event.
| publish: function(event) {
for (var subscriber in this.subscriptions) {
subscriber.callback(event);
}
this.published.push(event);
}
};
|