angular-tiny-eventemitter
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "angular-tiny-eventemitter", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "dist/angular-tiny-eventemitter.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
angular.module('rt.eventemitter', []).factory('eventEmitter', function () { | ||
var key = '_listeners'; | ||
function on($scope, event, fn) { | ||
if (typeof $scope === 'string') { | ||
fn = event; | ||
event = $scope; | ||
$scope = null; | ||
var key = '$$tinyEventListeners'; | ||
function on($scope, event, fn) { | ||
if (typeof $scope === 'string') { | ||
fn = event; | ||
event = $scope; | ||
$scope = null; | ||
} | ||
if (!this[key]) { | ||
this[key] = {}; | ||
} | ||
var events = this[key]; | ||
if (!events[event]) { | ||
events[event] = []; | ||
} | ||
events[event].push(fn); | ||
var self = this; | ||
if ($scope) { | ||
$scope.$on('$destroy', function () { | ||
self.off(event, fn); | ||
}); | ||
} | ||
return this; | ||
} | ||
if (!this[key]) { | ||
this[key] = {}; | ||
function once($scope, event, fn) { | ||
if (typeof $scope === 'string') { | ||
fn = event; | ||
event = $scope; | ||
$scope = null; | ||
} | ||
var self = this; | ||
var cb = function () { | ||
fn.apply(this, arguments); | ||
self.off(event, cb); | ||
}; | ||
this.on($scope, event, cb); | ||
return this; | ||
} | ||
var events = this[key]; | ||
if (!events[event]) { | ||
events[event] = []; | ||
function off(event, fn) { | ||
if (!this[key] || !this[key][event]) { | ||
return this; | ||
} | ||
var events = this[key]; | ||
if (!fn) { | ||
delete events[event]; | ||
} else { | ||
var listeners = events[event]; | ||
var index = listeners.indexOf(fn); | ||
if (index > -1) { | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
} | ||
events[event].push(fn); | ||
var self = this; | ||
if ($scope) { | ||
$scope.$on('$destroy', function () { | ||
self.off(event, fn); | ||
}); | ||
function emit(event) { | ||
if (!this[key] || !this[key][event]) { | ||
return; | ||
} | ||
// Making a copy here to allow `off` in listeners. | ||
var listeners = this[key][event].slice(0); | ||
var params = [].slice.call(arguments, 1); | ||
for (var i = 0; i < listeners.length; i++) { | ||
listeners[i].apply(null, params); | ||
} | ||
return this; | ||
} | ||
return this; | ||
} | ||
function once($scope, event, fn) { | ||
if (typeof $scope === 'string') { | ||
fn = event; | ||
event = $scope; | ||
$scope = null; | ||
} | ||
var self = this; | ||
var cb = function () { | ||
fn.apply(this, arguments); | ||
self.off(event, cb); | ||
return { | ||
inject: function (cls) { | ||
var proto = cls.prototype || cls; | ||
proto.on = on; | ||
proto.once = once; | ||
proto.off = off; | ||
proto.emit = emit; | ||
} | ||
}; | ||
this.on($scope, event, cb); | ||
return this; | ||
} | ||
function off(event, fn) { | ||
if (!this[key] || !this[key][event]) { | ||
return this; | ||
} | ||
var events = this[key]; | ||
if (!fn) { | ||
delete events[event]; | ||
} else { | ||
var listeners = events[event]; | ||
var index = listeners.indexOf(fn); | ||
if (index > -1) { | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
} | ||
function emit(event) { | ||
if (!this[key] || !this[key][event]) { | ||
return; | ||
} | ||
// Making a copy here to allow `off` in listeners. | ||
var listeners = this[key][event].slice(0); | ||
var params = [].slice.call(arguments, 1); | ||
for (var i = 0; i < listeners.length; i++) { | ||
listeners[i].apply(null, params); | ||
} | ||
return this; | ||
} | ||
return { | ||
inject: function (cls) { | ||
var proto = cls.prototype || cls; | ||
proto.on = on; | ||
proto.once = once; | ||
proto.off = off; | ||
proto.emit = emit; | ||
} | ||
}; | ||
}); | ||
}); |
@@ -1,1 +0,1 @@ | ||
angular.module("rt.eventemitter",[]).factory("eventEmitter",function(){function a(a,b,c){"string"==typeof a&&(c=b,b=a,a=null),this[e]||(this[e]={});var d=this[e];d[b]||(d[b]=[]),d[b].push(c);var f=this;return a&&a.$on("$destroy",function(){f.off(b,c)}),this}function b(a,b,c){"string"==typeof a&&(c=b,b=a,a=null);var d=this,e=function(){c.apply(this,arguments),d.off(b,e)};return this.on(a,b,e),this}function c(a,b){if(!this[e]||!this[e][a])return this;var c=this[e];if(b){var d=c[a],f=d.indexOf(b);f>-1&&d.splice(f,1)}else delete c[a];return this}function d(a){if(this[e]&&this[e][a]){for(var b=this[e][a].slice(0),c=[].slice.call(arguments,1),d=0;d<b.length;d++)b[d].apply(null,c);return this}}var e="_listeners";return{inject:function(e){var f=e.prototype||e;f.on=a,f.once=b,f.off=c,f.emit=d}}}); | ||
angular.module("rt.eventemitter",[]).factory("eventEmitter",function(){function a(a,b,c){"string"==typeof a&&(c=b,b=a,a=null),this[e]||(this[e]={});var d=this[e];d[b]||(d[b]=[]),d[b].push(c);var f=this;return a&&a.$on("$destroy",function(){f.off(b,c)}),this}function b(a,b,c){"string"==typeof a&&(c=b,b=a,a=null);var d=this,e=function(){c.apply(this,arguments),d.off(b,e)};return this.on(a,b,e),this}function c(a,b){if(!this[e]||!this[e][a])return this;var c=this[e];if(b){var d=c[a],f=d.indexOf(b);f>-1&&d.splice(f,1)}else delete c[a];return this}function d(a){if(this[e]&&this[e][a]){for(var b=this[e][a].slice(0),c=[].slice.call(arguments,1),d=0;d<b.length;d++)b[d].apply(null,c);return this}}var e="$$tinyEventListeners";return{inject:function(e){var f=e.prototype||e;f.on=a,f.once=b,f.off=c,f.emit=d}}}); |
{ | ||
"name": "angular-tiny-eventemitter", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Tiny event emitter for Angular.JS.", | ||
@@ -24,19 +24,21 @@ "main": "dist/angular-tiny-eventemitter.js", | ||
"devDependencies": { | ||
"chai": "~1.9.0", | ||
"grunt": "~0.4.4", | ||
"grunt-bump": "0.3.1", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-concat": "~0.4.0", | ||
"grunt-contrib-jshint": "~0.10.0", | ||
"grunt-contrib-uglify": "~0.5.0", | ||
"grunt-contrib-watch": "~0.6.0", | ||
"grunt-jscs-checker": "^0.6.1", | ||
"grunt-karma": "~0.8.3", | ||
"grunt-ngmin": "0.0.3", | ||
"chai": "~3.5.0", | ||
"grunt": "~1.0.1", | ||
"grunt-bump": "~0.8.0", | ||
"grunt-contrib-clean": "~1.0.0", | ||
"grunt-contrib-concat": "~1.0.1", | ||
"grunt-contrib-jshint": "~1.0.0", | ||
"grunt-contrib-uglify": "~1.0.1", | ||
"grunt-contrib-watch": "~1.0.0", | ||
"grunt-jscs": "~2.8.0", | ||
"grunt-karma": "~2.0.0", | ||
"grunt-ng-annotate": "^2.0.2", | ||
"karma": "~0.13.22", | ||
"karma-chai": "~0.1.0", | ||
"karma-chrome-launcher": "~0.1.2", | ||
"karma-firefox-launcher": "~0.1.3", | ||
"karma-mocha": "~0.1.1", | ||
"karma-phantomjs-launcher": "~0.1.2", | ||
"mocha": "~1.18.2" | ||
"karma-chrome-launcher": "~1.0.1", | ||
"karma-firefox-launcher": "~1.0.0", | ||
"karma-mocha": "~1.0.1", | ||
"karma-phantomjs-launcher": "~1.0.0", | ||
"mocha": "~2.5.3", | ||
"phantomjs-prebuilt": "~2.1.7" | ||
}, | ||
@@ -43,0 +45,0 @@ "repository": { |
@@ -85,3 +85,3 @@ # angular-tiny-eventemitter | ||
Copyright (C) 2014 by Ruben Vermeersch <ruben@rocketeer.be> | ||
Copyright (C) 2014-2016 by Ruben Vermeersch <ruben@rocketeer.be> | ||
@@ -88,0 +88,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
Sorry, the diff of this file is not supported yet
10919
130
19