Namespace: Signals

Signals

Core Signals API for reactive state management. Provides primitives for creating reactive values, computed values, and async computations.
Source:

Methods

(static) batch(fn) → {*}

Alias for effect(). Batches multiple signal updates together.
Parameters:
Name Type Description
fn function Function containing signal updates
Source:
See:
Returns:
Return value of the function
Type
*

(static) computed(fn, nameopt) → {ComputedSignal}

Creates a computed signal that automatically recalculates when dependencies change. Dependencies are tracked automatically when accessed inside the computation function.
Parameters:
Name Type Attributes Default Description
fn function Computation function that returns the computed value
name string | null <optional>
null Optional name for debugging
Source:
Throws:
If circular dependency is detected
Type
Error
Returns:
Computed signal with dispose method
Type
ComputedSignal
Example
const firstName = Signals.create("John");
const lastName = Signals.create("Doe");
const fullName = Signals.computed(() => `${firstName.get()} ${lastName.get()}`);
console.log(fullName.get()); // "John Doe"

(static) computedAsync(fn, nameopt) → {ComputedSignal.<AsyncState>}

Creates a computed signal for async operations that tracks loading/error/data states. Automatically cancels previous execution when dependencies change.
Parameters:
Name Type Attributes Default Description
fn function Async computation function
name string | null <optional>
null Optional name for debugging
Source:
Returns:
Signal containing {status, data, error, loading}
Type
ComputedSignal.<AsyncState>
Example
const userId = Signals.create(1);
const userData = Signals.computedAsync(async (cancel) => {
  const response = await fetch(`/api/users/${userId.get()}`);
  if (cancel.cancelled) return;
  return response.json();
});
// userData.get() returns {status: "pending", data: undefined, error: null, loading: true}

(static) create(value, equalsopt, nameopt) → {Signal}

Creates a reactive signal that holds a single value. Signals track dependencies and notify subscribers when the value changes.
Parameters:
Name Type Attributes Default Description
value * Initial value
equals function <optional>
(a, b) => a === b Equality function to determine if value changed
name string | null <optional>
null Optional name for debugging
Source:
Returns:
Signal object with get/set/subscribe methods
Type
Signal
Example
const count = Signals.create(0, undefined, "count");
count.set(5);
console.log(count.get()); // 5
count.subscribe(val => console.log("Changed:", val));

(static) effect(fn) → {*}

Batches multiple signal updates to prevent redundant recalculations. All updates within the function are queued and executed once at the end.
Parameters:
Name Type Description
fn function Function containing signal updates
Source:
Returns:
Return value of the function
Type
*
Example
Signals.effect(() => {
  count.set(1);
  count.set(2);
  count.set(3);
}); // Subscribers only notified once with value 3