reactivity
Signals, refs, computed values and reactive collections.
Import
ts
import { Signal, Ref, ReactiveArray, ReactiveRecord, ... } from "reactivity";Signal class
ts
class Signal<T>Multicast event channel. Construct with Signal() (no new), subscribe with on / once, fire with emit. Each listener receives the emitted value as its single argument; once listeners auto-unsubscribe after firing. close permanently disables further on / emit calls.
Signal.hasListeners
ts
readonly hasListeners: booleanTrue when at least one persistent or one-shot listener is attached.
Signal.listenerCount
ts
readonly listenerCount: uintTotal count of persistent and one-shot listeners.
Signal.clear
ts
clear(): voidDrop every listener. Does not close the signal.
Signal.close
ts
close(): voidDrop every listener and disable further on / once / emit. Subsequent emits are silently ignored.
Signal.emit
ts
emit(value?: any): voidInvoke every listener with value as the single argument. When omitted, listeners receive undefined.
Signal.off
ts
off(listener: any): voidRemove a previously attached persistent listener. No-op if the listener was never attached.
Signal.on
ts
on(listener: any): FunctionAttach a persistent listener. Returns a function that removes it.
Signal.once
ts
once(listener: any): FunctionAttach a one-shot listener. Auto-removed after the next emit. Returns a function that removes it early.
Ref class
ts
class Ref<T>Reactive value cell. Writes update value immediately, while listeners run once at the next frame boundary. Multiple writes in one frame carry the first old value and last new value to each listener.
Ref.value
ts
value: TTracked read and batched write access to the current value.
Ref.dispose
ts
dispose(): voidPermanently detach listeners and ignore later writes.
Ref.freeze
ts
freeze(): voidSuppress listener delivery until unfreeze.
Ref.off
ts
off(listener: any): voidRemove a persistent listener.
Ref.on
ts
on(listener: any): voidRegister a batched (newValue, oldValue) listener.
Ref.once
ts
once(listener: any): voidRegister a one-shot batched listener.
Ref.peek
ts
peek(): TRead without dependency tracking.
Ref.reset
ts
reset(): voidRestore the constructor value through the normal batched setter.
Ref.set
ts
set(value: T): voidUpdate through the normal batched setter.
Ref.silent
ts
silent(value: T): voidUpdate without listeners or dependency invalidation.
Ref.unfreeze
ts
unfreeze(): voidRe-enable listener delivery.
ReactiveArray class
ts
class ReactiveArray<T>Reactive ordered collection with Go willowui operation parity.
ReactiveArray.at
ts
at(index: int): TGet the element at the given index, tracking access for reactivity.
ReactiveArray.setAt
ts
setAt(index: int, item: T): voidReplace the element at the given index and notify listeners.
ReactiveArray.slice
ts
slice(start: int, end?: int): Array<T>Return a copy of the elements from start to end (end exclusive), without tracking.
ReactiveArray.clone
ts
clone(): ReactiveArray<T>Return a new ReactiveArray with a copy of all items.
ReactiveArray.version
ts
version(): Ref<uint>Return the version Ref: incremented on every change.
ReactiveArray.lengthRef
ts
lengthRef(): Ref<int>Return the length Ref: tracks the current item count.
ReactiveArray.push
ts
push(...items: Array<T>): voidAppend items to the end and notify listeners.
ReactiveArray.pop
ts
pop(): TRemove and return the last item; no-op if the array is empty.
ReactiveArray.unshift
ts
unshift(...items: Array<T>): voidInsert items at the beginning and notify listeners.
ReactiveArray.shift
ts
shift(): TRemove and return the first item; no-op if the array is empty.
ReactiveArray.insert
ts
insert(index: int, item: T): voidInsert an item at the given index, shifting others to the right.
ReactiveArray.remove
ts
remove(index: int): voidRemove the item at the given index.
ReactiveArray.removeAt
ts
removeAt(index: int): voidRemove the item at the given index (same as remove).
ReactiveArray.splice
ts
splice(start: int, deleteCount: int, ...items: Array<T>): voidRemove deleteCount items starting at start, optionally inserting new items.
ReactiveArray.swap
ts
swap(left: int, right: int): voidSwap the elements at left and right indices.
ReactiveArray.move
ts
move(sourceIndex: int, targetIndex: int): voidMove the item at sourceIndex to targetIndex.
ReactiveArray.reverse
ts
reverse(): voidReverse the array in-place.
ReactiveArray.sort
ts
sort(compare: Function): voidSort the array in-place using the compare function.
ReactiveArray.shuffle
ts
shuffle(): voidRandomly shuffle the array in-place.
ReactiveArray.set
ts
set(items: Array<T>): voidReplace all items with the given array.
ReactiveArray.fill
ts
fill(value: T, start: int, end: int): voidFill elements from start to end (end exclusive) with the given value.
ReactiveArray.truncate
ts
truncate(length: int): voidRemove all items after the given length.
ReactiveArray.clear
ts
clear(): voidRemove all items.
ReactiveArray.reserve
ts
reserve(capacity: int): voidReserve capacity (no-op).
ReactiveArray.shrink
ts
shrink(): voidShrink the array to fit (creates a copy).
ReactiveArray.batch
ts
batch(fn: Function): voidRun the function with change notifications batched until it returns.
ReactiveArray.find
ts
find(fn: Function): anyReturn the first item matching the predicate, or undefined.
ReactiveArray.findIndex
ts
findIndex(fn: Function): intReturn the index of the first item matching the predicate, or -1.
ReactiveArray.some
ts
some(fn: Function): booleanReturn true if any item matches the predicate.
ReactiveArray.every
ts
every(fn: Function): booleanReturn true if all items match the predicate.
ReactiveArray.forEach
ts
forEach(fn: Function): voidCall the function for each item with (index, item).
ReactiveArray.filter
ts
filter(fn: Function): ReactiveArray<T>Return a new ReactiveArray with items matching the predicate.
ReactiveArray.concat
ts
concat(...others: Array<ReactiveArray<T>>): ReactiveArray<T>Return a new ReactiveArray with items from this array and all others concatenated.
ReactiveArray.onChange
ts
onChange(fn: Function): FunctionSubscribe to any change; returns a function that unsubscribes.
ReactiveArray.onAdded
ts
onAdded(fn: Function): FunctionSubscribe to item additions; returns a function that unsubscribes.
ReactiveArray.onRemoved
ts
onRemoved(fn: Function): FunctionSubscribe to item removals; returns a function that unsubscribes.
ReactiveArray.onMoved
ts
onMoved(fn: Function): FunctionSubscribe to item moves; returns a function that unsubscribes.
ReactiveArray.onReplaced
ts
onReplaced(fn: Function): FunctionSubscribe to bulk replacements; returns a function that unsubscribes.
ReactiveArray.onItemChanged
ts
onItemChanged(fn: Function): FunctionSubscribe to item updates; returns a function that unsubscribes.
Other members of ReactiveArray
ts
readonly length: int
constructor()
constructor(items: Array<T>)ReactiveRecord class
ts
class ReactiveRecord<V>Reactive string-keyed collection with independently tracked values.
ReactiveRecord.delete
ts
delete(key: string): voidRemove a key and notify listeners.
ReactiveRecord.get
ts
get(key: string): V | undefinedGet the current value of a key, or undefined if not set.
ReactiveRecord.has
ts
has(key: string): booleanReturn true if the key exists.
ReactiveRecord.keys
ts
keys(): Array<string>Return an array of all active keys.
ReactiveRecord.onChange
ts
onChange(fn: Function): FunctionSubscribe to any change; returns a function that unsubscribes.
ReactiveRecord.onFieldChange
ts
onFieldChange(key: string, fn: Function): FunctionSubscribe to changes of a specific key; returns a function that unsubscribes.
ReactiveRecord.ref
ts
ref(key: string): Ref<V>Get the Ref for a key, creating one if needed.
ReactiveRecord.set
ts
set(key: string, value: V): voidSet the value of a key and notify listeners.
ReactiveRecord.setMany
ts
setMany(fields: Map<string, V>): voidSet multiple keys from a map.
ReactiveRecord.toMap
ts
toMap(): Map<string, V>Return a copy of all keys and values as a Map.
Other members of ReactiveRecord
ts
constructor()
constructor(fields: Map<string, V>)Signal function
ts
function Signal(...args: any[]): Signal<any>Create a multicast event channel.
Ref function
ts
function Ref(...args: any[]): Ref<any>Create a reactive value cell with an optional initial value.
computed function
ts
function computed(fn: Function): Ref<any>Create a lazy derived value. Dependency invalidation is batched; the callback re-evaluates only when a dirty value is read or observed.
watchEffect function
ts
function watchEffect(fn: Function): FunctionRun fn immediately, auto-track every reactive read, then rerun it once on the next frame when any current dependency changes. The returned function stops the effect.
Generated from lang/types/reactivity.d.tks in the ThicketScript repository.