@solidjs/signals 0.13.13 → 2.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +8 -7
  2. package/dist/dev.js +502 -244
  3. package/dist/node.cjs +1501 -1308
  4. package/dist/prod.js +1134 -929
  5. package/dist/types/boundaries.d.ts +124 -3
  6. package/dist/types/core/action.d.ts +34 -0
  7. package/dist/types/core/constants.d.ts +24 -0
  8. package/dist/types/core/context.d.ts +10 -2
  9. package/dist/types/core/core.d.ts +108 -9
  10. package/dist/types/core/dev.d.ts +1 -1
  11. package/dist/types/core/effect.d.ts +3 -2
  12. package/dist/types/core/error.d.ts +24 -0
  13. package/dist/types/core/external.d.ts +19 -0
  14. package/dist/types/core/graph.d.ts +1 -0
  15. package/dist/types/core/owner.d.ts +93 -3
  16. package/dist/types/core/scheduler.d.ts +27 -2
  17. package/dist/types/core/types.d.ts +3 -6
  18. package/dist/types/index.d.ts +2 -2
  19. package/dist/types/map.d.ts +32 -3
  20. package/dist/types/signals.d.ts +338 -39
  21. package/dist/types/store/optimistic.d.ts +38 -12
  22. package/dist/types/store/projection.d.ts +55 -15
  23. package/dist/types/store/reconcile.d.ts +22 -0
  24. package/dist/types/store/store.d.ts +72 -15
  25. package/dist/types/store/storePath.d.ts +28 -0
  26. package/dist/types/store/utils.d.ts +78 -7
  27. package/dist/types-cjs/boundaries.d.cts +173 -0
  28. package/dist/types-cjs/core/action.d.cts +35 -0
  29. package/dist/types-cjs/core/async.d.cts +6 -0
  30. package/dist/types-cjs/core/constants.d.cts +49 -0
  31. package/dist/types-cjs/core/context.d.cts +36 -0
  32. package/dist/types-cjs/core/core.d.cts +153 -0
  33. package/dist/types-cjs/core/dev.d.cts +49 -0
  34. package/dist/types-cjs/core/effect.d.cts +31 -0
  35. package/dist/types-cjs/core/error.d.cts +38 -0
  36. package/dist/types-cjs/core/external.d.cts +45 -0
  37. package/dist/types-cjs/core/graph.d.cts +4 -0
  38. package/dist/types-cjs/core/heap.d.cts +14 -0
  39. package/dist/types-cjs/core/index.d.cts +12 -0
  40. package/dist/types-cjs/core/lanes.d.cts +54 -0
  41. package/dist/types-cjs/core/owner.d.cts +116 -0
  42. package/dist/types-cjs/core/scheduler.d.cts +106 -0
  43. package/dist/types-cjs/core/types.d.cts +83 -0
  44. package/dist/types-cjs/index.d.cts +9 -0
  45. package/dist/types-cjs/map.d.cts +53 -0
  46. package/dist/types-cjs/package.json +3 -0
  47. package/dist/types-cjs/signals.d.cts +491 -0
  48. package/dist/types-cjs/store/index.d.cts +9 -0
  49. package/dist/types-cjs/store/optimistic.d.cts +45 -0
  50. package/dist/types-cjs/store/projection.d.cts +66 -0
  51. package/dist/types-cjs/store/reconcile.d.cts +23 -0
  52. package/dist/types-cjs/store/store.d.cts +125 -0
  53. package/dist/types-cjs/store/storePath.d.cts +58 -0
  54. package/dist/types-cjs/store/utils.d.cts +114 -0
  55. package/package.json +32 -24
@@ -5,18 +5,29 @@ export interface BoundaryComputed<T> extends Computed<T> {
5
5
  }
6
6
  type RevealSlot = CollectionQueue | RevealController;
7
7
  type BoolAccessor = () => boolean;
8
+ export type RevealOrder = "sequential" | "together" | "natural";
9
+ type OrderAccessor = () => RevealOrder;
8
10
  export declare class RevealController {
9
- _togetherAccessor: BoolAccessor;
11
+ _orderAccessor: OrderAccessor;
10
12
  _collapsedAccessor: BoolAccessor;
11
13
  _slots: RevealSlot[];
12
14
  _parentController?: RevealController;
13
15
  _disabled: Signal<boolean>;
14
16
  _collapsed: Signal<boolean>;
15
17
  _ready: boolean;
18
+ _minimallyReady: boolean;
16
19
  _evaluating: boolean;
17
- constructor(together: BoolAccessor, collapsed: BoolAccessor);
20
+ constructor(order: OrderAccessor, collapsed: BoolAccessor);
18
21
  _forEachOwnedSlot(fn: (slot: RevealSlot) => boolean | void): boolean;
19
22
  isReady(): boolean;
23
+ /**
24
+ * "Minimally ready" = this group has something visible to show under its own policy.
25
+ * Used by an enclosing `together` group to decide when it can release.
26
+ * - `together`: fully ready (atomic).
27
+ * - `sequential`: the first owned slot is minimally ready (frontier can advance).
28
+ * - `natural`: any owned slot is minimally ready.
29
+ */
30
+ isMinimallyReady(): boolean;
20
31
  register(slot: RevealSlot): void;
21
32
  unregister(slot: RevealSlot): void;
22
33
  evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
@@ -37,14 +48,124 @@ export declare class CollectionQueue extends Queue {
37
48
  notify(node: Effect<any>, type: number, flags: number, error?: any): boolean;
38
49
  checkSources(): void;
39
50
  }
51
+ /**
52
+ * Lower-level primitive that backs the `<Loading>` flow control. Catches
53
+ * pending async reads inside `fn` and renders `fallback` until they settle.
54
+ *
55
+ * App code should use `<Loading fallback={...}>` instead — reach for this only
56
+ * when authoring custom boundary components.
57
+ *
58
+ * @param fn the tracked subtree
59
+ * @param fallback the fallback shown while async reads in `fn` are unresolved
60
+ * @param options `on` — accessor whose value scopes the boundary; when set,
61
+ * transitions caused by writes to other reactive sources are *not* caught
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // Custom boundary component built on top of the primitive.
66
+ * function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
67
+ * return createLoadingBoundary(
68
+ * () => props.children,
69
+ * () => props.fallback
70
+ * ) as unknown as JSX.Element;
71
+ * }
72
+ * ```
73
+ */
40
74
  export declare function createLoadingBoundary(fn: () => any, fallback: () => any, options?: {
41
75
  on?: () => any;
42
76
  }): import("./signals.js").Accessor<unknown>;
77
+ /**
78
+ * Lower-level primitive that backs the `<Errored>` flow control. Catches
79
+ * thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
80
+ * `reset()` recomputes the failing sources so the boundary can attempt to
81
+ * recover.
82
+ *
83
+ * App code should use `<Errored fallback={...}>` instead — reach for this only
84
+ * when authoring custom boundary components.
85
+ *
86
+ * @example
87
+ * ```tsx
88
+ * // Custom boundary that wraps the primitive and adds telemetry.
89
+ * function TracedErrored(props: { fallback: (e: unknown) => JSX.Element; children: JSX.Element }) {
90
+ * return createErrorBoundary(
91
+ * () => props.children,
92
+ * (err, reset) => {
93
+ * reportError(err);
94
+ * return props.fallback(err);
95
+ * }
96
+ * ) as unknown as JSX.Element;
97
+ * }
98
+ * ```
99
+ */
43
100
  export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): import("./signals.js").Accessor<unknown>;
101
+ /**
102
+ * Coordinate the reveal timing of sibling loading boundaries.
103
+ *
104
+ * Accepts reactive accessors:
105
+ * - `order`: `"sequential"` (default) | `"together"` | `"natural"`.
106
+ * - `"sequential"` — classic frontier reveal: siblings reveal in registration order
107
+ * as each resolves; later siblings stay hidden until earlier ones complete.
108
+ * - `"together"` — every direct slot stays on its fallback until the whole group
109
+ * is "minimally ready" (each direct slot has produced its own first visible
110
+ * content under its own order), then the whole group releases at once.
111
+ * - `"natural"` — children reveal independently (as each resolves). At the top
112
+ * level this is a no-op compared to not using `createRevealOrder`; the mode
113
+ * exists for nesting, where the group registers as a single composite slot to
114
+ * any enclosing `createRevealOrder`.
115
+ * - `collapsed`: only meaningful when `order === "sequential"`. When set, tail siblings
116
+ * past the frontier suppress their own fallback output. Ignored under `"together"`
117
+ * and `"natural"` — those orders have no frontier.
118
+ *
119
+ * Nested `createRevealOrder` groups compose: the inner controller registers as a
120
+ * single slot in the outer controller and is held on its fallbacks until the outer
121
+ * releases that slot. Once released, the inner controller runs its own order locally
122
+ * over anything still pending. There is no opt-out from an outer hold.
123
+ *
124
+ * "Minimally ready" is what an order considers its first visible content:
125
+ * - `sequential` — frontier-0 is minimally ready (leaf: on resolve; nested: via its
126
+ * own minimal signal).
127
+ * - `together` — every direct slot is minimally ready.
128
+ * - `natural` — any direct slot has visible content (leaves on resolve; nested
129
+ * composites when fully ready, since natural treats composites as atomic).
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
134
+ * // programmatically. App code uses the JSX `<Reveal>` component instead.
135
+ * // Both options are accessors so they can react to state changes.
136
+ * createRevealOrder(
137
+ * () => renderSiblings(),
138
+ * { order: () => mode(), collapsed: () => true }
139
+ * );
140
+ * ```
141
+ */
44
142
  export declare function createRevealOrder<T>(fn: () => T, options?: {
45
- together?: BoolAccessor;
143
+ order?: OrderAccessor;
46
144
  collapsed?: BoolAccessor;
47
145
  }): T;
146
+ /**
147
+ * Resolves a children value to its renderable form: unwraps zero-arg functions
148
+ * (accessors), recursively flattens arrays, and optionally skips
149
+ * non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
150
+ *
151
+ * Used internally by flow components and by the renderer to walk a children
152
+ * tree. App code rarely needs this directly — see `children()` in `solid-js`
153
+ * for the user-facing helper that memoizes the result.
154
+ *
155
+ * @param children value or array of values to flatten
156
+ * @param options
157
+ * - `skipNonRendered` — drop values that won't render
158
+ * - `doNotUnwrap` — leave function children as-is (caller will resolve)
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * // Custom renderer walking a children tree manually. Most authors should
163
+ * // use `children()` from solid-js, which memoizes the resolved value.
164
+ * function renderChildren(value: unknown): unknown {
165
+ * return flatten(value, { skipNonRendered: true });
166
+ * }
167
+ * ```
168
+ */
48
169
  export declare function flatten(children: any, options?: {
49
170
  skipNonRendered?: boolean;
50
171
  doNotUnwrap?: boolean;
@@ -1 +1,35 @@
1
+ /**
2
+ * Wraps a generator function so each invocation runs as a single transaction
3
+ * (a "transition") that batches every signal/store write between yields. The
4
+ * surrounding UI sees one atomic update per yielded step; nothing is committed
5
+ * until the action either completes or the next `yield` resolves.
6
+ *
7
+ * Yield promises (or any awaitable) inside the generator — the action waits
8
+ * for each before continuing, but the writes you made beforehand are already
9
+ * visible (or held by `<Loading>` if optimistic). Yield bare values for
10
+ * synchronous batched steps.
11
+ *
12
+ * Each call returns a `Promise` that resolves with the generator's return
13
+ * value, or rejects if it throws. Pair with `createOptimistic` /
14
+ * `createOptimisticStore` to apply tentative writes that auto-revert if the
15
+ * action fails.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const [todos, setTodos] = createOptimisticStore<Todo[]>([]);
20
+ *
21
+ * const addTodo = action(function* (text: string) {
22
+ * const tempId = crypto.randomUUID();
23
+ * setTodos(t => { t.push({ id: tempId, text, pending: true }); }); // optimistic
24
+ * const saved = yield api.createTodo(text); // network round-trip
25
+ * setTodos(t => {
26
+ * const i = t.findIndex(x => x.id === tempId);
27
+ * if (i >= 0) t[i] = saved;
28
+ * });
29
+ * return saved;
30
+ * });
31
+ *
32
+ * await addTodo("buy milk");
33
+ * ```
34
+ */
1
35
  export declare function action<Args extends any[], Y, R>(genFn: (...args: Args) => Generator<Y, R, any> | AsyncGenerator<Y, R, any>): (...args: Args) => Promise<R>;
@@ -9,6 +9,12 @@ export declare const REACTIVE_DISPOSED: number;
9
9
  export declare const REACTIVE_OPTIMISTIC_DIRTY: number;
10
10
  export declare const REACTIVE_SNAPSHOT_STALE: number;
11
11
  export declare const REACTIVE_LAZY: number;
12
+ export declare const CONFIG_OWNED_WRITE: number;
13
+ export declare const CONFIG_NO_SNAPSHOT: number;
14
+ export declare const CONFIG_TRANSPARENT: number;
15
+ export declare const CONFIG_IN_SNAPSHOT_SCOPE: number;
16
+ export declare const CONFIG_CHILDREN_FORBIDDEN: number;
17
+ export declare const CONFIG_AUTO_DISPOSE: number;
12
18
  export declare const STATUS_NONE = 0;
13
19
  export declare const STATUS_PENDING: number;
14
20
  export declare const STATUS_ERROR: number;
@@ -22,4 +28,22 @@ export declare const NO_SNAPSHOT: {};
22
28
  export declare const STORE_SNAPSHOT_PROPS = "sp";
23
29
  export declare const SUPPORTS_PROXY: boolean;
24
30
  export declare const defaultContext: {};
31
+ /**
32
+ * Brand symbol used by `Refreshable<T>` values (projection stores, async
33
+ * memos) to expose their underlying computation to `refresh()`. Not part of
34
+ * the user-facing API.
35
+ *
36
+ * @internal
37
+ */
25
38
  export declare const $REFRESH: unique symbol;
39
+ /**
40
+ * Brand applied to derived/projected stores indicating they participate in
41
+ * the `refresh()` re-run protocol. Use this alias instead of inlining
42
+ * `T & { [$REFRESH]: any }` so that user-defined hooks that wrap
43
+ * `createOptimisticStore` / `createProjection` / projection-form
44
+ * `createStore` can have their return types inferred without leaking the
45
+ * internal `$REFRESH` symbol into public type signatures (TS4058).
46
+ */
47
+ export type Refreshable<T> = T & {
48
+ readonly [$REFRESH]: any;
49
+ };
@@ -14,15 +14,23 @@ export type ContextRecord = Record<string | symbol, unknown>;
14
14
  */
15
15
  export declare function createContext<T>(defaultValue?: T, description?: string): Context<T>;
16
16
  /**
17
- * Attempts to get a context value for the given key.
17
+ * Low-level owner-targeted context read. The user-facing read API is
18
+ * `useContext` (in `solid-js`), which wraps this primitive. Exposed here for
19
+ * cross-package wiring (e.g. hydration-aware context plumbing).
18
20
  *
19
21
  * @throws `NoOwnerError` if there's no owner at the time of call.
20
22
  * @throws `ContextNotFoundError` if a context value has not been set yet.
23
+ *
24
+ * @internal
21
25
  */
22
26
  export declare function getContext<T>(context: Context<T>, owner?: Owner | null): T;
23
27
  /**
24
- * Attempts to set a context value on the parent scope with the given key.
28
+ * Low-level owner-targeted context write. The user-facing API is
29
+ * `createContext` (in `solid-js`); its provider component wraps this
30
+ * primitive. Exposed here for cross-package wiring.
25
31
  *
26
32
  * @throws `NoOwnerError` if there's no owner at the time of call.
33
+ *
34
+ * @internal
27
35
  */
28
36
  export declare function setContext<T>(context: Context<T>, value?: T, owner?: Owner | null): void;
@@ -1,6 +1,7 @@
1
- import { $REFRESH } from "./constants.js";
1
+ import { type Refreshable } from "./constants.js";
2
2
  import { type OptimisticLane } from "./lanes.js";
3
3
  import type { Computed, FirewallSignal, NodeOptions, Owner, Signal } from "./types.js";
4
+ export declare const PRIMITIVE_IN_FORBIDDEN_SCOPE_MESSAGE = "[PRIMITIVE_IN_FORBIDDEN_SCOPE] Cannot create reactive primitives inside createTrackedEffect or owner-backed onSettled";
4
5
  export declare let tracking: boolean;
5
6
  export declare let stale: boolean;
6
7
  export declare let refreshing: boolean;
@@ -17,11 +18,11 @@ export declare function releaseSnapshotScope(owner: Owner): void;
17
18
  export declare function clearSnapshots(): void;
18
19
  export declare function recompute(el: Computed<any>, create?: boolean): void;
19
20
  export declare function computed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>): Computed<T>;
20
- export declare function computed<T>(fn: (prev: T) => T | PromiseLike<T> | AsyncIterable<T>, initialValue?: T, options?: NodeOptions<T>): Computed<T>;
21
+ export declare function computed<T>(fn: (prev: T) => T | PromiseLike<T> | AsyncIterable<T>, options?: NodeOptions<T>): Computed<T>;
21
22
  export declare function signal<T>(v: T, options?: NodeOptions<T>): Signal<T>;
22
23
  export declare function signal<T>(v: T, options?: NodeOptions<T>, firewall?: Computed<any>): FirewallSignal<T>;
23
24
  export declare function optimisticSignal<T>(v: T, options?: NodeOptions<T>): Signal<T>;
24
- export declare function optimisticComputed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>, initialValue?: T, options?: NodeOptions<T>): Computed<T>;
25
+ export declare function optimisticComputed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>, options?: NodeOptions<T>): Computed<T>;
25
26
  export declare function isEqual<T>(a: T, b: T): boolean;
26
27
  /**
27
28
  * When set to a component name string, any reactive read that is not inside a nested tracking
@@ -30,14 +31,49 @@ export declare function isEqual<T>(a: T, b: T): boolean;
30
31
  export declare let strictRead: string | false;
31
32
  export declare function setStrictRead(v: string | false): string | false;
32
33
  /**
33
- * Executes `fn` without tracking reactive dependencies.
34
+ * Runs `fn` outside of any reactive tracking — reads inside `fn` will not
35
+ * subscribe the current scope. Returns whatever `fn` returns.
34
36
  *
35
- * Pass a `strictReadLabel` string to enable strict-read warnings: any reactive read inside `fn`
36
- * that is not inside a nested tracking scope will log a warning in dev mode.
37
+ * Use `untrack` inside a memo or effect when you need to read a signal once
38
+ * without making the surrounding computation depend on its future changes.
39
+ *
40
+ * Pass a `strictReadLabel` string to enable a dev-mode warning: any reactive
41
+ * read inside `fn` that isn't inside a nested tracking scope will log a
42
+ * warning naming the label.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * createEffect(
47
+ * () => trigger(), // tracks `trigger` only
48
+ * () => {
49
+ * const snapshot = untrack(() => state); // read once, untracked
50
+ * log(snapshot);
51
+ * }
52
+ * );
53
+ * ```
37
54
  */
