0.58.73 โ€ข Published 1 year ago

@stacksjs/signals v0.58.73

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year 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

1 year ago

0.58.72

1 year ago

0.58.70

1 year ago

0.58.71

1 year ago

0.58.69

1 year ago

0.58.65

1 year ago

0.58.66

1 year ago

0.58.67

1 year ago

0.58.68

1 year ago

0.58.60

1 year ago

0.58.61

1 year ago

0.58.62

1 year ago

0.58.63

1 year ago

0.58.64

1 year ago

0.58.59

1 year ago

0.58.58

1 year ago

0.58.57

1 year ago

0.58.56

1 year ago

0.58.55

1 year ago

0.58.52

1 year ago

0.58.53

1 year ago

0.58.50

1 year ago

0.58.51

1 year ago

0.58.49

1 year ago

0.58.47

1 year ago

0.58.48

1 year ago

0.58.43

1 year ago

0.58.44

1 year ago

0.58.45

1 year ago

0.58.46

1 year ago

0.58.27

1 year ago

0.58.28

1 year ago

0.58.19

1 year ago

0.58.20

1 year ago

0.58.21

1 year ago

0.58.22

1 year ago

0.58.24

1 year ago

0.56.35

2 years ago

0.56.34

2 years ago

0.57.4

2 years ago

0.57.2

2 years ago

0.57.3

2 years ago

0.56.31

2 years ago

0.56.30

2 years ago

0.56.33

2 years ago

0.56.32

2 years ago

0.56.24

2 years ago

0.56.23

2 years ago

0.56.28

2 years ago

0.56.27

2 years ago

0.56.29

2 years ago

0.56.3

2 years ago

0.53.1

2 years ago

0.52.10

2 years ago

0.52.9

2 years ago

0.52.8

2 years ago

0.52.7

2 years ago

0.52.5

2 years ago

0.52.6

2 years ago

0.52.4

2 years ago

0.52.3

2 years ago

0.52.2

2 years ago

0.52.1

2 years ago

0.52.0

2 years ago