1 | declare const BRAND_SYMBOL: unique symbol;
|
2 | /**
|
3 | * Combine multiple value updates into one "commit" at the end of the provided callback.
|
4 | *
|
5 | * Batches can be nested and changes are only flushed once the outermost batch callback
|
6 | * completes.
|
7 | *
|
8 | * Accessing a signal that has been modified within a batch will reflect its updated
|
9 | * value.
|
10 | *
|
11 | * @param fn The callback function.
|
12 | * @returns The value returned by the callback.
|
13 | */
|
14 | declare function batch<T>(fn: () => T): T;
|
15 | /**
|
16 | * Run a callback function that can access signal values without
|
17 | * subscribing to the signal updates.
|
18 | *
|
19 | * @param fn The callback function.
|
20 | * @returns The value returned by the callback.
|
21 | */
|
22 | declare function untracked<T>(fn: () => T): T;
|
23 | /**
|
24 | * The base class for plain and computed signals.
|
25 | */
|
26 | declare class Signal<T = any> {
|
27 | constructor(value?: T);
|
28 | subscribe(fn: (value: T) => void): () => void;
|
29 | valueOf(): T;
|
30 | toString(): string;
|
31 | toJSON(): T;
|
32 | peek(): T;
|
33 | brand: typeof BRAND_SYMBOL;
|
34 | get value(): T;
|
35 | set value(value: T);
|
36 | }
|
37 | /**
|
38 | * Create a new plain signal.
|
39 | *
|
40 | * @param value The initial value for the signal.
|
41 | * @returns A new signal.
|
42 | */
|
43 | declare function signal<T>(value: T): Signal<T>;
|
44 | /**
|
45 | * An interface for read-only signals.
|
46 | */
|
47 | interface ReadonlySignal<T = any> extends Signal<T> {
|
48 | readonly value: T;
|
49 | }
|
50 | /**
|
51 | * Create a new signal that is computed based on the values of other signals.
|
52 | *
|
53 | * The returned computed signal is read-only, and its value is automatically
|
54 | * updated when any signals accessed from within the callback function change.
|
55 | *
|
56 | * @param fn The effect callback.
|
57 | * @returns A new read-only signal.
|
58 | */
|
59 | declare function computed<T>(fn: () => T): ReadonlySignal<T>;
|
60 | /**
|
61 | * Create an effect to run arbitrary code in response to signal changes.
|
62 | *
|
63 | * An effect tracks which signals are accessed within the given callback
|
64 | * function `fn`, and re-runs the callback when those signals change.
|
65 | *
|
66 | * The callback may return a cleanup function. The cleanup function gets
|
67 | * run once, either when the callback is next called or when the effect
|
68 | * gets disposed, whichever happens first.
|
69 | *
|
70 | * @param fn The effect callback.
|
71 | * @returns A function for disposing the effect.
|
72 | */
|
73 | declare function effect(fn: () => unknown): () => void;
|
74 | export { signal, computed, effect, batch, untracked, Signal, ReadonlySignal };
|