@stacksjs/signals v0.58.73
Stacks Signals
Stacks proxies https://github.com/maverick-js/signals signals.
โ๏ธ Features
- ๐ชถ Light (~1kB minzipped)
- ๐ฝ Works in both browsers and Node.js
- ๐ All types are observable (i.e., string, array, object, etc.)
- ๐ต๏ธโโ๏ธ Only updates when value has changed
- โฑ๏ธ Batched updates via microtask scheduler
- ๐ด Lazy by default - efficiently re-computes only what's needed
- ๐ฌ Computations via computed
- ๐ Effect subscriptions via effect
- ๐ Debugging identifiers
- ๐ช Strongly typed
๐ค Usage
bun install -d @stacksjs/signals
You may now use it in your project:
import { computedSignal, effect, root, signal, tick } from '@stacksjs/signals'
root((dispose) => {
// Create - all types supported (string, array, object, etc.)
const $m = signal(1)
const $x = signal(1)
const $b = signal(0)
// Compute - only re-computed when `$m`, `$x`, or `$b` changes.
const $y = computedSignal(() => $m() * $x() + $b())
// Effect - this will run whenever `$y` is updated.
const stop = effect(() => {
console.log($y())
// Called each time `effect` ends and when finally disposed.
return () => {}
})
$m.set(10) // logs `10` inside effect
// Flush queue synchronously so effect is run.
// Otherwise, effects will be batched and run on the microtask queue.
tick()
$b.set(prev => prev + 5) // logs `15` inside effect
tick()
// Nothing has changed - no re-compute.
$y()
// Stop running effect.
stop()
// ...
// Dispose of all signals inside `root`.
dispose()
})
๐งช Testing
bun test
๐ Changelog
Please see our releases page for more information on what has changed recently.
๐ Contributing
Please review the Contributing Guide for details.
๐ Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
๐๐ผ Credits
Many thanks to the following core technologies & people who have contributed to this package:
๐ License
The MIT License (MIT). Please see LICENSE for more information.
Made with ๐
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago