event-pubsub
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -15,3 +15,17 @@ window.pubsub=( | ||
checkScope.apply(this); | ||
if(type=='*'){ | ||
var params=Array.prototype.slice.call(arguments,1); | ||
for( | ||
var keys = Object.keys(this._events_), | ||
count = keys.length, | ||
i=0; | ||
i<count; | ||
i++ | ||
){ | ||
var args=params.unshift(keys[i]); | ||
this.off.call(args); | ||
} | ||
} | ||
if(!this._events_[type]) | ||
@@ -25,9 +39,14 @@ return; | ||
if(this._events_[type].length<2){ | ||
delete this._events_[type]; | ||
return; | ||
} | ||
for(var i=0, | ||
count=this._events_[type].length; | ||
count=this._events_[type].length; | ||
i<count; | ||
i++){ | ||
if(this._events_[type][i]==handler) | ||
delete this._events_[type][i]; | ||
i++ | ||
){ | ||
if(this._events_[type][i]==handler) | ||
this._events_[type].splice(i,1); | ||
return; | ||
@@ -34,0 +53,0 @@ } |
@@ -13,2 +13,16 @@ function sub(type,handler){ | ||
if(type=='*'){ | ||
var params=Array.prototype.slice.call(arguments,1); | ||
for( | ||
var keys = Object.keys(this._events_), | ||
count = keys.length, | ||
i=0; | ||
i<count; | ||
i++ | ||
){ | ||
var args=params.unshift(keys[i]); | ||
this.off.call(args); | ||
} | ||
} | ||
if(!this._events_[type]) | ||
@@ -22,9 +36,14 @@ return; | ||
if(this._events_[type].length<2){ | ||
delete this._events_[type]; | ||
return; | ||
} | ||
for(var i=0, | ||
count=this._events_[type].length; | ||
count=this._events_[type].length; | ||
i<count; | ||
i++){ | ||
if(this._events_[type][i]==handler) | ||
delete this._events_[type][i]; | ||
i++ | ||
){ | ||
if(this._events_[type][i]==handler) | ||
this._events_[type].splice(i,1); | ||
return; | ||
@@ -31,0 +50,0 @@ } |
@@ -37,2 +37,4 @@ var events = new window.pubsub(); | ||
eventLog.log('World event got',data); | ||
events.off('*'); | ||
eventLog.log('Removed all events') | ||
} | ||
@@ -39,0 +41,0 @@ ); |
@@ -37,2 +37,4 @@ var events = new require('../../event-pubsub.js')(); | ||
console.log('World event got',data); | ||
events.off('*'); | ||
console.log('Removed all events'); | ||
} | ||
@@ -39,0 +41,0 @@ ); |
{ | ||
"name": "event-pubsub", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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": "https://github.com/RIAEvangelist/event-pubsub" | ||
"homepage": "http://riaevangelist.github.io/event-pubsub/" | ||
} |
@@ -7,5 +7,24 @@ Event PubSub | ||
[Pretty GitHub.io site](http://riaevangelist.github.io/event-pubsub/) | ||
[![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) | ||
**EXAMPLE FILES** | ||
1. [Node Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/node) | ||
2. [Browser Pubsub Event Examples](https://github.com/RIAEvangelist/event-pubsub/tree/master/examples/browser) | ||
**Node Install** | ||
``npm install event-pubsub`` | ||
**Browser Install** | ||
*see browser examples above or below* | ||
--- | ||
### Basic Examples | ||
### Basic Example | ||
--- | ||
***NOTE - the only diffeence between node and browser code is how the ``events`` variable is created*** | ||
* node ``var events = new require('../../event-pubsub.js')();`` | ||
* browser ``var events = new window.pubsub();`` | ||
#### Node | ||
@@ -29,2 +48,10 @@ | ||
events.on( | ||
'removeEvents', | ||
function(){ | ||
events.off('*'); | ||
console.log('Removed all events'); | ||
} | ||
); | ||
/************************************\ | ||
@@ -37,2 +64,7 @@ * trigger events for testing | ||
); | ||
events.trigger( | ||
'removeEvents' | ||
); | ||
@@ -42,4 +74,18 @@ #### Browser | ||
var events = new require('../../event-pubsub.js')(); | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>PubSub Example</title> | ||
<script src='../../event-pubsub-browser.js'></script> | ||
<script src='yourAmazingCode.js'></script> | ||
</head> | ||
<body> | ||
... | ||
</body> | ||
</html> | ||
##### Inside Your Amazing Code | ||
var events = new window.pubsub(); | ||
events.on( | ||
@@ -59,2 +105,10 @@ 'hello', | ||
events.on( | ||
'removeEvents', | ||
function(){ | ||
events.off('*'); | ||
console.log('Removed all events'); | ||
} | ||
); | ||
/************************************\ | ||
@@ -67,1 +121,5 @@ * trigger events for testing | ||
); | ||
events.trigger( | ||
'removeEvents' | ||
); |
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
21789
608
120