angular-socket-io
Advanced tools
Comparing version 0.4.1 to 0.5.0
{ | ||
"name": "angular-socket-io", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "socket.js", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -11,7 +11,14 @@ var io = { | ||
}, | ||
once: function (ev, fn) { | ||
(this._listeners[ev] = this._listeners[ev] || []).push(fn); | ||
fn._once = true; | ||
}, | ||
emit: function (ev, data) { | ||
if (this._listeners[ev]) { | ||
this._listeners[ev].forEach(function (listener) { | ||
if (listener._once) { | ||
this.removeListener(ev, listener); | ||
} | ||
listener(data); | ||
}); | ||
}.bind(this)); | ||
} | ||
@@ -18,0 +25,0 @@ }, |
{ | ||
"name": "angular-socket-io", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "socket.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
/* | ||
* @license | ||
* angular-socket-io v0.4.1 | ||
* angular-socket-io v0.5.0 | ||
* (c) 2014 Brian Ford http://briantford.com | ||
@@ -39,5 +39,10 @@ * License: MIT | ||
var addOnceListener = function (eventName, callback) { | ||
socket.once(eventName, callback.__ng = asyncAngularify(socket, callback)); | ||
}; | ||
var wrappedSocket = { | ||
on: addListener, | ||
addListener: addListener, | ||
once: addOnceListener, | ||
@@ -44,0 +49,0 @@ emit: function (eventName, data, callback) { |
/* | ||
* @license | ||
* angular-socket-io v0.4.1 | ||
* angular-socket-io v0.5.0 | ||
* (c) 2014 Brian Ford http://briantford.com | ||
* License: MIT | ||
*/ | ||
"use strict";angular.module("btford.socket-io",[]).provider("socketFactory",function(){var n="socket:";this.$get=["$rootScope","$timeout",function(t,o){var r=function(n,t){return t?function(){var r=arguments;o(function(){t.apply(n,r)},0)}:angular.noop};return function(o){o=o||{};var e=o.ioSocket||io.connect(),u=o.prefix||n,i=o.scope||t,a=function(n,t){e.on(n,t.__ng=r(e,t))},c={on:a,addListener:a,emit:function(n,t,o){var u=arguments.length-1,o=arguments[u];return"function"==typeof o&&(o=r(e,o),arguments[u]=o),e.emit.apply(e,arguments)},removeListener:function(n,t){return t&&t.__ng&&(arguments[1]=t.__ng),e.removeListener.apply(e,arguments)},forward:function(n,t){n instanceof Array==!1&&(n=[n]),t||(t=i),n.forEach(function(n){var o=u+n,i=r(e,function(n){t.$broadcast(o,n)});t.$on("$destroy",function(){e.removeListener(n,i)}),e.on(n,i)})}};return c}}]}); | ||
"use strict";angular.module("btford.socket-io",[]).provider("socketFactory",function(){var n="socket:";this.$get=["$rootScope","$timeout",function(t,o){var e=function(n,t){return t?function(){var e=arguments;o(function(){t.apply(n,e)},0)}:angular.noop};return function(o){o=o||{};var r=o.ioSocket||io.connect(),u=o.prefix||n,c=o.scope||t,i=function(n,t){r.on(n,t.__ng=e(r,t))},a=function(n,t){r.once(n,t.__ng=e(r,t))},f={on:i,addListener:i,once:a,emit:function(n,t,o){var u=arguments.length-1,o=arguments[u];return"function"==typeof o&&(o=e(r,o),arguments[u]=o),r.emit.apply(r,arguments)},removeListener:function(n,t){return t&&t.__ng&&(arguments[1]=t.__ng),r.removeListener.apply(r,arguments)},forward:function(n,t){n instanceof Array==!1&&(n=[n]),t||(t=c),n.forEach(function(n){var o=u+n,c=e(r,function(n){t.$broadcast(o,n)});t.$on("$destroy",function(){r.removeListener(n,c)}),r.on(n,c)})}};return f}}]}); |
@@ -50,2 +50,31 @@ /* | ||
describe('#once', function () { | ||
it('should apply asynchronously', function () { | ||
socket.once('event', spy); | ||
mockIoSocket.emit('event'); | ||
expect(spy).not.toHaveBeenCalled(); | ||
$timeout.flush(); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('should only run once', function () { | ||
var counter = 0; | ||
socket.once('event', function () { | ||
counter += 1; | ||
}); | ||
mockIoSocket.emit('event'); | ||
mockIoSocket.emit('event'); | ||
$timeout.flush(); | ||
expect(counter).toBe(1); | ||
}); | ||
}); | ||
describe('#emit', function () { | ||
@@ -52,0 +81,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18728
304