callback-registry
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -17,24 +17,11 @@ module.exports = function () { | ||
// callback id is formed as <item-index>_<key>, we use that id to remove the callback | ||
return itemIndex + '_' + key; | ||
// remove function | ||
return function(){ | ||
callbacksForKey = callbacksForKey.filter(function(item){ | ||
item != callback; | ||
}); | ||
callbacks[key] = callbacksForKey; | ||
}; | ||
} | ||
function remove(callbackId) { | ||
var parts = callbackId.split('_'); | ||
if (parts.length !== 2) { | ||
return false; | ||
} | ||
var index = parts[0]; | ||
var key = parts[1]; | ||
var callbackArray = callbacks[key]; | ||
if (!callbackArray || callbackArray.length === 0) { | ||
return false; | ||
} | ||
delete callbackArray[index]; | ||
return true; | ||
} | ||
function execute(key, argumentsArr) { | ||
@@ -55,5 +42,4 @@ var callbacksForKey = callbacks[key]; | ||
add: add, | ||
remove: remove, | ||
execute: execute | ||
}; | ||
}; |
{ | ||
"name": "callback-registry", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Registry for callbacks", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -10,4 +10,4 @@ # callback-registry | ||
const Registry = require('../lib/index.js'); | ||
const registry = Registry(); | ||
const callbackRegistry = require('callback-registry'); | ||
const registry = callbackRegistry(); | ||
@@ -14,0 +14,0 @@ // add a new callback for that event key |
@@ -52,7 +52,7 @@ var expect = require('chai').expect; | ||
var registry = Registry(); | ||
var callbackKey = registry.add('test', function () { | ||
var removeCallback = registry.add('test', function () { | ||
console.log('!!! ERROR'); | ||
done('should not be executed'); | ||
}); | ||
registry.remove(callbackKey); | ||
removeCallback('test'); | ||
registry.execute('test'); | ||
@@ -59,0 +59,0 @@ done(); |
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
12009
99