@monstermann/signals
v0.11.0
Published
A signals library.
Readme
A signals library.
A fork of @preact/signals-core where signals are functions, with a couple of additions.
import { action, batch, effect, memo, signal } from "@monstermann/signals";
const count = signal(0);
const double = memo(() => count() * 2);
const dispose = effect(() => {
console.log(count(), double());
});
// Read, write, transform:
count();
count(1);
count((n) => n + 1);
// Update several signals at once:
batch(() => {
count(3);
count(4);
});
// Batched and untracked functions:
const increment = action((by: number) => count((n) => n + by));
dispose();Installation
bun add @monstermann/signalsAPI
Everything is documented with JSDoc, including examples.
| | |
| --------- | ----------------------------------------------------------------------------------------------- |
| State | signal, memo, indexed, reducer |
| Reactions | effect, deferEffect, watch, onCleanup |
| Actions | action |
| Events | emitter |
| Disposal | disposer, dispose, onDispose, isDisposed, disposed, mixinDisposer |
| Batching | batch, startBatch, endBatch, isBatching |
| Tracking | untrack, peek, pauseTracking, resumeTracking |
| Running | hasEffect, currentEffect, disposeEffect, hasWatcher, currentWatcher, disposeWatcher |
| Other | context, RawSignal, RawMemo, RawEffect |
HMR
@monstermann/signals-transform disposes effects, watchers and emitters when their module is replaced during development.
