2.0.7 • Published 4 years ago

@soncodi/signal v2.0.7

Weekly downloads
2,015
License
MIT
Repository
github
Last release
4 years ago

Signal

Build Status Coverage Status Dependency Status npm version

Tiny, typed signal utility for Node.js and browsers. No dependencies.

Need multiple dynamic events and types? Check out EE (Event Emitter) instead

Installation

npm install @soncodi/signal --save

Usage (TypeScript)

import { Signal } from '@soncodi/signal';

// specify callback param type
const signal = new Signal<number>();

const cb = (num: number) => console.log('signal', num);

signal.on(cb);

signal.emit(123);

signal.off(cb);

Methods

on(fn)

Attaches a signal handler to be called whenever the signal fires.

once(fn)

Attaches a one-time handler which is unbound after it fires the first time.

off(fn?)

Detaches one instance of a given handler from the signal. If no handler is provided, detaches all handlers.

emit(arg)

Fires the signal synchronously, triggering any attached handlers with the given arg.

event(arg)

Fires the signal asynchronously, triggering any attached handlers with the given arg. Useful when attaching handlers later in the same event loop turn.

2.0.7

4 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago