Socket
Socket
Sign inDemoInstall

mini-signals

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-signals


Version published
Weekly downloads
28K
decreased by-17.42%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

mini-signals

signals, in JavaScript, fast

NPM License

Description

Custom event/messaging system for TypeScript/JavaScript inspired by js-signals originally based on EventEmitter3 code base.

There are several advantages to signals over event-emitters (see Comparison between different Observer Pattern implementations). However, the current implementation of js-signals is (arguably) slow compared to other implementations (see EventsSpeedTests). mini-signals is a fast, minimal emitter, with an API similar to js-signals.

Note: Signals here are the type defined by js-signals inspired by AS3-Signals. They should not to be confused with SolidJS or Angular signals.

Install

npm:

npm install mini-signals

Example Usage

import { MiniSignal } from "mini-signals";

const mySignal = new MiniSignal<[string, string]>();

const binding = mySignal.add(onSignal); //add listener

mySignal.dispatch("foo", "bar"); // dispatch signal passing custom parameters
binding.detach(); // remove a single listener

function onSignal(foo: string, bar: string) {
  assert(foo === "foo");
  assert(bar === "bar");
}

Another Example

const myObject = {
  foo: "bar",
  updated: new MiniSignal<never>(),
};

myObject.updated.add(onUpdated, myObject); //add listener with context

myObject.foo = "baz";
myObject.updated.dispatch(); //dispatch signal

function onUpdated() {
  assert(this === myObject);
  assert(this.foo === "baz");
}

API

See API.md

License

Copyright (c) 2015-2023 Jayson Harshbarger

MIT License

Keywords

FAQs

Last updated on 25 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc