Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Apr 16, 2022
1 parent d36858d commit 8e1cbf9
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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<number>()
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<string>()
.add((name) => console.log(`Hello ${name}!`))
.add((name) => console.log(`Hi again ${name}!`))
.emit()
```

0 comments on commit 8e1cbf9

Please sign in to comment.