API reference

signalium/utils

Functions

watchOnce

export function watchOnce<T>(fn: () => T): T;

Run a function in a watched reactive context. This activates its relays without subscribing to later updates.

Synchronous values return immediately. Synchronous errors are rethrown. Asynchronous results return a native promise with the same fulfillment value or rejection reason. The watcher stays strongly retained until the operation fulfills or rejects, then releases its watch. Relay deactivation follows the configured scheduler and waits for other watchers to release their watches.

There is no timeout or cancellation option. An operation that never settles keeps its watcher and dependencies retained. Ignoring the result or timing out a separate Promise.race does not release the watch. Bound the underlying work when an operation can be abandoned.

import { watchOnce } from 'signalium/utils';

const account = await watchOnce(() => getSelectedAccount());

hashValue

export function hashValue(value: unknown): number;

Stable hash for arbitrary values. Values are hashed semi-deeply, meaning that objects are hashed by their properties, arrays are hashed by their items, and so on, but only if they are plain objects or arrays. Class instances are hashed by reference by default, but you can override this behavior by providing a custom hash function using registerCustomHash.

ParameterTypeDescription
valueunknownValue to hash

registerCustomHash

export function registerCustomHash<T>(
  ctor: { new (): T },
  hashFn: (obj: T) => number,
): void;

Provide a custom hash for a prototype. This is useful for hashing class instances, which are hashed by reference by default.

ParameterTypeDescription
ctor{ new(): T }Constructor whose prototype gets the hash
hashFn(obj: T) => numberHash function
Previous
signalium/react