This package implements a reactive graph-based state management system where values automatically update based on their dependencies. It is inspired by the Angular JS framework and built around three core concepts:
- Signal: wraps a value and notifies dependents when it changes.
- Computed signal: automatically derived values that update when their dependencies change.
- Effect: callback that run when its dependent signals change.
Simple example:
using StateSignals
x = Signal(1)
y = Signal(2)
z = computed(() -> x() + y()) # z is 3
effect(() -> println("Sum changed to: ", z()))
x(5) # Prints "Sum changed to: 7"
Using resources for long computations:
using StateSignals
s = Signal(0)
r = Resource([s]) do
sleep(3)
println("Resource acquired")
s()*3
end
s(3)