added ability to remove all events

This commit is contained in:
Brandon Miller 2014-03-01 03:23:59 -08:00
parent 425ccc5afd
commit 851d0219dc
3 changed files with 49 additions and 5 deletions

View file

@ -10,6 +10,19 @@ function sub(type,handler){
function unsub(type,handler){ function unsub(type,handler){
checkScope.apply(this); checkScope.apply(this);
if(type=='*'){
delete this._events_['*'];
for(
var keys = Object.keys(this._events_),
count = keys.length,
i=0;
i<count;
i++
){
this.off(keys[i]);
}
}
if(!this._events_[type]) if(!this._events_[type])
return; return;
@ -21,8 +34,8 @@ function unsub(type,handler){
for(var i=0, for(var i=0,
count=this._events_[type].length; count=this._events_[type].length;
i<count; i<count;
i++){ i++
){
if(this._events_[type][i]==handler) if(this._events_[type][i]==handler)
delete this._events_[type][i]; delete this._events_[type][i];
return; return;

View file

@ -34,6 +34,8 @@ events.on(
'world', 'world',
function(data){ function(data){
console.log('World event got',data); console.log('World event got',data);
events.off('*');
console.log('Removed all events');
} }
); );

29
package.json Normal file
View file

@ -0,0 +1,29 @@
{
"name": "event-pubsub",
"version": "1.0.2",
"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!",
"main": "event-pubsub.js",
"directories": {
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/RIAEvangelist/event-pubsub.git"
},
"keywords": [
"event",
"events",
"pubsub",
"node",
"browser"
],
"author": "Brandon Nozaki Miller",
"license": "Unlicense",
"bugs": {
"url": "https://github.com/RIAEvangelist/event-pubsub/issues"
},
"homepage": "https://github.com/RIAEvangelist/event-pubsub"
}