38
55
  export declare function untrack<T>(fn: () => T, strictReadLabel?: string | false): T;
39
56
  export declare function read<T>(el: Signal<T> | Computed<T>): T;
40
57
  export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
58
+ /**
59
+ * Executes `fn` with the given `owner` set as the current owner. Any reactive
60
+ * primitives (`createSignal`, `createMemo`, `createEffect`, `onCleanup`,
61
+ * `cleanup`, etc.) created inside `fn` are attached to that owner, so they
62
+ * are disposed when the owner is disposed.
63
+ *
64
+ * The classic pattern: capture the current owner with `getOwner()` inside a
65
+ * component, then re-enter it from a callback (event handler, async resolve,
66
+ * setTimeout) so disposables created in the callback get cleaned up with the
67
+ * component.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * function delayed<T>(ms: number, fn: () => T) {
72
+ * const owner = getOwner();
73
+ * setTimeout(() => runWithOwner(owner, fn), ms);
74
+ * }
75
+ * ```
76
+ */
41
77
  export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
42
78
  /**
43
79
  * Update _pendingSignal when pending state changes. When the override clears
@@ -46,9 +82,72 @@ export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
46
82
  */
47
83
  export declare function updatePendingSignal(el: Signal<any> | Computed<any>): void;
48
84
  export declare function staleValues<T>(fn: () => T, set?: boolean): T;
85
+ /**
86
+ * Reads reactive expressions while bypassing any pending async overlay — i.e.
87
+ * always returns the most-recently-committed value, even when newer reads
88
+ * inside `fn` are still in flight.
89
+ *
90
+ * Useful inside a `<Loading>` boundary's children when you want to keep
91
+ * showing the previous resolved data instead of the fallback while the next
92
+ * value loads.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * <Loading fallback={<Skeleton />}>
97
+ * {/* During a transition, render the previous user instead of skeleton: *\/}
98
+ * <UserCard user={latest(() => user())} />
99
+ * </Loading>
100
+ * ```
101
+ */
49
102
  export declare function latest<T>(fn: () => T): T;
103
+ /**
104
+ * Returns `true` if any reactive read inside `fn` is currently in a pending
105
+ * (async, not-yet-settled) state. Does not subscribe — pair with a tracked
106
+ * memo if you want to react to pending status changes.
107
+ *
108
+ * Useful for showing inline transition indicators alongside the previous
109
+ * value (rather than swapping to a `<Loading>` fallback).
110
+ *
111
+ * @example
112
+ * ```tsx
113
+ * const pending = createMemo(() => isPending(() => user()));
114
+ *
115
+ * <button disabled={pending()}>{pending() ? "Saving…" : "Save"}</button>
116
+ * ```
117
+ */
50
118
  export declare function isPending(fn: () => any): boolean;
51
- export declare function refresh<T>(fn: (() => T) | (T & {
52
- [$REFRESH]: any;
53
- })): T;
119
+ /**
120
+ * Forces a reactive source to re-execute, even if its inputs haven't changed.
121
+ *
122
+ * Two forms:
123
+ * - `refresh(memo)` — pass an accessor (memo / signal getter) and its
124
+ * underlying computation reruns.
125
+ * - `refresh(store)` — pass a *projected* store created from
126
+ * `createStore(fn, ...)` or `createProjection(...)` and the projection
127
+ * recomputes.
128
+ *
129
+ * Use it to invalidate cached async values (e.g. force a re-fetch) without
130
+ * tearing the consumer down.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const user = createMemo(async () => fetch(`/users/${id()}`).then(r => r.json()));
135
+ *
136
+ * // Re-fetch on demand
137
+ * <button onClick={() => refresh(user)}>Reload</button>
138
+ * ```
139
+ */
140
+ export declare function refresh<T>(fn: (() => T) | Refreshable<T>): T;
141
+ /**
142
+ * Returns `true` while a `refresh()` call is in progress. Useful for showing
143
+ * a "refreshing" indicator distinct from the initial-load `<Loading>`
144
+ * fallback.
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * <Show when={isRefreshing()}>
149
+ * <span class="badge">refreshing…</span>
150
+ * </Show>
151
+ * ```
152
+ */
54
153
  export declare function isRefreshing(): boolean;
@@ -6,7 +6,7 @@ export interface DevHooks {
6
6
  onStoreNodeUpdate?: (state: any, property: PropertyKey, value: any, prev: any) => void;
7
7
  }
8
8
  export type DiagnosticSeverity = "warn" | "error";
9
- export type DiagnosticCode = "STRICT_READ_UNTRACKED" | "PENDING_ASYNC_UNTRACKED_READ" | "PENDING_ASYNC_FORBIDDEN_SCOPE" | "SIGNAL_WRITE_IN_OWNED_SCOPE" | "RUN_WITH_DISPOSED_OWNER" | "NO_OWNER_CLEANUP" | "CLEANUP_IN_FORBIDDEN_SCOPE" | "NO_OWNER_EFFECT" | "NO_OWNER_BOUNDARY" | "ASYNC_OUTSIDE_LOADING_BOUNDARY";
9
+ export type DiagnosticCode = "STRICT_READ_UNTRACKED" | "PENDING_ASYNC_UNTRACKED_READ" | "PENDING_ASYNC_FORBIDDEN_SCOPE" | "SIGNAL_WRITE_IN_OWNED_SCOPE" | "RUN_WITH_DISPOSED_OWNER" | "NO_OWNER_CLEANUP" | "CLEANUP_IN_FORBIDDEN_SCOPE" | "PRIMITIVE_IN_FORBIDDEN_SCOPE" | "NO_OWNER_EFFECT" | "NO_OWNER_BOUNDARY" | "ASYNC_OUTSIDE_LOADING_BOUNDARY" | "MISSING_EFFECT_FN";
10
10
  export type DiagnosticKind = "strict-read" | "async" | "write" | "lifecycle" | "owner";
