1.3.2 • Published 3 years ago

@plato/signal v1.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@plato/signal

Node.js CI

A Signal is a specific event to which observers can subscribe to receive, with strong typing.

See the API reference for more information.

Why?

Instead of an inheritable class (like Node's EventEmitter), this library promotes composition over inheritance.

Usage

import { Signal } from "@plato/signal";

const onPing = new Signal();

onPing.receive(() => {
	// Received the "onPing" signal
});

onPing.emit();

By default, a SignalReceiver will have a generic type of (...args: any[]) => void. However, you can strongly type receivers by passing a type variable when constructing a Signal:

// Create a signal with a strongly typed receiver
const onMessage = new Signal<(message: string) => void>();

onMessage.receive((message) => {
  // TODO: Do something with "message", which is a string
});

onMessage.emit("Hello Plato!");
1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago