fixed bug elrroniously removing last event even if not a match

This commit is contained in:
Brandon Nozaki Miller 2016-07-11 03:17:17 -07:00
parent 71e526d724
commit 65bd9b289b
4 changed files with 137 additions and 64 deletions

47
.tags Normal file
View file

@ -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

28
bower.json Normal file
View file

@ -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"
]
}

View file

@ -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<count;
i++
){
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!='*'){
var params=Array.prototype.slice.call(arguments);
params.unshift('*');
this.trigger.apply(this,params);
}
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++){
events[i].apply(this, args);
}
}
function checkScope(){
if(!this._events_)
this._events_={};
}
function init(scope){
if(!scope)
return {
@ -85,44 +84,44 @@ window.pubsub=(
off:unsub,
trigger:pub
};
scope.on=(
function(scope){
return function(){
sub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope.off=(
function(scope){
return function(){
unsub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope.trigger=(
function(scope){
return function(){
pub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope._events_={};
}
return init;
}
)();
)();

View file

@ -1,15 +1,15 @@
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(
@ -23,48 +23,47 @@ function unsub(type,handler){
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<count;
i++
){
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!='*'){
var params=Array.prototype.slice.call(arguments);
params.unshift('*');
this.trigger.apply(this,params);
}
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++){
events[i].apply(this, args);
}
@ -82,41 +81,41 @@ function init(scope){
off:unsub,
trigger:pub
};
scope.on=(
function(scope){
return function(){
sub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope.off=(
function(scope){
return function(){
unsub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope.trigger=(
function(scope){
return function(){
pub.apply(
scope,
scope,
Array.prototype.slice.call(arguments)
);
}
}
)(scope);
scope._events_={};
}
module.exports=init
module.exports=init