Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

callback-registry

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callback-registry - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

28

lib/index.js

@@ -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();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc