mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Renaming fire to emit and making a copy of events first (thanks @fjakobs)
This commit is contained in:
@@ -99,14 +99,15 @@
|
||||
return this;
|
||||
};
|
||||
|
||||
Socket.prototype.fire = function(name, args){
|
||||
if (name in this._events){
|
||||
for (var i = 0, ii = this._events[name].length; i < ii; i++)
|
||||
this._events[name][i].apply(this, args === undefined ? [] : args);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Socket.prototype.emit = function(name, args){
|
||||
if (name in this._events){
|
||||
var events = this._events[name].concat();
|
||||
for (var i = 0, ii = events.length; i < ii; i++)
|
||||
events[i].apply(this, args === undefined ? [] : args);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Socket.prototype.removeEvent = function(name, fn){
|
||||
if (name in this._events){
|
||||
for (var a = 0, l = this._events[name].length; a < l; a++)
|
||||
@@ -137,11 +138,11 @@
|
||||
this.connecting = false;
|
||||
this._doQueue();
|
||||
if (this.options.rememberTransport) this.options.document.cookie = 'socketio=' + encodeURIComponent(this.transport.type);
|
||||
this.fire('connect');
|
||||
this.emit('connect');
|
||||
};
|
||||
|
||||
Socket.prototype._onMessage = function(data){
|
||||
this.fire('message', [data]);
|
||||
this.emit('message', [data]);
|
||||
};
|
||||
|
||||
Socket.prototype._onDisconnect = function(){
|
||||
@@ -149,9 +150,11 @@
|
||||
this.connected = false;
|
||||
this.connecting = false;
|
||||
this._queueStack = [];
|
||||
if (wasConnected) this.fire('disconnect');
|
||||
if (wasConnected) this.emit('disconnect');
|
||||
};
|
||||
|
||||
Socket.prototype.fire = Socket.prototype.emit;
|
||||
|
||||
Socket.prototype.addListener = Socket.prototype.addEvent = Socket.prototype.addEventListener = Socket.prototype.on;
|
||||
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user