Complete API reference for the Pulse reactive state engine.
Creates a reactive signal.
Parameters:
initialValue: T- Initial value for the signaloptions?: SignalOptions<T>- Optional configurationequals?: (a: T, b: T) => boolean- Custom equality functionmiddleware?: Middleware<T>[]- Middleware pipeline
Returns: Signal<T> - A reactive signal
Example:
const count = signal(0);
count.set(5);
console.log(count()); // 5Creates a computed value that automatically recalculates when dependencies change.
Parameters:
fn: () => T- Computation function
Returns: Computed<T> - A computed signal
Example:
const count = signal(0);
const doubled = computed(() => count() * 2);
count.set(5);
console.log(doubled()); // 10Creates an effect that runs when dependencies change.
Parameters:
fn: () => void | (() => void)- Effect function, can return cleanup
Returns: () => void - Cleanup function
Example:
const count = signal(0);
const stop = effect(() => {
console.log('Count:', count());
});
count.set(5); // Logs: "Count: 5"
stop(); // Stop the effectCreates a reactive store (object signal) with convenient update methods.
Parameters:
initialValue: T- Initial object value
Returns: Store<T> - A store signal
Example:
const user = store({ name: 'John', age: 30 });
user.setField('age', 31);
user.update(u => ({ ...u, name: 'Jane' }));Batches multiple signal updates together.
Example:
batch(() => {
a.set(1);
b.set(2);
c.set(3);
}); // All updates batched, effects run onceCreates a signal with history tracking.
Example:
const count = historySignal(0, { maxHistory: 10 });
count.set(1);
count.set(2);
count.undo(); // Back to 1
count.redo(); // Back to 2Creates a signal that persists to storage.
Example:
const settings = persistentSignal(
{ theme: 'light' },
{
key: 'settings',
storage: 'localStorage',
}
);Creates a signal with validation.
Example:
const email = validatedSignal('', {
contract: {
validate: (value) => value.includes('@') || 'Invalid email',
},
});Logging middleware.
Validation middleware.
Transformation middleware.
Example:
const count = signal(0, {
middleware: [
middleware.logging('count'),
middleware.transform(v => Math.max(0, v)),
],
});Creates an async computed value with loading and error states.
Example:
const user = asyncComputed(async () => {
const response = await fetch('/api/user');
return response.json();
});
if (user.loading()) {
console.log('Loading...');
}websocketSignal<T>(url: string, options?: WebSocketSignalOptions): Signal<T | null> & WebSocketMethods
Creates a reactive WebSocket signal.
Example:
const ws = websocketSignal('wss://echo.websocket.org', {
reconnect: true,
});
ws.send('Hello');
ws.subscribe((data) => console.log('Received:', data));reducerSignal<TState, TAction>(reducer: Reducer<TState, TAction>, initialState: TState): ReducerSignal<TState, TAction>
Creates a Redux-like reducer signal.
Example:
const counter = reducerSignal(
(state, action) => {
switch (action.type) {
case 'increment': return state + 1;
case 'decrement': return state - 1;
default: return state;
}
},
0
);
counter.dispatch({ type: 'increment' });stateMachine<TState>(config: StateMachineConfig<TState>, onStateChange?: (state: TState) => void): StateMachine<TState>
Creates a state machine.
Example:
const machine = stateMachine({
initialState: 'idle',
states: {
idle: { transitions: { start: 'loading' } },
loading: { transitions: { success: 'done' } },
},
});
machine.transition('start');Creates an animated signal.
Example:
const position = animatedSignal(0);
position.animate(100, {
duration: 1000,
easing: easing.easeInOut,
});React hook for using a signal.
React hook for using a computed value.
React hook for using an effect.
Example:
function Counter() {
const [count, setCount] = useSignal(signal(0));
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}Vue composable for using a signal.
Example:
export default {
setup() {
const count = useSignal(signal(0));
return { count };
}
}Clones a signal.
Merges multiple signals.
Gets the difference between two signals.
promiseSignal<T>(promise: Promise<T>): Signal<T | null> & { loading: Signal<boolean>; error: Signal<Error | null> }
Creates a signal from a promise.
serializableSignal<T>(initialValue: T, options?: SerializationOptions): Signal<T> & SerializationMethods
Creates a serializable signal.
Enables DevTools integration.
Creates a signal with DevTools integration.
Logs signal updates to console.
Profiles signal performance.
interface Signal<T> {
(): T;
set(value: T): void;
update(fn: (value: T) => T): void;
subscribe(callback: (value: T) => void): () => void;
}interface Computed<T> {
(): T;
subscribe(callback: (value: T) => void): () => void;
}interface Store<T> extends Signal<T> {
setField<K extends keyof T>(key: K, value: T[K]): void;
update(updater: (value: T) => T): void;
}Wraps a function with error handling.
Creates an error boundary.
Batches updates for better performance.
Creates a debounced signal.
Creates a throttled signal.
Limits the number of subscribers.
Cleans up a signal.
Creates a mock signal for testing.
Waits for a signal to match a predicate.
Collects signal values over time.