Skip to content

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: boolean

True when at least one persistent or one-shot listener is attached.

Signal.listenerCount ​

ts
readonly listenerCount: uint

Total count of persistent and one-shot listeners.

Signal.clear ​

ts
clear(): void

Drop every listener. Does not close the signal.

Signal.close ​

ts
close(): void

Drop every listener and disable further on / once / emit. Subsequent emits are silently ignored.

Signal.emit ​

ts
emit(value?: any): void

Invoke every listener with value as the single argument. When omitted, listeners receive undefined.

Signal.off ​

ts
off(listener: any): void

Remove a previously attached persistent listener. No-op if the listener was never attached.

Signal.on ​

ts
on(listener: any): Function

Attach a persistent listener. Returns a function that removes it.

Signal.once ​

ts
once(listener: any): Function

Attach 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: T

Tracked read and batched write access to the current value.

Ref.dispose ​

ts
dispose(): void

Permanently detach listeners and ignore later writes.

Ref.freeze ​

ts
freeze(): void

Suppress listener delivery until unfreeze.

Ref.off ​

ts
off(listener: any): void

Remove a persistent listener.

Ref.on ​

ts
on(listener: any): void

Register a batched (newValue, oldValue) listener.

Ref.once ​

ts
once(listener: any): void

Register a one-shot batched listener.

Ref.peek ​

ts
peek(): T

Read without dependency tracking.

Ref.reset ​

ts
reset(): void

Restore the constructor value through the normal batched setter.

Ref.set ​

ts
set(value: T): void

Update through the normal batched setter.

Ref.silent ​

ts
silent(value: T): void

Update without listeners or dependency invalidation.

Ref.unfreeze ​

ts
unfreeze(): void

Re-enable listener delivery.

ReactiveArray class ​

ts
class ReactiveArray<T>

Reactive ordered collection with Go willowui operation parity.

ReactiveArray.at ​

ts
at(index: int): T

Get the element at the given index, tracking access for reactivity.

ReactiveArray.setAt ​

ts
setAt(index: int, item: T): void

Replace 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>): void

Append items to the end and notify listeners.

ReactiveArray.pop ​

ts
pop(): T

Remove and return the last item; no-op if the array is empty.

ReactiveArray.unshift ​

ts
unshift(...items: Array<T>): void

Insert items at the beginning and notify listeners.

ReactiveArray.shift ​

ts
shift(): T

Remove and return the first item; no-op if the array is empty.

ReactiveArray.insert ​

ts
insert(index: int, item: T): void

Insert an item at the given index, shifting others to the right.

ReactiveArray.remove ​

ts
remove(index: int): void

Remove the item at the given index.

ReactiveArray.removeAt ​

ts
removeAt(index: int): void

Remove the item at the given index (same as remove).

ReactiveArray.splice ​

ts
splice(start: int, deleteCount: int, ...items: Array<T>): void

Remove deleteCount items starting at start, optionally inserting new items.

ReactiveArray.swap ​

ts
swap(left: int, right: int): void

Swap the elements at left and right indices.

ReactiveArray.move ​

ts
move(sourceIndex: int, targetIndex: int): void

Move the item at sourceIndex to targetIndex.

ReactiveArray.reverse ​

ts
reverse(): void

Reverse the array in-place.

ReactiveArray.sort ​

ts
sort(compare: Function): void

Sort the array in-place using the compare function.

ReactiveArray.shuffle ​

ts
shuffle(): void

Randomly shuffle the array in-place.

ReactiveArray.set ​

ts
set(items: Array<T>): void

Replace all items with the given array.

ReactiveArray.fill ​

ts
fill(value: T, start: int, end: int): void

Fill elements from start to end (end exclusive) with the given value.

ReactiveArray.truncate ​

ts
truncate(length: int): void

Remove all items after the given length.

ReactiveArray.clear ​

ts
clear(): void

Remove all items.

ReactiveArray.reserve ​

ts
reserve(capacity: int): void

Reserve capacity (no-op).

ReactiveArray.shrink ​

ts
shrink(): void

Shrink the array to fit (creates a copy).

ReactiveArray.batch ​

ts
batch(fn: Function): void

Run the function with change notifications batched until it returns.

ReactiveArray.find ​

ts
find(fn: Function): any

Return the first item matching the predicate, or undefined.

ReactiveArray.findIndex ​

ts
findIndex(fn: Function): int

Return the index of the first item matching the predicate, or -1.

ReactiveArray.some ​

ts
some(fn: Function): boolean

Return true if any item matches the predicate.

ReactiveArray.every ​

ts
every(fn: Function): boolean

Return true if all items match the predicate.

ReactiveArray.forEach ​

ts
forEach(fn: Function): void

Call 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): Function

Subscribe to any change; returns a function that unsubscribes.

ReactiveArray.onAdded ​

ts
onAdded(fn: Function): Function

Subscribe to item additions; returns a function that unsubscribes.

ReactiveArray.onRemoved ​

ts
onRemoved(fn: Function): Function

Subscribe to item removals; returns a function that unsubscribes.

ReactiveArray.onMoved ​

ts
onMoved(fn: Function): Function

Subscribe to item moves; returns a function that unsubscribes.

ReactiveArray.onReplaced ​

ts
onReplaced(fn: Function): Function

Subscribe to bulk replacements; returns a function that unsubscribes.

ReactiveArray.onItemChanged ​

ts
onItemChanged(fn: Function): Function

Subscribe 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): void

Remove a key and notify listeners.

ReactiveRecord.get ​

ts
get(key: string): V | undefined

Get the current value of a key, or undefined if not set.

ReactiveRecord.has ​

ts
has(key: string): boolean

Return true if the key exists.

ReactiveRecord.keys ​

ts
keys(): Array<string>

Return an array of all active keys.

ReactiveRecord.onChange ​

ts
onChange(fn: Function): Function

Subscribe to any change; returns a function that unsubscribes.

ReactiveRecord.onFieldChange ​

ts
onFieldChange(key: string, fn: Function): Function

Subscribe 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): void

Set the value of a key and notify listeners.

ReactiveRecord.setMany ​

ts
setMany(fields: Map<string, V>): void

Set 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): Function

Run 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.