Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value[T comparable] interface { // Gets the value. This may be a variable or computed value. When this is called // within a watch or computed function it ties the value to that function - telling // it that when this value changes that function can re-execute to get an updated value. Get() T // Sets the value and returns true if successful. Computed values cannot be set. If set // is called on a value with the same value (by == comparison) it has no affect. Set(value T) bool // Detaches the value from the reactivity system. Detach() // Watches this value for changes and calls updated when it changes. Watch(updated func(value T)) Watcher[T] }
A reactive value that can be watched and possibly set.
func Computed ¶
func Computed[T comparable](get func() T) Value[T]
Creates a computed value. A computed value is lazily calculated on Get. If no dependent reactive values have changed it's not recomputed.
func Val ¶
func Val[T comparable](value T) Value[T]
Creates a reactive value. This value can be referenced in watchers and computed values and can trigger those watch functions or computed values to recalculate.
type Watcher ¶
type Watcher[T any] interface { // Stops watching the current values. Watching can be resumed with Update. Stop() // Updates the watcher forcefully, calling the get function and update function. Update() // Returns whether this watcher is lazy. A lazy watcher only processes on Get. IsLazy() bool // Sets whether this watcher is lazy. A lazy watcher only processes on Get. SetLazy(lazy bool) // Gets the latest value. If this is a lazy watcher and it has an outdated value it // will recompute the new value and call the passed update function. Get() T }
A watcher allows control over a watched function and the function invoked when the watched function has a new value. A watcher can be made lazy which means it only processes on Get when there's an outdate value.
func Watch ¶
func Watch[T comparable](get func() T, updated func(value T)) Watcher[T]
Creates a reactive watcher. The get function is called and all reactive values referenced within are tracked. When any of those values are changed get is called again. Any time get is called and a new value is returned updated will be called as well. The returned watcher can be used to stop watching, resume, be marked as lazy, and get the most recent value.