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

callback-registry

Package Overview
Dependencies
Maintainers
2
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 2.5.2 to 2.6.0

8

index.d.ts

@@ -10,5 +10,9 @@ /**

* Adds a new callback to the registry under some key.
* The callback will be notified when someone executes
* The callback will be notified when someone executes.
* The callback will be called with all replayArguments:
* e.g. add('clientAdded', (name, age) => console.log(name, age), [['Alice', 25], ['Bob', 30]])
* will invoke the callback with 'Alice', 25 and 'Bob', 30 *after* returning the unsubscribe function.
* An example use case are events that need to call the provided callback with previous values (replay) and want to allow the callback to unsubscribe while replaying
*/
add(key: string, callback: Callback): UnsubscribeFunction;
add(key: string, callback: Callback, replayArgumentsArr?: any[] | Array<any[]>): UnsubscribeFunction;

@@ -15,0 +19,0 @@ /**

@@ -12,3 +12,3 @@ "use strict";

var callbacks = {};
function add(key, callback) {
function add(key, callback, replayArgumentsArr) {
var callbacksForKey = callbacks[key];

@@ -20,2 +20,22 @@ if (!callbacksForKey) {

callbacksForKey.push(callback);
if (replayArgumentsArr) {
setTimeout(function () {
replayArgumentsArr.forEach(function (replayArgument) {
var _a;
if ((_a = callbacks[key]) === null || _a === void 0 ? void 0 : _a.includes(callback)) {
try {
if (Array.isArray(replayArgument)) {
callback.apply(undefined, replayArgument);
}
else {
callback.apply(undefined, [replayArgument]);
}
}
catch (err) {
_handleError(err, key);
}
}
});
}, 0);
}
return function () {

@@ -22,0 +42,0 @@ var allForKey = callbacks[key];

{
"name": "callback-registry",
"version": "2.5.2",
"version": "2.6.0",
"description": "Registry for callbacks",

@@ -31,3 +31,3 @@ "main": "./lib/index.js",

"mocha": "6.2.2",
"typescript": "3.6.4"
"typescript": "^3.9.6"
},

@@ -34,0 +34,0 @@ "publishConfig": {

@@ -46,3 +46,5 @@ # Intro

# Change log
* 2.5.0
* 2.6.0
added replayArgumentsArr that allows you to replay arguments to a new callback
* 2.5.0
added clearKey method that removes a key from the registry

@@ -49,0 +51,0 @@ * 2.3.2

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