0.58.73 โ€ข Published 3 months ago

@stacksjs/signals v0.58.73

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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:

Discussions on GitHub

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 ๐Ÿ’™

0.58.73

3 months ago

0.58.72

3 months ago

0.58.70

3 months ago

0.58.71

3 months ago

0.58.69

3 months ago

0.58.65

3 months ago

0.58.66

3 months ago

0.58.67

3 months ago

0.58.68

3 months ago

0.58.60

3 months ago

0.58.61

3 months ago

0.58.62

3 months ago

0.58.63

3 months ago

0.58.64

3 months ago

0.58.59

3 months ago

0.58.58

3 months ago

0.58.57

3 months ago

0.58.56

3 months ago

0.58.55

3 months ago

0.58.52

3 months ago

0.58.53

3 months ago

0.58.50

3 months ago

0.58.51

3 months ago

0.58.49

3 months ago

0.58.47

3 months ago

0.58.48

3 months ago

0.58.43

3 months ago

0.58.44

3 months ago

0.58.45

3 months ago

0.58.46

3 months ago

0.58.27

4 months ago

0.58.28

4 months ago

0.58.19

4 months ago

0.58.20

4 months ago

0.58.21

4 months ago

0.58.22

4 months ago

0.58.24

4 months ago

0.56.35

10 months ago

0.56.34

10 months ago

0.57.4

10 months ago

0.57.2

10 months ago

0.57.3

10 months ago

0.56.31

10 months ago

0.56.30

10 months ago

0.56.33

10 months ago

0.56.32

10 months ago

0.56.24

10 months ago

0.56.23

10 months ago

0.56.28

10 months ago

0.56.27

10 months ago

0.56.29

10 months ago

0.56.3

11 months ago

0.53.1

12 months ago

0.52.10

12 months ago

0.52.9

12 months ago

0.52.8

12 months ago

0.52.7

12 months ago

0.52.5

12 months ago

0.52.6

12 months ago

0.52.4

12 months ago

0.52.3

12 months ago

0.52.2

12 months ago

0.52.1

12 months ago

0.52.0

12 months ago