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

@wixc3/patterns

Package Overview
Dependencies
Maintainers
65
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/patterns - npm Package Compare versions

Comparing version 5.1.0 to 5.2.3

9

dist/cjs/debouncer.js

@@ -30,9 +30,2 @@ "use strict";

class Debouncer {
cb;
waitTime;
maxWaitTime;
timeout;
maxTimeout;
args = [];
defer = (0, promise_assist_1.deferred)();
/**

@@ -48,2 +41,4 @@ *

this.maxWaitTime = maxWaitTime;
this.args = [];
this.defer = (0, promise_assist_1.deferred)();
}

@@ -50,0 +45,0 @@ execute() {

@@ -9,74 +9,77 @@ "use strict";

class EventEmitter {
events = new Map();
emitOnce = new Map();
/**
* Check if an event has subscribers
* @returns true if event has subscribers
*/
hasSubscribers = (event) => this.events.has(event);
/**
* Subscribe a handler for event
*/
subscribe = (event, handler) => {
const bucket = this.events.get(event);
bucket ? bucket.add(handler) : this.events.set(event, new signal_1.Signal([handler]));
};
/**
* {@inheritDoc EventEmitter.subscribe}
*/
on = this.subscribe;
/**
* Adds a handler that will be called at most once
*/
once = (event, handler) => {
this.off(event, handler);
const bucket = this.emitOnce.get(event);
bucket ? bucket.add(handler) : this.emitOnce.set(event, new signal_1.Signal([handler]));
};
/**
* Unsubscribe a handler from event
*/
unsubscribe = (event, handler) => {
let bucket = this.events.get(event);
bucket?.delete(handler);
bucket?.size === 0 && this.events.delete(event);
bucket = this.emitOnce.get(event);
bucket?.delete(handler);
bucket?.size === 0 && this.events.delete(event);
};
/**
* {@inheritDoc EventEmitter.unsubscribe}
*/
off = this.unsubscribe;
/**
* Drop all subscriptions of a signal
* @param event - signal id
*/
delete = (event) => {
this.events.delete(event);
this.emitOnce.delete(event);
};
/**
* Drop all subscriptions
*/
clear = () => {
constructor() {
this.events = new Map();
this.emitOnce = new Map();
};
/**
* {@inheritDoc Signal.notify}
* @param event - eve
* @param data - event data
*/
notify = (event, data) => {
this.events.get(event)?.notify(data);
this.emitOnce.get(event)?.notify(data);
this.emitOnce.delete(event);
};
/**
* {@inheritDoc EventEmitter.notify}
*/
emit = this.notify;
/**
* Check if an event has subscribers
* @returns true if event has subscribers
*/
this.hasSubscribers = (event) => this.events.has(event);
/**
* Subscribe a handler for event
*/
this.subscribe = (event, handler) => {
const bucket = this.events.get(event);
bucket ? bucket.add(handler) : this.events.set(event, new signal_1.Signal([handler]));
};
/**
* {@inheritDoc EventEmitter.subscribe}
*/
this.on = this.subscribe;
/**
* Adds a handler that will be called at most once
*/
this.once = (event, handler) => {
this.off(event, handler);
const bucket = this.emitOnce.get(event);
bucket ? bucket.add(handler) : this.emitOnce.set(event, new signal_1.Signal([handler]));
};
/**
* Unsubscribe a handler from event
*/
this.unsubscribe = (event, handler) => {
let bucket = this.events.get(event);
bucket === null || bucket === void 0 ? void 0 : bucket.delete(handler);
(bucket === null || bucket === void 0 ? void 0 : bucket.size) === 0 && this.events.delete(event);
bucket = this.emitOnce.get(event);
bucket === null || bucket === void 0 ? void 0 : bucket.delete(handler);
(bucket === null || bucket === void 0 ? void 0 : bucket.size) === 0 && this.events.delete(event);
};
/**
* {@inheritDoc EventEmitter.unsubscribe}
*/
this.off = this.unsubscribe;
/**
* Drop all subscriptions of a signal
* @param event - signal id
*/
this.delete = (event) => {
this.events.delete(event);
this.emitOnce.delete(event);
};
/**
* Drop all subscriptions
*/
this.clear = () => {
this.events = new Map();
this.emitOnce = new Map();
};
/**
* {@inheritDoc Signal.notify}
* @param event - eve
* @param data - event data
*/
this.notify = (event, data) => {
var _a, _b;
(_a = this.events.get(event)) === null || _a === void 0 ? void 0 : _a.notify(data);
(_b = this.emitOnce.get(event)) === null || _b === void 0 ? void 0 : _b.notify(data);
this.emitOnce.delete(event);
};
/**
* {@inheritDoc EventEmitter.notify}
*/
this.emit = this.notify;
}
}
exports.EventEmitter = EventEmitter;
//# sourceMappingURL=event-emitter.js.map

