Skip to content

Commit 149a708

Browse files
committed
fix(deps): use named parameters
1 parent 9d9130c commit 149a708

File tree

1 file changed

+73
-72
lines changed

1 file changed

+73
-72
lines changed

socket.js

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,93 +6,94 @@
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 = function ($rootScope, $timeout) {
18+
this.$get = ['$rootScope', '$timeout',
19+
function($rootScope, $timeout) {
1920

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-
};
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+
};
2829

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;
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;
3435

35-
var addListener = function (eventName, callback) {
36-
socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
37-
};
36+
var addListener = function(eventName, callback) {
37+
socket.on(eventName, callback.__ng = asyncAngularify(socket, callback));
38+
};
3839

39-
var addOnceListener = function (eventName, callback) {
40-
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
41-
};
40+
var addOnceListener = function(eventName, callback) {
41+
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback));
42+
};
4243

43-
var wrappedSocket = {
44-
on: addListener,
45-
addListener: addListener,
46-
once: addOnceListener,
44+
var wrappedSocket = {
45+
on: addListener,
46+
addListener: addListener,
47+
once: addOnceListener,
4748

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-
},
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+
},
5758

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

65-
removeAllListeners: function() {
66-
return socket.removeAllListeners.apply(socket, arguments);
67-
},
66+
removeAllListeners: function() {
67+
return socket.removeAllListeners.apply(socket, arguments);
68+
},
6869

69-
disconnect: function (close) {
70-
return socket.disconnect(close);
71-
},
70+
disconnect: function(close) {
71+
return socket.disconnect(close);
72+
},
7273

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-
}
93-
};
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+
};
9495

95-
return wrappedSocket;
96-
};
97-
};
98-
});
96+
return wrappedSocket;
97+
};
98+
};
99+
}]);

0 commit comments

Comments
 (0)