From 65bd9b289b3bc2ead99b975a012d0abbda14b21c Mon Sep 17 00:00:00 2001 From: Brandon Nozaki Miller Date: Mon, 11 Jul 2016 03:17:17 -0700 Subject: [PATCH] fixed bug elrroniously removing last event even if not a match --- .tags | 47 ++++++++++++++++++++++++++++ bower.json | 28 +++++++++++++++++ event-pubsub-browser.js | 69 ++++++++++++++++++++--------------------- event-pubsub.js | 57 +++++++++++++++++----------------- 4 files changed, 137 insertions(+), 64 deletions(-) create mode 100644 .tags create mode 100644 bower.json diff --git a/.tags b/.tags new file mode 100644 index 0000000..6566eb0 --- /dev/null +++ b/.tags @@ -0,0 +1,47 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.9~svn20110310 // +_log_ examples/browser/basic.js /^function _log_ (){$/;" c +_log_ examples/browser/multipleScopes.js /^function _log_ (){$/;" c +_log_ examples/browser/objectScope.js /^function _log_ (){$/;" c +author package.json /^ "author": "Brandon Nozaki Miller",$/;" f +authors bower.json /^ "authors": [$/;" f +bugs package.json /^ "bugs": {$/;" f +checkScope event-pubsub.js /^function checkScope(){$/;" f +description bower.json /^ "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!",$/;" f +description package.json /^ "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!",$/;" f +directories package.json /^ "directories": {$/;" f +eventLog examples/browser/basic.js /^var eventLog=document.getElementById('events');$/;" v +eventLog examples/browser/multipleScopes.js /^var eventLog=document.getElementById('events');$/;" v +eventLog examples/browser/objectScope.js /^var eventLog=document.getElementById('events');$/;" v +example package.json /^ "example": "examples"$/;" f +homepage bower.json /^ "homepage": "https:\/\/github.com\/RIAEvangelist\/event-pubsub",$/;" f +homepage package.json /^ "homepage": "https:\/\/github.com\/RIAEvangelist\/event-pubsub"$/;" f +ignore bower.json /^ "ignore": [$/;" f +init event-pubsub.js /^function init(scope){$/;" f +keywords bower.json /^ "keywords": [$/;" f +keywords package.json /^ "keywords": [$/;" f +license bower.json /^ "license": "DBAD",$/;" f +license package.json /^ "license": "Unlicense",$/;" f +main bower.json /^ "main": "event-pubsub.js",$/;" f +main package.json /^ "main": "event-pubsub.js",$/;" f +moduleType bower.json /^ "moduleType": [$/;" f +name bower.json /^ "name": "event-pubsub",$/;" f +name package.json /^ "name": "event-pubsub",$/;" f +pub event-pubsub.js /^function pub(type){$/;" f +pubsub examples/node/multipleScopes.js /^var pubsub = require('..\/..\/event-pubsub.js');$/;" v +pubsub examples/node/objectScope.js /^var pubsub = require('..\/..\/event-pubsub.js');$/;" v +repository package.json /^ "repository": {$/;" f +scripts package.json /^ "scripts": {$/;" f +sub event-pubsub.js /^function sub(type,handler){$/;" f +test package.json /^ "test": "echo \\"Error: no test specified\\" && exit 1"$/;" f +thing.id examples/browser/objectScope.js /^var thing={$/;" p +thing.id examples/node/objectScope.js /^var thing={$/;" p +type package.json /^ "type": "git",$/;" f +unsub event-pubsub.js /^function unsub(type,handler){$/;" f +url package.json /^ "url": "https:\/\/github.com\/RIAEvangelist\/event-pubsub.git"$/;" f +url package.json /^ "url": "https:\/\/github.com\/RIAEvangelist\/event-pubsub\/issues"$/;" f +version package.json /^ "version": "1.0.3",$/;" f diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..357f57b --- /dev/null +++ b/bower.json @@ -0,0 +1,28 @@ +{ + "name": "event-pubsub", + "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", + "authors": [ + "Brandon Nozaki Miller" + ], + "license": "DBAD", + "keywords": [ + "event", + "events", + "pubsub", + "node", + "browser" + ], + "homepage": "https://github.com/RIAEvangelist/event-pubsub", + "moduleType": [ + "globals", + "node" + ], + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/event-pubsub-browser.js b/event-pubsub-browser.js index 0b59a9e..4ee521d 100644 --- a/event-pubsub-browser.js +++ b/event-pubsub-browser.js @@ -3,16 +3,16 @@ window.pubsub=( function sub(type,handler){ checkScope.apply(this); - + if(!this._events_[type]) this._events_[type]=[]; - + this._events_[type].push(handler); } - + function unsub(type,handler){ checkScope.apply(this); - + if(type=='*'){ var params=Array.prototype.slice.call(arguments,1); for( @@ -26,58 +26,57 @@ window.pubsub=( this.off.call(args); } } - + if(!this._events_[type]) return; - + if(!handler){ delete this._events_[type]; return; } - - if(this._events_[type].length<2){ - delete this._events_[type]; - return; - } - - for(var i=0, + + for(var i=0, count=this._events_[type].length; i