Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "eev", | ||
"main": "eev.js", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/chrisdavies/eev", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -61,4 +61,9 @@ | ||
var me = this; | ||
names.split(splitter).forEach(function (name) { | ||
fn && names.split(splitter).forEach(function (name) { | ||
var list = me.events[name]; | ||
if (!list) { | ||
return; | ||
} | ||
var link = list.reg[fn._eev]; | ||
@@ -65,0 +70,0 @@ |
@@ -1,2 +0,1 @@ | ||
var Eev=function(){function e(e){this.head=new t,this.tail=new t(this.head),this.head.next=this.tail,this.linkConstructor=e,this.reg={}}function t(e,t,i){this.prev=e,this.next=t,this.fn=i||n}function n(){}function i(){this.events={}}var r=0,o=/[^\w\-]+/g;return e.prototype={insert:function(e){var n=new t(this.tail.prev,this.tail,e);return n.next.prev=n.prev.next=n,n},remove:function(e){e.prev.next=e.next,e.next.prev=e.prev}},t.prototype.run=function(e){this.fn(e),this.next&&this.next.run(e)},i.prototype={on:function(t,n){var i=this;t.split(o).forEach(function(t){var o=i.events[t]||(i.events[t]=new e),s=n._eev||(n._eev=++r);o.reg[s]||(o.reg[s]=o.insert(n))})},off:function(e,t){var n=this;e.split(o).forEach(function(e){var i=n.events[e],r=i.reg[t._eev];i.reg[t._eev]=void 0,i&&r&&i.remove(r)})},emit:function(e,t){var n=this.events[e];n&&n.head.run(t)}},i}();!function(e,t){var n=e.define;n&&n.amd?n([],t):"undefined"!=typeof module&&module.exports&&(module.exports=t())}(this,function(){return Eev}); | ||
//# sourceMappingURL=eev.min.js.map | ||
var Eev=function(){var e=0,t=/[^\w\-]+/g;function n(e){this.head=new i,this.tail=new i(this.head),this.head.next=this.tail,this.linkConstructor=e,this.reg={}}n.prototype={insert:function(e){var t=new i(this.tail.prev,this.tail,e);return t.next.prev=t.prev.next=t,t},remove:function(e){e.prev.next=e.next,e.next.prev=e.prev}};function i(e,t,n){this.prev=e,this.next=t,this.fn=n||r}i.prototype.run=function(e){this.fn(e),this.next&&this.next.run(e)};function r(){}function o(){this.events={}}return o.prototype={on:function(i,r){var o=this;i.split(t).forEach(function(t){var i=o.events[t]||(o.events[t]=new n),s=r._eev||(r._eev=++e);i.reg[s]||(i.reg[s]=i.insert(r))})},off:function(e,n){var i=this;n&&e.split(t).forEach(function(e){var t=i.events[e];if(t){var r=t.reg[n._eev];t.reg[n._eev]=void 0,t&&r&&t.remove(r)}})},emit:function(e,t){var n=this.events[e];n&&n.head.run(t)}},o}();!function(e,t){var n=e.define;n&&n.amd?n([],t):"undefined"!=typeof module&&module.exports&&(module.exports=t())}(this,function(){return Eev}); |
{ | ||
"name": "eev", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A tiny, fast, zero-dependency event emitter", | ||
"main": "eev.js", | ||
"directories": {}, | ||
"scripts": {}, | ||
"scripts": { | ||
"test": "jasmine-node test/*.spec.js", | ||
"min": "uglifyjs eev.js --source-map \"filename=eev.min.js.map\" -m -c -o eev.min.js && echo 'Minified size' && cat eev.min.js | gzip -9f | wc -c" | ||
}, | ||
"repository": { | ||
@@ -27,9 +30,6 @@ "type": "git", | ||
"homepage": "https://github.com/chrisdavies/eev", | ||
"scripts": { | ||
"test": "jasmine-node test/*.spec.js", | ||
"min": "uglifyjs eev.js --source-map eev.min.js.map -m -c -o eev.min.js && echo 'Minified size' && cat eev.min.js | gzip -9f | wc -c" | ||
}, | ||
"devDependencies": { | ||
"jasmine-node": "^1.14.5" | ||
"jasmine-node": "^1.14.5", | ||
"uglify-js": "^3.3.4" | ||
} | ||
} |
@@ -48,2 +48,25 @@ (function (Eev) { | ||
it('Allows removal of invalid handlers', function () { | ||
var e = new Eev(); | ||
e.on('go', function (data) { | ||
expect(data).toEqual('hi'); | ||
}); | ||
function nope () { | ||
throw new Error('Should not have run'); | ||
} | ||
e.off('go there', nope); | ||
e.on('go there', nope); | ||
e.off('go there', nope); | ||
e.off('go there', nope); | ||
e.off('go there'); | ||
e.emit('go', 'hi'); | ||
}); | ||
it('Allows multiple registrations in one statement', function () { | ||
@@ -50,0 +73,0 @@ var e = new Eev(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14165
251
2