From 8e1cbf90e4e972aa22f1e8bbfa2f2ed5e6437bd8 Mon Sep 17 00:00:00 2001 From: Hendrik Mans Date: Sat, 16 Apr 2022 17:26:30 +0200 Subject: [PATCH] README --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d77b4d1..e0b4871 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,43 @@ # @hmans/signal -A super duper simple signal implementation. +## A super duper simple signal implementation. + +### tl;dr + +```tsx +import { Signal } from "@hmans/signal" + +const signal = new Signal() +signal.add((n) => console.log(n)) +signal.emit() +``` + +Callbacks are added through `add` and removed through `remove`. + +```tsx +const callback = (n) => console.log(n) +signal.add(callback) +signal.remove(callback) +``` + +`clear` discards all registered listeners: + +```tsx +signal.clear() +``` + +Signals optionally accept a listener through their constructor (just a bit of syntactical sugar for convenience): + +```tsx +const signal = new Signal(() => console.log("I've been signalled!")) +signal.emit() +``` + +Interactions with `Signal` instances can be chained: + +```tsx +new Signal() + .add((name) => console.log(`Hello ${name}!`)) + .add((name) => console.log(`Hi again ${name}!`)) + .emit() +```