callback-registry
Advanced tools
Comparing version 2.2.5 to 2.2.6
@@ -1,51 +0,48 @@ | ||
module.exports = function () { | ||
"use strict"; | ||
var callbacks = {}; | ||
function add(key, callback) { | ||
var callbacksForKey = callbacks[key]; | ||
if (!callbacksForKey) { | ||
callbacksForKey = []; | ||
callbacks[key] = callbacksForKey; | ||
} | ||
callbacksForKey.push(callback); | ||
// remove function | ||
return function(){ | ||
// get a new view of the collection( | ||
"use strict"; | ||
function createRegistry() { | ||
var callbacks = {}; | ||
function add(key, callback) { | ||
var callbacksForKey = callbacks[key]; | ||
if (!callbacksForKey) { | ||
callbacksForKey = []; | ||
callbacks[key] = callbacksForKey; | ||
} | ||
callbacksForKey.push(callback); | ||
return function () { | ||
var allForKey = callbacks[key]; | ||
allForKey = allForKey.filter(function(item){ | ||
allForKey = allForKey.filter(function (item) { | ||
return item !== callback; | ||
}); | ||
callbacks[key] = allForKey; | ||
}; | ||
} | ||
function execute(key) { | ||
var callbacksForKey = callbacks[key]; | ||
if (!callbacksForKey || callbacksForKey.length === 0){ | ||
return []; | ||
} | ||
var args = [].splice.call(arguments, 1); | ||
var results = []; | ||
callbacksForKey.forEach(function (callback) { | ||
}; | ||
} | ||
function execute(key) { | ||
var argumentsArr = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
argumentsArr[_i - 1] = arguments[_i]; | ||
} | ||
var callbacksForKey = callbacks[key]; | ||
if (!callbacksForKey || callbacksForKey.length === 0) { | ||
return []; | ||
} | ||
var results = []; | ||
callbacksForKey.forEach(function (callback) { | ||
try { | ||
var result = callback.apply(undefined, args); | ||
var result = callback.apply(undefined, argumentsArr); | ||
results.push(result); | ||
} catch (err) { | ||
} | ||
catch (err) { | ||
results.push(undefined); | ||
} | ||
}); | ||
return results; | ||
} | ||
return { | ||
add: add, | ||
execute: execute | ||
}; | ||
}; | ||
return results; | ||
} | ||
return { | ||
add: add, | ||
execute: execute | ||
}; | ||
} | ||
; | ||
createRegistry.default = createRegistry; | ||
module.exports = createRegistry; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "callback-registry", | ||
"version": "2.2.5", | ||
"description": "Registry for callbacks", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"test": "mocha tests/index.js", | ||
"prepublish" : "npm run test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kirilpopov/callback-registry.git" | ||
}, | ||
"keywords": [ | ||
"callbacks", | ||
"registry", | ||
"store", | ||
"dispatcher" | ||
], | ||
"author": "Kiril Popov", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/kirilpopov/callback-registry/issues" | ||
}, | ||
"homepage": "https://github.com/kirilpopov/callback-registry#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3" | ||
}, | ||
"publishConfig":{ | ||
"registry":"https://registry.npmjs.org" | ||
} | ||
"name": "callback-registry", | ||
"version": "2.2.6", | ||
"description": "Registry for callbacks", | ||
"main": "./lib/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "npm run build && mocha tests/index.js", | ||
"prepublish": "npm run test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/kirilpopov/callback-registry.git" | ||
}, | ||
"keywords": [ | ||
"callbacks", | ||
"registry", | ||
"store", | ||
"dispatcher" | ||
], | ||
"author": "Kiril Popov", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/kirilpopov/callback-registry/issues" | ||
}, | ||
"homepage": "https://github.com/kirilpopov/callback-registry#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3", | ||
"typescript": "^2.3.4" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
} | ||
} |
# Intro | ||
A simple registry for callbacks that allows you to add one or more callbacks | ||
under some key and then execute all by just using the key. | ||
under some key and then execute all callbacks under some key. | ||
Example: | ||
```javascript | ||
const registryFactory = require('callback-registry'); | ||
@@ -10,0 +10,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
4730
3
4
47