Remove the Publisher mixin.
This commit is contained in:
@@ -46,29 +46,47 @@ var API = {
|
||||
},
|
||||
|
||||
addEventListener: function(type, listener, useCapture) {
|
||||
this.bind(type, listener);
|
||||
this._subscribers = this._subscribers || {};
|
||||
var list = this._subscribers[eventType] = this._subscribers[eventType] || [];
|
||||
list.push([listener, context]);
|
||||
},
|
||||
|
||||
removeEventListener: function(type, listener, useCapture) {
|
||||
this.unbind(type, listener);
|
||||
if (!this._subscribers || !this._subscribers[eventType]) return;
|
||||
|
||||
if (!listener) {
|
||||
delete this._subscribers[eventType];
|
||||
return;
|
||||
}
|
||||
var list = this._subscribers[eventType],
|
||||
i = list.length;
|
||||
|
||||
while (i--) {
|
||||
if (listener !== list[i][0]) continue;
|
||||
if (context && list[i][1] !== context) continue;
|
||||
list.splice(i,1);
|
||||
}
|
||||
},
|
||||
|
||||
dispatchEvent: function(event) {
|
||||
event.target = event.currentTarget = this;
|
||||
event.eventPhase = API.Event.AT_TARGET;
|
||||
|
||||
this.trigger(event.type, event);
|
||||
if (this['on' + event.type])
|
||||
this['on' + event.type](event);
|
||||
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
eventType = args.shift();
|
||||
|
||||
if (!this._subscribers || !this._subscribers[eventType]) return;
|
||||
|
||||
this._subscribers[eventType].forEach(function(listener) {
|
||||
listener[0].apply(listener[1], args);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var Publisher = require('./publisher');
|
||||
for (var key in Publisher)
|
||||
API[key] = Publisher[key];
|
||||
|
||||
|
||||
var Event = function(eventType, options) {
|
||||
this.type = eventType;
|
||||
for (var key in options)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
var Publisher = {
|
||||
countListeners: function(eventType) {
|
||||
if (!this._subscribers || !this._subscribers[eventType]) return 0;
|
||||
return this._subscribers[eventType].length;
|
||||
},
|
||||
|
||||
bind: function(eventType, listener, context) {
|
||||
this._subscribers = this._subscribers || {};
|
||||
var list = this._subscribers[eventType] = this._subscribers[eventType] || [];
|
||||
list.push([listener, context]);
|
||||
},
|
||||
|
||||
unbind: function(eventType, listener, context) {
|
||||
if (!this._subscribers || !this._subscribers[eventType]) return;
|
||||
|
||||
if (!listener) {
|
||||
delete this._subscribers[eventType];
|
||||
return;
|
||||
}
|
||||
var list = this._subscribers[eventType],
|
||||
i = list.length;
|
||||
|
||||
while (i--) {
|
||||
if (listener !== list[i][0]) continue;
|
||||
if (context && list[i][1] !== context) continue;
|
||||
list.splice(i,1);
|
||||
}
|
||||
},
|
||||
|
||||
trigger: function() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
eventType = args.shift();
|
||||
|
||||
if (!this._subscribers || !this._subscribers[eventType]) return;
|
||||
|
||||
this._subscribers[eventType].forEach(function(listener) {
|
||||
listener[0].apply(listener[1], args);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Publisher;
|
||||
|
||||
Reference in New Issue
Block a user