@@ -8,9 +8,8 @@ "use strict";

class LRUCache {
config;
cache = new Map();
keys = [];
maxSize;
constructor(config = {}) {
var _a;
this.config = config;
this.maxSize = config.maxSize ?? Infinity;
this.cache = new Map();
this.keys = [];
this.maxSize = (_a = config.maxSize) !== null && _a !== void 0 ? _a : Infinity;
if (this.maxSize < 1) {

@@ -17,0 +16,0 @@ throw new Error('LRUCache max size must be larger than 0');

@@ -18,4 +18,4 @@ "use strict";

class SetMultiMap {
map = new Map();
constructor(entries) {
this.map = new Map();
(0, common_1.forEach)(entries, ([key, val]) => {

@@ -22,0 +22,0 @@ this.add(key, val);

@@ -36,23 +36,26 @@ "use strict";

class Signal extends Set {
/**
* Subscribe a notification callback
* @param handler - Will be executed with a data arg when a notification occurs
*/
subscribe = (handler) => {
this.add(handler);
};
/**
* Unsubscribe an existing callback
*/
unsubscribe = (handler) => {
this.delete(handler);
};
/**
* Notify all subscribers with arg data
*/
notify = (data) => {
for (const handler of this) {
handler(data);
}
};
constructor() {
super(...arguments);
/**
* Subscribe a notification callback
* @param handler - Will be executed with a data arg when a notification occurs
*/
this.subscribe = (handler) => {
this.add(handler);
};
/**
* Unsubscribe an existing callback
*/
this.unsubscribe = (handler) => {
this.delete(handler);
};
/**
* Notify all subscribers with arg data
*/
this.notify = (data) => {
for (const handler of this) {
handler(data);
}
};
}
}

@@ -59,0 +62,0 @@ exports.Signal = Signal;

@@ -27,9 +27,2 @@ import { deferred } from 'promise-assist';

export class Debouncer {
cb;
waitTime;
maxWaitTime;
timeout;
maxTimeout;
args = [];
defer = deferred();
/**

@@ -45,2 +38,4 @@ *

this.maxWaitTime = maxWaitTime;
this.args = [];
this.defer = deferred();
}

@@ -47,0 +42,0 @@ execute() {

@@ -6,73 +6,76 @@ import { Signal } from './signal';

export class EventEmitter {
events = new Map();
emitOnce = new Map();
/**
* Check if an event has subscribers
* @returns true if event has subscribers
*/
hasSubscribers = (event) => this.events.has(event);
/**
* Subscribe a handler for event
*/
subscribe = (event, handler) => {
const bucket = this.events.get(event);
bucket ? bucket.add(handler) : this.events.set(event, new Signal([handler]));
};
/**
* {@inheritDoc EventEmitter.subscribe}
*/
on = this.subscribe;
/**
* Adds a handler that will be called at most once
*/
once = (event, handler) => {
this.off(event, handler);
const bucket = this.emitOnce.get(event);
bucket ? bucket.add(handler) : this.emitOnce.set(event, new Signal([handler]));
};
/**
* Unsubscribe a handler from event
*/
unsubscribe = (event, handler) => {
let bucket = this.events.get(event);
bucket?.delete(handler);
bucket?.size === 0 && this.events.delete(event);
bucket = this.emitOnce.get(event);
bucket?.delete(handler);
bucket?.size === 0 && this.events.delete(event);
};
/**
* {@inheritDoc EventEmitter.unsubscribe}
*/
off = this.unsubscribe;
/**
* Drop all subscriptions of a signal
* @param event - signal id
*/
delete = (event) => {
this.events.delete(event);
this.emitOnce.delete(event);
};
/**
* Drop all subscriptions
*/
clear = () => {
constructor() {
this.events = new Map();
this.emitOnce = new Map();
};
/**
* {@inheritDoc Signal.notify}
* @param event - eve
* @param data - event data
*/
notify = (event, data) => {
this.events.get(event)?.notify(data);
this.emitOnce.get(event)?.notify(data);
this.emitOnce.delete(event);
};
/**
* {@inheritDoc EventEmitter.notify}
*/
emit = this.notify;
/**
* Check if an event has subscribers
* @returns true if event has subscribers
*/
this.hasSubscribers = (event) => this.events.has(event);
/**
* Subscribe a handler for event
*/
this.subscribe = (event, handler) => {
const bucket = this.events.get(event);
bucket ? bucket.add(handler) : this.events.set(event, new Signal([handler]));
};
/**
* {@inheritDoc EventEmitter.subscribe}
*/
this.on = this.subscribe;
/**
* Adds a handler that will be called at most once
*/
this.once = (event, handler) => {
this.off(event, handler);
const bucket = this.emitOnce.get(event);
bucket ? bucket.add(handler) : this.emitOnce.set(event, new Signal([handler]));
};
/**
* Unsubscribe a handler from event
*/
this.unsubscribe = (event, handler) => {
let bucket = this.events.get(event);
bucket === null || bucket === void 0 ? void 0 : bucket.delete(handler);
(bucket === null || bucket === void 0 ? void 0 : bucket.size) === 0 && this.events.delete(event);
bucket = this.emitOnce.get(event);
bucket === null || bucket === void 0 ? void 0 : bucket.delete(handler);
(bucket === null || bucket === void 0 ? void 0 : bucket.size) === 0 && this.events.delete(event);
};
/**
* {@inheritDoc EventEmitter.unsubscribe}
*/
this.off = this.unsubscribe;
/**
* Drop all subscriptions of a signal
* @param event - signal id
*/
this.delete = (event) => {
this.events.delete(event);
this.emitOnce.delete(event);
};
/**
* Drop all subscriptions
*/
this.clear = () => {
this.events = new Map();
this.emitOnce = new Map();
};
/**
* {@inheritDoc Signal.notify}
* @param event - eve
* @param data - event data
*/
this.notify = (event, data) => {
var _a, _b;
(_a = this.events.get(event)) === null || _a === void 0 ? void 0 : _a.notify(data);
(_b = this.emitOnce.get(event)) === null || _b === void 0 ? void 0 : _b.notify(data);
this.emitOnce.delete(event);
};
/**
* {@inheritDoc EventEmitter.notify}
*/
this.emit = this.notify;
}
}
//# sourceMappingURL=event-emitter.js.map

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

export class LRUCache {
config;
cache = new Map();
keys = [];
maxSize;
constructor(config = {}) {
var _a;
this.config = config;
this.maxSize = config.maxSize ?? Infinity;
this.cache = new Map();
this.keys = [];
this.maxSize = (_a = config.maxSize) !== null && _a !== void 0 ? _a : Infinity;
if (this.maxSize < 1) {

@@ -14,0 +13,0 @@ throw new Error('LRUCache max size must be larger than 0');

@@ -15,4 +15,4 @@ import { forEach, chain } from '@wixc3/common';

export class SetMultiMap {
map = new Map();
constructor(entries) {
this.map = new Map();
forEach(entries, ([key, val]) => {

@@ -19,0 +19,0 @@ this.add(key, val);

@@ -33,23 +33,26 @@ /**

export class Signal extends Set {
/**
* Subscribe a notification callback
* @param handler - Will be executed with a data arg when a notification occurs
*/
subscribe = (handler) => {
this.add(handler);
};
/**
* Unsubscribe an existing callback
*/
unsubscribe = (handler) => {
this.delete(handler);
};
/**
* Notify all subscribers with arg data
*/
notify = (data) => {
for (const handler of this) {
handler(data);
}
};
constructor() {
super(...arguments);
/**
* Subscribe a notification callback
* @param handler - Will be executed with a data arg when a notification occurs
*/
this.subscribe = (handler) => {
this.add(handler);
};
/**
* Unsubscribe an existing callback
*/
this.unsubscribe = (handler) => {
this.delete(handler);
};
/**
* Notify all subscribers with arg data
*/
this.notify = (data) => {
for (const handler of this) {
handler(data);
}
};
}
}

@@ -56,0 +59,0 @@ /**

{
"name": "@wixc3/patterns",
"version": "5.1.0",
"version": "5.2.3",
"description": "A utility for saving objects to be disposed",

@@ -21,5 +21,5 @@ "main": "dist/cjs/index.js",

"dependencies": {
"@wixc3/common": "^5.1.0",
"@wixc3/common": "^5.2.3",
"promise-assist": "^1.3.0"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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