11
11
  export interface DiagnosticEvent {
12
12
  sequence: number;
@@ -12,9 +12,10 @@ export interface Effect<T> extends Computed<T>, Owner {
12
12
  * automatically added to the queue of effects to re-execute, which will cause them to fetch their
13
13
  * sources and recompute
14
14
  */
15
- export declare function effect<T>(compute: (prev: T | undefined) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown, cleanup: () => void) => void | (() => void), initialValue?: T, options?: NodeOptions<any> & {
16
- render?: boolean;
15
+ export declare function effect<T>(compute: (prev: T | undefined) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown, cleanup: () => void) => void | (() => void), options?: NodeOptions<any> & {
16
+ user?: boolean;
17
17
  defer?: boolean;
18
+ schedule?: boolean;
18
19
  }): void;
19
20
  export interface TrackedEffect extends Computed<void> {
20
21
  _cleanup?: () => void;
@@ -1,3 +1,27 @@
1
+ /**
2
+ * Thrown by a tracked read whose value is currently pending (an async memo /
3
+ * `createSignal(asyncFn)` / projection / store derivation that hasn't settled
4
+ * yet). Surfacing through the reactive graph is what suspends the consumer
5
+ * scope — the nearest enclosing `<Loading>` boundary catches the throw and
6
+ * renders its fallback until the source resolves.
7
+ *
8
+ * App code rarely catches this directly; `<Loading>` is the canonical
9
+ * handler. The error type is exposed for advanced cases — e.g. interop layers
10
+ * that bridge Solid's pending-throw protocol to a different async strategy,
11
+ * or tests that want to assert on the suspension shape.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Advanced: distinguish "not ready yet" from a real error in custom
16
+ * // boundary plumbing. App code should rely on `<Loading>` / `<Errored>`.
17
+ * try {
18
+ * const value = readReactiveSource();
19
+ * } catch (err) {
20
+ * if (err instanceof NotReadyError) throw err; // re-throw to suspend
21
+ * reportError(err);
22
+ * }
23
+ * ```
24
+ */
1
25
  export declare class NotReadyError extends Error {
2
26
  source: any;
3
27
  constructor(source: any);
@@ -21,6 +21,25 @@ export declare let externalSourceConfig: {
21
21
  * @param config.factory receives `(fn, trigger)` — wrap fn execution in external tracking,
22
22
  * call trigger when external deps change. Return `{ track, dispose }`.
23
23
  * @param config.untrack optional wrapper for `untrack` — disables external tracking too.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // Bridge an external "subscribe / notify" library into Solid's graph.
28
+ * // `factory` wraps every Solid compute so the external library can attach
29
+ * // its own dependency tracker; `trigger` re-runs the compute on external
30
+ * // change. `untrack` mirrors Solid's `untrack()` into the external library
31
+ * // so that reads inside `untrack(...)` don't get tracked twice.
32
+ * enableExternalSource({
33
+ * factory: (compute, trigger) => {
34
+ * const sub = externalLib.subscribe(trigger);
35
+ * return {
36
+ * track: prev => externalLib.run(() => compute(prev)),
37
+ * dispose: () => sub.unsubscribe()
38
+ * };
39
+ * },
40
+ * untrack: fn => externalLib.untracked(fn)
41
+ * });
42
+ * ```
24
43
  */
25
44
  export declare function enableExternalSource(config: ExternalSourceConfig): void;
26
45
  export declare function _resetExternalSourceConfig(): void;
@@ -1,3 +1,4 @@
1
1
  import type { Computed, Link, Signal } from "./types.js";
2
2
  export declare function unlinkSubs(link: Link): Link | null;
3
+ export declare function unobserved(el: Computed<unknown>): void;
3
4
  export declare function link(dep: Signal<any> | Computed<any>, sub: Computed<any>): void;
@@ -2,21 +2,111 @@ import type { Computed, Disposable, Owner, Root } from "./types.js";
2
2
  export declare function markDisposal(el: Owner): void;
3
3
  export declare function dispose(node: Computed<unknown>): void;
4
4
  export declare function disposeChildren(node: Owner, self?: boolean, zombie?: boolean): void;
5
+ /**
6
+ * Allocates and returns the next stable child id for `owner`. Used by
7
+ * hydration plumbing and `createUniqueId`. Not part of the user-facing API.
8
+ *
9
+ * @internal
10
+ */
5
11
  export declare function getNextChildId(owner: Owner): string;
12
+ /**
13
+ * Returns the *next* child id for `owner` without consuming it. Used by
14
+ * hydration plumbing to peek at the id a future child will receive.
15
+ *
16
+ * @internal
17
+ */
6
18
  export declare function peekNextChildId(owner: Owner): string;
19
+ /**
20
+ * Returns the currently-tracking observer (the computation that subscribes to
21
+ * reactive reads at this point), or `null` if reads here would be untracked.
22
+ * Used by reactive primitives that need to know whether they're inside a
23
+ * tracking scope. App code rarely needs this — see `getOwner()` for the
24
+ * lifecycle owner instead.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // Library predicate: only register a hot-path subscription when the
29
+ * // caller is inside a tracking scope (memo / effect compute / JSX).
30
+ * function trackIfTracked(source: () => unknown) {
31
+ * if (getObserver()) source();
32
+ * }
33
+ * ```
34
+ */
7
35
  export declare function getObserver(): Owner | null;
36
+ /**
37
+ * Returns the current reactive **owner** — the lifecycle node that the next
38
+ * `cleanup()` / `onCleanup()` / `createSignal()` etc. will be attached to.
39
+ *
40
+ * Returns `null` if called outside any owner. Capture the owner with
41
+ * `getOwner()` and re-enter it later with `runWithOwner(owner, fn)` to attach
42
+ * disposables created from a callback (event handler, async resolution, etc.)
43
+ * back to a component's lifecycle.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * function defer<T>(fn: () => T) {
48
+ * const owner = getOwner();
49
+ * queueMicrotask(() => runWithOwner(owner, fn));
50
+ * }
51
+ * ```
52
+ */
8
53
  export declare function getOwner(): Owner | null;
54
+ /**
55
+ * Low-level: registers `fn` as a disposal callback on the current owner.
56
+ * Most code should use `onCleanup()` from `solid-js`, which adds dev-mode
57
+ * checks. `cleanup()` is the unchecked primitive used by internals.
58
+ */
9
59
  export declare function cleanup(fn: Disposable): Disposable;
60
+ /**
61
+ * Returns `true` if the owner has been disposed (or marked zombie pending
62
+ * disposal). Pair with a captured owner to bail out of late callbacks whose
63
+ * surrounding component already unmounted.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * function onSettleSafe(fn: () => void) {
68
+ * const owner = getOwner();
69
+ * queueMicrotask(() => {
70
+ * if (owner && isDisposed(owner)) return; // component unmounted; skip
71
+ * runWithOwner(owner, fn);
72
+ * });
73
+ * }
74
+ * ```
75
+ */
10
76
  export declare function isDisposed(node: Owner): boolean;
77
+ /**
78
+ * Creates a fresh owner attached as a child of the current owner (or as a
79
+ * detached root if there is none). Used by framework internals to group
80
+ * cleanups; app code should use `createRoot()` (host a reactive scope outside
81
+ * a component) or `runWithOwner()` (re-enter a captured owner).
82
+ *
83
+ * @internal
84
+ */
11
85
  export declare function createOwner(options?: {
12
86
  id?: string;
13
87
  transparent?: boolean;
14
88
  }): Root;
15
89
  /**
16
- * Creates a new non-tracked reactive context with manual disposal
90
+ * Creates a detached reactive root. The callback receives a `dispose()`
91
+ * function which, when called, tears down every signal, memo, effect, and
92
+ * `onCleanup` registered inside the root.
93
+ *
94
+ * Use this to host long-lived reactive scopes outside of a component (custom
95
+ * controllers, app bootstrapping, tests). Inside a component, prefer
96
+ * letting Solid's component lifecycle own things.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const dispose = createRoot(dispose => {
101
+ * const [n, setN] = createSignal(0);
102
+ * createEffect(() => n(), value => console.log(value));
103
+ * setInterval(() => setN(x => x + 1), 1000);
104
+ * return dispose;
105
+ * });
17
106
  *
18
- * @param fn a function in which the reactive state is scoped
19
- * @returns the output of `fn`.
107
+ * // Later, to tear everything down:
108
+ * dispose();
109
+ * ```
20
110
  *
21
111
  * @description https://docs.solidjs.com/reference/reactive-utilities/create-root
22
112
  */
@@ -9,7 +9,16 @@ export declare let clock: number;
9
9
  export declare let activeTransition: Transition | null;
10
10
  export declare let projectionWriteActive: boolean;
11
11
  export declare let _hitUnhandledAsync: boolean;
12
+ export declare function registerTransientStoreNode(node: Signal<any>): void;
12
13
  export declare function resetUnhandledAsync(): void;
14
+ /**
15
+ * Toggles the dev-mode "must be inside a `<Loading>` boundary" enforcement
16
+ * window. Only `render()` calls this — wrapping the initial mount so that a
17
+ * top-level uncaught async read surfaces the diagnostic. Not part of the
18
+ * user-facing API.
19
+ *
20
+ * @internal
21
+ */
13
22
  export declare function enforceLoadingBoundary(enabled: boolean): void;
14
23
  export declare function shouldReadStashedOptimisticValue(node: Signal<any>): boolean;
15
24
  export declare function setProjectionWriteActive(value: boolean): void;
@@ -29,6 +38,7 @@ export interface Transition {
29
38
  _actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
30
39
  _queueStash: QueueStub;
31
40
  _done: boolean | Transition;
41
+ _gatedSubs: Set<Computed<any>>;
32
42
  }
33
43
  export declare function schedule(): void;
34
44
  export interface IQueue {
@@ -72,8 +82,23 @@ export declare function finalizePureQueue(completingTransition?: Transition | nu
72
82
  export declare function trackOptimisticStore(store: any): void;
73
83
  export declare const globalQueue: GlobalQueue;
74
84
  /**
75
- * By default, changes are batched on the microtask queue which is an async process. You can flush
76
- * the queue synchronously to get the latest updates by calling `flush()`.
85
+ * Synchronously processes the pending reactive queue: runs every scheduled
86
+ * memo/effect/computation that has dirty inputs, until the graph is settled.
87
+ *
88
+ * Reactive updates are normally batched onto the microtask queue, so multiple
89
+ * writes in a row collapse into a single update pass. Call `flush()` when you
90
+ * need to *observe* the result of those writes synchronously — most commonly
91
+ * in tests, but also at the boundary of imperative integration code.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const [count, setCount] = createSignal(0);
96
+ * const doubled = createMemo(() => count() * 2);
97
+ *
98
+ * setCount(5);
99
+ * flush();
100
+ * expect(doubled()).toBe(10);
101
+ * ```
77
102
  */
78
103
  export declare function flush(): void;
79
104
  export declare function currentTransition(transition: Transition): Transition;