event-pubsub
Advanced tools
Comparing version 1.0.3 to 1.0.5
@@ -6,12 +6,12 @@ window.pubsub=( | ||
checkScope.apply(this); | ||
if(!this._events_[type]) | ||
this._events_[type]=[]; | ||
this._events_[type].push(handler); | ||
} | ||
function unsub(type,handler){ | ||
checkScope.apply(this); | ||
if(type=='*'){ | ||
@@ -30,6 +30,6 @@ var params=Array.prototype.slice.call(arguments,1); | ||
} | ||
if(!this._events_[type]) | ||
return; | ||
if(!handler){ | ||
@@ -39,9 +39,4 @@ delete this._events_[type]; | ||
} | ||
if(this._events_[type].length<2){ | ||
delete this._events_[type]; | ||
return; | ||
} | ||
for(var i=0, | ||
for(var i=0, | ||
count=this._events_[type].length; | ||
@@ -51,11 +46,15 @@ i<count; | ||
){ | ||
if(this._events_[type][i]==handler) | ||
if(this._events_[type][i]==handler){ | ||
this._events_[type].splice(i,1); | ||
return; | ||
} | ||
} | ||
if(this._events_[type].length<1){ | ||
delete this._events_[type]; | ||
} | ||
} | ||
function pub(type){ | ||
checkScope.apply(this); | ||
if(this._events_['*'] && type!='*'){ | ||
@@ -66,11 +65,11 @@ var params=Array.prototype.slice.call(arguments); | ||
} | ||
if(!this._events_[type]) | ||
return; | ||
for(var i=0, | ||
events=this._events_[type], | ||
for(var i=0, | ||
events=this._events_[type], | ||
count=events.length, | ||
args=Array.prototype.slice.call(arguments,1); | ||
i<count; | ||
args=Array.prototype.slice.call(arguments,1); | ||
i<count; | ||
i++){ | ||
@@ -80,3 +79,3 @@ events[i].apply(this, args); | ||
} | ||
function checkScope(){ | ||
@@ -86,3 +85,3 @@ if(!this._events_) | ||
} | ||
function init(scope){ | ||
@@ -95,3 +94,3 @@ if(!scope) | ||
}; | ||
scope.on=( | ||
@@ -101,3 +100,3 @@ function(scope){ | ||
sub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -108,3 +107,3 @@ ); | ||
)(scope); | ||
scope.off=( | ||
@@ -114,3 +113,3 @@ function(scope){ | ||
unsub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -121,3 +120,3 @@ ); | ||
)(scope); | ||
scope.trigger=( | ||
@@ -127,3 +126,3 @@ function(scope){ | ||
pub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -134,9 +133,9 @@ ); | ||
)(scope); | ||
scope._events_={}; | ||
} | ||
return init; | ||
} | ||
)(); | ||
)(); |
function sub(type,handler){ | ||
checkScope.apply(this); | ||
if(!this._events_[type]) | ||
this._events_[type]=[]; | ||
this._events_[type].push(handler); | ||
@@ -12,3 +12,3 @@ } | ||
checkScope.apply(this); | ||
if(type=='*'){ | ||
@@ -27,6 +27,6 @@ var params=Array.prototype.slice.call(arguments,1); | ||
} | ||
if(!this._events_[type]) | ||
return; | ||
if(!handler){ | ||
@@ -36,9 +36,4 @@ delete this._events_[type]; | ||
} | ||
if(this._events_[type].length<2){ | ||
delete this._events_[type]; | ||
return; | ||
} | ||
for(var i=0, | ||
for(var i=0, | ||
count=this._events_[type].length; | ||
@@ -48,6 +43,10 @@ i<count; | ||
){ | ||
if(this._events_[type][i]==handler) | ||
if(this._events_[type][i]==handler){ | ||
this._events_[type].splice(i,1); | ||
return; | ||
} | ||
} | ||
if(this._events_[type].length<1){ | ||
delete this._events_[type]; | ||
} | ||
} | ||
@@ -57,3 +56,3 @@ | ||
checkScope.apply(this); | ||
if(this._events_['*'] && type!='*'){ | ||
@@ -64,11 +63,11 @@ var params=Array.prototype.slice.call(arguments); | ||
} | ||
if(!this._events_[type]) | ||
return; | ||
for(var i=0, | ||
events=this._events_[type], | ||
for(var i=0, | ||
events=this._events_[type], | ||
count=events.length, | ||
args=Array.prototype.slice.call(arguments,1); | ||
i<count; | ||
args=Array.prototype.slice.call(arguments,1); | ||
i<count; | ||
i++){ | ||
@@ -91,3 +90,3 @@ events[i].apply(this, args); | ||
}; | ||
scope.on=( | ||
@@ -97,3 +96,3 @@ function(scope){ | ||
sub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -104,3 +103,3 @@ ); | ||
)(scope); | ||
scope.off=( | ||
@@ -110,3 +109,3 @@ function(scope){ | ||
unsub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -117,3 +116,3 @@ ); | ||
)(scope); | ||
scope.trigger=( | ||
@@ -123,3 +122,3 @@ function(scope){ | ||
pub.apply( | ||
scope, | ||
scope, | ||
Array.prototype.slice.call(arguments) | ||
@@ -130,6 +129,6 @@ ); | ||
)(scope); | ||
scope._events_={}; | ||
} | ||
module.exports=init | ||
module.exports=init |
{ | ||
"name": "event-pubsub", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"description": "Pubsub events for Node and the browser allowing event scoping and multiple scopes. Easy for any developer level. No frills, just high speed pubsub events!", | ||
@@ -28,3 +28,3 @@ "main": "event-pubsub.js", | ||
}, | ||
"homepage": "http://riaevangelist.github.io/event-pubsub/" | ||
"homepage": "https://github.com/RIAEvangelist/event-pubsub" | ||
} |
Event PubSub | ||
============ | ||
npm info : | ||
![event-pubsub npm version](https://img.shields.io/npm/v/event-pubsub.svg) ![total npm downloads for event-pubsub](https://img.shields.io/npm/dt/event-pubsub.svg) ![monthly npm downloads for event-pubsub](https://img.shields.io/npm/dm/event-pubsub.svg) | ||
GitHub info : | ||
![event-pubsub GitHub Release](https://img.shields.io/github/release/RIAEvangelist/event-pubsub.svg) ![GitHub license event-pubsub license](https://img.shields.io/github/license/RIAEvangelist/event-pubsub.svg) ![open issues for event-pubsub on GitHub](https://img.shields.io/github/issues/RIAEvangelist/event-pubsub.svg) | ||
Pubsub events for Node and the browser allowing event scoping and multiple scopes. | ||
@@ -9,3 +14,3 @@ Easy for any developer level. No frills, just high speed pubsub events! | ||
[![alt event-pubsub npm details](https://nodei.co/npm/event-pubsub.png?stars=true "event-pubsub npm package details")](https://npmjs.org/package/event-pubsub) | ||
[See NPM stats for event-pubsub](http://npm-stat.com/charts.html?package=event-pubsub&author=&from=&to=) | ||
@@ -12,0 +17,0 @@ **EXAMPLE FILES** |
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
25793
16
636
125