Skip to content

Commit 1acb7fd

Browse files
committed
Revert "fix(deps): use named parameters"
This reverts commit 149a708.
1 parent 149a708 commit 1acb7fd

File tree

1 file changed

+72
-73
lines changed

1 file changed

+72
-73
lines changed

socket.js

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,93 @@
66
*/
77

88
angular.module('btford.socket-io', []).
9-
provider('socketFactory', function() {
9+
provider('socketFactory', function () {
1010

1111
'use strict';
1212

1313
// when forwarding events, prefix the event name
1414
var defaultPrefix = 'socket:',
15-
ioSocket;
15+
ioSocket;
1616

1717
// expose to provider
18-
this.$get = ['$rootScope', '$timeout',
19-
function($rootScope, $timeout) {
18+
this.$get = function ($rootScope, $timeout) {
2019

21-
var asyncAngularify = function(socket, callback) {
22-
return callback ? function() {
23-
var args = arguments;
24-
$timeout(function() {
25-
callback.apply(socket, args);
26-
}, 0);
27-
} : angular.noop;
28-
};
20+
var asyncAngularify = function (socket, callback) {
21+
return callback ? function () {
22+
var args = arguments;
23+
$timeout(function () {
24+
callback.apply(socket, args);
25+
}, 0);
26+
} : angular.noop;
27+
};
2928

30-
return function socketFactory(options) {
31-
options = options || {};
32-
var socket = options.ioSocket || io.connect();
33-
var prefix = options.prefix || defaultPrefix;
34-
var defaultScope = options.scope || $rootScope;
29+
return function socketFactory (options) {
30+
options = options || {};
31+
var socket = options.ioSocket || io.connect();
32+
var prefix = options.prefix || defaultPrefix;
33+
var defaultScope = options.scope || $rootScope;
3534

36-
var addListener = function(eventName, callback) {
37-
socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
38-
};
39-
40-
var addOnceListener = function(eventName, callback) {
41-
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
42-
};
35+
var addListener = function (eventName, callback) {
36+
socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
37+
};
4338

44-
var wrappedSocket = {
45-
on: addListener,
46-
addListener: addListener,
47-
once: addOnceListener,
39+
var addOnceListener = function (eventName, callback) {
40+
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
41+
};
4842

49-
emit: function(eventName, data, callback) {
50-
var lastIndex = arguments.length - 1;
51-
var callback = arguments[lastIndex];
52-
if (typeof callback == 'function') {
53-
callback = asyncAngularify(socket, callback);
54-
arguments[lastIndex] = callback;
55-
}
56-
return socket.emit.apply(socket, arguments);
57-
},
43+
var wrappedSocket = {
44+
on: addListener,
45+
addListener: addListener,
46+
once: addOnceListener,
5847

59-
removeListener: function(ev, fn) {
60-
if (fn && fn.__ng) {
61-
arguments[1] = fn.__ng;
62-
}
63-
return socket.removeListener.apply(socket, arguments);
64-
},
48+
emit: function (eventName, data, callback) {
49+
var lastIndex = arguments.length - 1;
50+
var callback = arguments[lastIndex];
51+
if(typeof callback == 'function') {
52+
callback = asyncAngularify(socket, callback);
53+
arguments[lastIndex] = callback;
54+
}
55+
return socket.emit.apply(socket, arguments);
56+
},
6557

66-
removeAllListeners: function() {
67-
return socket.removeAllListeners.apply(socket, arguments);
68-
},
58+
removeListener: function (ev, fn) {
59+
if (fn && fn.__ng) {
60+
arguments[1] = fn.__ng;
61+
}
62+
return socket.removeListener.apply(socket, arguments);
63+
},
6964

70-
disconnect: function(close) {
71-
return socket.disconnect(close);
72-
},
65+
removeAllListeners: function() {
66+
return socket.removeAllListeners.apply(socket, arguments);
67+
},
7368

74-
// when socket.on('someEvent', fn (data) { ... }),
75-
// call scope.$broadcast('someEvent', data)
76-
forward: function(events, scope) {
77-
if (events instanceof Array === false) {
78-
events = [events];
79-
}
80-
if (!scope) {
81-
scope = defaultScope;
82-
}
83-
events.forEach(function(eventName) {
84-
var prefixedEvent = prefix + eventName;
85-
var forwardBroadcast = asyncAngularify(socket, function(data) {
86-
scope.$broadcast(prefixedEvent, data);
87-
});
88-
scope.$on('$destroy', function() {
89-
socket.removeListener(eventName, forwardBroadcast);
90-
});
91-
socket.on(eventName, forwardBroadcast);
92-
});
93-
}
94-
};
69+
disconnect: function (close) {
70+
return socket.disconnect(close);
71+
},
9572

96-
return wrappedSocket;
97-
};
73+
// when socket.on('someEvent', fn (data) { ... }),
74+
// call scope.$broadcast('someEvent', data)
75+
forward: function (events, scope) {
76+
if (events instanceof Array === false) {
77+
events = [events];
78+
}
79+
if (!scope) {
80+
scope = defaultScope;
81+
}
82+
events.forEach(function (eventName) {
83+
var prefixedEvent = prefix + eventName;
84+
var forwardBroadcast = asyncAngularify(socket, function (data) {
85+
scope.$broadcast(prefixedEvent, data);
86+
});
87+
scope.$on('$destroy', function () {
88+
socket.removeListener(eventName, forwardBroadcast);
89+
});
90+
socket.on(eventName, forwardBroadcast);
91+
});
92+
}
9893
};
99-
}]);
94+
95+
return wrappedSocket;
96+
};
97+
};
98+
});

0 commit comments

Comments
 (0)