@solidjs/signals 2.0.0-beta.8 → 2.0.0-beta.9
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.
- package/dist/dev.js +172 -79
- package/dist/node.cjs +1091 -1043
- package/dist/prod.js +802 -752
- package/dist/types/boundaries.d.ts +35 -0
- package/dist/types/core/action.d.ts +34 -0
- package/dist/types/core/constants.d.ts +17 -0
- package/dist/types/core/core.d.ts +106 -7
- package/dist/types/core/dev.d.ts +1 -1
- package/dist/types/core/owner.d.ts +54 -3
- package/dist/types/core/scheduler.d.ts +18 -2
- package/dist/types/core/types.d.ts +2 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/map.d.ts +32 -3
- package/dist/types/signals.d.ts +264 -11
- package/dist/types/store/optimistic.d.ts +38 -12
- package/dist/types/store/projection.d.ts +40 -14
- package/dist/types/store/reconcile.d.ts +22 -0
- package/dist/types/store/store.d.ts +64 -14
- package/dist/types/store/storePath.d.ts +28 -0
- package/dist/types/store/utils.d.ts +78 -7
- package/dist/types-cjs/boundaries.d.cts +35 -0
- package/dist/types-cjs/core/action.d.cts +34 -0
- package/dist/types-cjs/core/constants.d.cts +17 -0
- package/dist/types-cjs/core/core.d.cts +106 -7
- package/dist/types-cjs/core/dev.d.cts +1 -1
- package/dist/types-cjs/core/owner.d.cts +54 -3
- package/dist/types-cjs/core/scheduler.d.cts +18 -2
- package/dist/types-cjs/core/types.d.cts +2 -5
- package/dist/types-cjs/index.d.cts +1 -1
- package/dist/types-cjs/map.d.cts +32 -3
- package/dist/types-cjs/signals.d.cts +264 -11
- package/dist/types-cjs/store/optimistic.d.cts +38 -12
- package/dist/types-cjs/store/projection.d.cts +40 -14
- package/dist/types-cjs/store/reconcile.d.cts +22 -0
- package/dist/types-cjs/store/store.d.cts +64 -14
- package/dist/types-cjs/store/storePath.d.cts +28 -0
- package/dist/types-cjs/store/utils.d.cts +78 -7
- package/package.json +4 -3
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns a non reactive copy of
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Returns a plain (non-proxy, non-reactive) deep copy of a store value.
|
|
3
|
+
* Reading via `snapshot` does **not** subscribe to changes — use this when you
|
|
4
|
+
* need to hand a stable plain object to non-reactive code (logging,
|
|
5
|
+
* serialization, structured-clone, network payloads, etc.).
|
|
6
|
+
*
|
|
7
|
+
* Returns the original object identity for any sub-tree that wasn't modified
|
|
8
|
+
* relative to the proxy's underlying source.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const [state] = createStore({ user: { name: "Ada" }, todos: [] });
|
|
13
|
+
*
|
|
14
|
+
* console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
|
|
15
|
+
* ```
|
|
5
16
|
*/
|
|
6
17
|
export declare function snapshot<T>(item: T): T;
|
|
7
18
|
export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
|
|
8
19
|
/**
|
|
9
|
-
* Returns a non-
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
20
|
+
* Returns a plain (non-proxy) deep copy **and** subscribes the current
|
|
21
|
+
* tracking scope to every nested change in the source store. Any write
|
|
22
|
+
* anywhere in the subtree invalidates the consumer.
|
|
23
|
+
*
|
|
24
|
+
* Use this when you need plain data inside a reactive scope and want to
|
|
25
|
+
* react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
|
|
26
|
+
* memo that should rerun on any nested change). For most read paths, prefer
|
|
27
|
+
* direct property access — Solid stores already track per-property reads
|
|
28
|
+
* with no `deep()` wrapper needed.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const [state] = createStore({ a: { b: { c: 1 } } });
|
|
33
|
+
*
|
|
34
|
+
* createEffect(
|
|
35
|
+
* () => deep(state), // reruns on any nested change
|
|
36
|
+
* plain => sendToWorker(plain) // worker gets a non-proxy copy
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
13
39
|
*/
|
|
14
40
|
export declare function deep<T extends object>(store: T): T;
|
|
15
41
|
type DistributeOverride<T, F> = T extends undefined ? F : T;
|
|
@@ -35,9 +61,54 @@ type _Merge<T extends unknown[], Curr = {}> = T extends [
|
|
|
35
61
|
...infer Rest
|
|
36
62
|
] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
|
|
37
63
|
export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Merges multiple props-like objects into a single proxy that *preserves
|
|
66
|
+
* reactivity*. Reads are forwarded to the right-most source that defines the
|
|
67
|
+
* property, so later sources override earlier ones (like `Object.assign`).
|
|
68
|
+
*
|
|
69
|
+
* Function arguments are treated as memo-backed sources — useful for passing
|
|
70
|
+
* derived defaults whose computation should track reactively.
|
|
71
|
+
*
|
|
72
|
+
* Use this in component bodies to merge defaults / overrides without losing
|
|
73
|
+
* Solid's per-property tracking.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* function Button(_props: { label: string; type?: string; disabled?: boolean }) {
|
|
78
|
+
* const props = merge({ type: "button", disabled: false }, _props);
|
|
79
|
+
*
|
|
80
|
+
* return <button type={props.type} disabled={props.disabled}>{props.label}</button>;
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
38
84
|
export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
|
|
39
85
|
export type Omit<T, K extends readonly (keyof T)[]> = {
|
|
40
86
|
[P in keyof T as Exclude<P, K[number]>]: T[P];
|
|
41
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Returns a reactive proxy of `props` with the listed keys hidden. Tracking
|
|
90
|
+
* on the remaining keys is preserved.
|
|
91
|
+
*
|
|
92
|
+
* Use it to forward "rest" props to a child element while pulling out the
|
|
93
|
+
* keys your component handles itself — the equivalent of `splitProps(p, ["a","b"])[1]`.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* function Input(props: { label: string; value: string; onInput: (v: string) => void } & JSX.HTMLAttributes<HTMLInputElement>) {
|
|
98
|
+
* const rest = omit(props, "label", "value", "onInput");
|
|
99
|
+
*
|
|
100
|
+
* return (
|
|
101
|
+
* <label>
|
|
102
|
+
* {props.label}
|
|
103
|
+
* <input
|
|
104
|
+
* {...rest}
|
|
105
|
+
* value={props.value}
|
|
106
|
+
* onInput={e => props.onInput(e.currentTarget.value)}
|
|
107
|
+
* />
|
|
108
|
+
* </label>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
42
113
|
export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
|
|
43
114
|
export {};
|
|
@@ -48,9 +48,30 @@ export declare class CollectionQueue extends Queue {
|
|
|
48
48
|
notify(node: Effect<any>, type: number, flags: number, error?: any): boolean;
|
|
49
49
|
checkSources(): void;
|
|
50
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
|
+
*/
|
|
51
63
|
export declare function createLoadingBoundary(fn: () => any, fallback: () => any, options?: {
|
|
52
64
|
on?: () => any;
|
|
53
65
|
}): import("./signals.cjs").Accessor<unknown>;
|
|
66
|
+
/**
|
|
67
|
+
* Lower-level primitive that backs the `<Errored>` flow control. Catches
|
|
68
|
+
* thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
|
|
69
|
+
* `reset()` recomputes the failing sources so the boundary can attempt to
|
|
70
|
+
* recover.
|
|
71
|
+
*
|
|
72
|
+
* App code should use `<Errored fallback={...}>` instead — reach for this only
|
|
73
|
+
* when authoring custom boundary components.
|
|
74
|
+
*/
|
|
54
75
|
export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): import("./signals.cjs").Accessor<unknown>;
|
|
55
76
|
/**
|
|
56
77
|
* Coordinate the reveal timing of sibling loading boundaries.
|
|
@@ -86,6 +107,20 @@ export declare function createRevealOrder<T>(fn: () => T, options?: {
|
|
|
86
107
|
order?: OrderAccessor;
|
|
87
108
|
collapsed?: BoolAccessor;
|
|
88
109
|
}): T;
|
|
110
|
+
/**
|
|
111
|
+
* Resolves a children value to its renderable form: unwraps zero-arg functions
|
|
112
|
+
* (accessors), recursively flattens arrays, and optionally skips
|
|
113
|
+
* non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
|
|
114
|
+
*
|
|
115
|
+
* Used internally by flow components and by the renderer to walk a children
|
|
116
|
+
* tree. App code rarely needs this directly — see `children()` in `solid-js`
|
|
117
|
+
* for the user-facing helper that memoizes the result.
|
|
118
|
+
*
|
|
119
|
+
* @param children value or array of values to flatten
|
|
120
|
+
* @param options
|
|
121
|
+
* - `skipNonRendered` — drop values that won't render
|
|
122
|
+
* - `doNotUnwrap` — leave function children as-is (caller will resolve)
|
|
123
|
+
*/
|
|
89
124
|
export declare function flatten(children: any, options?: {
|
|
90
125
|
skipNonRendered?: boolean;
|
|
91
126
|
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;
|
|
@@ -23,3 +29,14 @@ export declare const STORE_SNAPSHOT_PROPS = "sp";
|
|
|
23
29
|
export declare const SUPPORTS_PROXY: boolean;
|
|
24
30
|
export declare const defaultContext: {};
|
|
25
31
|
export declare const $REFRESH: unique symbol;
|
|
32
|
+
/**
|
|
33
|
+
* Brand applied to derived/projected stores indicating they participate in
|
|
34
|
+
* the `refresh()` re-run protocol. Use this alias instead of inlining
|
|
35
|
+
* `T & { [$REFRESH]: any }` so that user-defined hooks that wrap
|
|
36
|
+
* `createOptimisticStore` / `createProjection` / projection-form
|
|
37
|
+
* `createStore` can have their return types inferred without leaking the
|
|
38
|
+
* internal `$REFRESH` symbol into public type signatures (TS4058).
|
|
39
|
+
*/
|
|
40
|
+
export type Refreshable<T> = T & {
|
|
41
|
+
readonly [$REFRESH]: any;
|
|
42
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Refreshable } from "./constants.cjs";
|
|
2
2
|
import { type OptimisticLane } from "./lanes.cjs";
|
|
3
3
|
import type { Computed, FirewallSignal, NodeOptions, Owner, Signal } from "./types.cjs";
|
|
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;
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
36
|
-
*
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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;
|
|
@@ -4,19 +4,70 @@ export declare function dispose(node: Computed<unknown>): void;
|
|
|
4
4
|
export declare function disposeChildren(node: Owner, self?: boolean, zombie?: boolean): void;
|
|
5
5
|
export declare function getNextChildId(owner: Owner): string;
|
|
6
6
|
export declare function peekNextChildId(owner: Owner): string;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the currently-tracking observer (the computation that subscribes to
|
|
9
|
+
* reactive reads at this point), or `null` if reads here would be untracked.
|
|
10
|
+
* Used by reactive primitives that need to know whether they're inside a
|
|
11
|
+
* tracking scope. App code rarely needs this — see `getOwner()` for the
|
|
12
|
+
* lifecycle owner instead.
|
|
13
|
+
*/
|
|
7
14
|
export declare function getObserver(): Owner | null;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current reactive **owner** — the lifecycle node that the next
|
|
17
|
+
* `cleanup()` / `onCleanup()` / `createSignal()` etc. will be attached to.
|
|
18
|
+
*
|
|
19
|
+
* Returns `null` if called outside any owner. Capture the owner with
|
|
20
|
+
* `getOwner()` and re-enter it later with `runWithOwner(owner, fn)` to attach
|
|
21
|
+
* disposables created from a callback (event handler, async resolution, etc.)
|
|
22
|
+
* back to a component's lifecycle.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* function defer<T>(fn: () => T) {
|
|
27
|
+
* const owner = getOwner();
|
|
28
|
+
* queueMicrotask(() => runWithOwner(owner, fn));
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
8
32
|
export declare function getOwner(): Owner | null;
|
|
33
|
+
/**
|
|
34
|
+
* Low-level: registers `fn` as a disposal callback on the current owner.
|
|
35
|
+
* Most code should use `onCleanup()` from `solid-js`, which adds dev-mode
|
|
36
|
+
* checks. `cleanup()` is the unchecked primitive used by internals.
|
|
37
|
+
*/
|
|
9
38
|
export declare function cleanup(fn: Disposable): Disposable;
|
|
39
|
+
/** Returns `true` if the owner has been disposed (or marked zombie pending disposal). */
|
|
10
40
|
export declare function isDisposed(node: Owner): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a fresh owner attached as a child of the current owner (or as a
|
|
43
|
+
* detached root if there is none). Mostly used by framework internals to
|
|
44
|
+
* group cleanups; app code should prefer `createRoot()` or `runWithOwner()`.
|
|
45
|
+
*/
|
|
11
46
|
export declare function createOwner(options?: {
|
|
12
47
|
id?: string;
|
|
13
48
|
transparent?: boolean;
|
|
14
49
|
}): Root;
|
|
15
50
|
/**
|
|
16
|
-
* Creates a
|
|
51
|
+
* Creates a detached reactive root. The callback receives a `dispose()`
|
|
52
|
+
* function which, when called, tears down every signal, memo, effect, and
|
|
53
|
+
* `onCleanup` registered inside the root.
|
|
54
|
+
*
|
|
55
|
+
* Use this to host long-lived reactive scopes outside of a component (custom
|
|
56
|
+
* controllers, app bootstrapping, tests). Inside a component, prefer
|
|
57
|
+
* letting Solid's component lifecycle own things.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const dispose = createRoot(dispose => {
|
|
62
|
+
* const [n, setN] = createSignal(0);
|
|
63
|
+
* createEffect(() => n(), value => console.log(value));
|
|
64
|
+
* setInterval(() => setN(x => x + 1), 1000);
|
|
65
|
+
* return dispose;
|
|
66
|
+
* });
|
|
17
67
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
68
|
+
* // Later, to tear everything down:
|
|
69
|
+
* dispose();
|
|
70
|
+
* ```
|
|
20
71
|
*
|
|
21
72
|
* @description https://docs.solidjs.com/reference/reactive-utilities/create-root
|
|
22
73
|
*/
|
|
@@ -30,6 +30,7 @@ export interface Transition {
|
|
|
30
30
|
_actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
|
|
31
31
|
_queueStash: QueueStub;
|
|
32
32
|
_done: boolean | Transition;
|
|
33
|
+
_gatedSubs: Set<Computed<any>>;
|
|
33
34
|
}
|
|
34
35
|
export declare function schedule(): void;
|
|
35
36
|
export interface IQueue {
|
|
@@ -73,8 +74,23 @@ export declare function finalizePureQueue(completingTransition?: Transition | nu
|
|
|
73
74
|
export declare function trackOptimisticStore(store: any): void;
|
|
74
75
|
export declare const globalQueue: GlobalQueue;
|
|
75
76
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
77
|
+
* Synchronously processes the pending reactive queue: runs every scheduled
|
|
78
|
+
* memo/effect/computation that has dirty inputs, until the graph is settled.
|
|
79
|
+
*
|
|
80
|
+
* Reactive updates are normally batched onto the microtask queue, so multiple
|
|
81
|
+
* writes in a row collapse into a single update pass. Call `flush()` when you
|
|
82
|
+
* need to *observe* the result of those writes synchronously — most commonly
|
|
83
|
+
* in tests, but also at the boundary of imperative integration code.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const [count, setCount] = createSignal(0);
|
|
88
|
+
* const doubled = createMemo(() => count() * 2);
|
|
89
|
+
*
|
|
90
|
+
* setCount(5);
|
|
91
|
+
* flush();
|
|
92
|
+
* expect(doubled()).toBe(10);
|
|
93
|
+
* ```
|
|
78
94
|
*/
|
|
79
95
|
export declare function flush(): void;
|
|
80
96
|
export declare function currentTransition(transition: Transition): Transition;
|
|
@@ -29,8 +29,7 @@ export interface RawSignal<T> {
|
|
|
29
29
|
_snapshotValue?: any;
|
|
30
30
|
_name?: string;
|
|
31
31
|
_equals: false | ((a: T, b: T) => boolean);
|
|
32
|
-
|
|
33
|
-
_noSnapshot?: boolean;
|
|
32
|
+
_config: number;
|
|
34
33
|
_unobserved?: () => void;
|
|
35
34
|
_time: number;
|
|
36
35
|
_transition: Transition | null;
|
|
@@ -48,8 +47,7 @@ export interface FirewallSignal<T> extends RawSignal<T> {
|
|
|
48
47
|
export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
|
|
49
48
|
export interface Owner {
|
|
50
49
|
id?: string;
|
|
51
|
-
|
|
52
|
-
_childrenForbidden?: boolean;
|
|
50
|
+
_config: number;
|
|
53
51
|
_snapshotScope?: boolean;
|
|
54
52
|
_disposal: Disposable | Disposable[] | null;
|
|
55
53
|
_parent: Owner | null;
|
|
@@ -65,7 +63,6 @@ export interface Computed<T> extends RawSignal<T>, Owner {
|
|
|
65
63
|
_deps: Link | null;
|
|
66
64
|
_depsTail: Link | null;
|
|
67
65
|
_flags: number;
|
|
68
|
-
_inSnapshotScope?: boolean;
|
|
69
66
|
_blocked?: boolean;
|
|
70
67
|
_pendingSource?: Computed<any>;
|
|
71
68
|
_pendingSources?: Set<Computed<any>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, isRefreshing, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource } from "./core/index.cjs";
|
|
2
2
|
import { type Dev } from "./core/index.cjs";
|
|
3
3
|
export declare const DEV: Dev | undefined;
|
|
4
|
-
export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
|
|
4
|
+
export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
|
|
5
5
|
export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.cjs";
|
|
6
6
|
export type { Accessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
|
|
7
7
|
export { mapArray, repeat, type Maybe } from "./map.cjs";
|
package/dist/types-cjs/map.d.cts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { type Accessor } from "./signals.cjs";
|
|
2
2
|
export type Maybe<T> = T | void | null | undefined | false;
|
|
3
3
|
/**
|
|
4
|
-
* Reactively
|
|
4
|
+
* Reactively maps an array, reusing the previously-mapped value for unchanged
|
|
5
|
+
* items. The callback receives `(value, index)` as accessors so individual
|
|
6
|
+
* items and indexes can be subscribed to without re-running the mapper.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
8
|
+
* This is the underlying helper that powers `<For>`. App code should use
|
|
9
|
+
* `<For>` directly; reach for `mapArray` when implementing custom list
|
|
10
|
+
* components.
|
|
11
|
+
*
|
|
12
|
+
* - `options.keyed` — `true` (default for primitives) compares by identity;
|
|
13
|
+
* `false` falls back to index-only mapping; pass a function `(item) => key`
|
|
14
|
+
* for stable identity by extracted key.
|
|
15
|
+
* - `options.fallback` — accessor returning a value to show when the input is
|
|
16
|
+
* empty.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const view = mapArray(
|
|
21
|
+
* items,
|
|
22
|
+
* (item, index) => `${index()}: ${item().label}`,
|
|
23
|
+
* { fallback: () => "no items" }
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
7
26
|
*
|
|
8
27
|
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
9
28
|
*/
|
|
@@ -13,7 +32,17 @@ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly
|
|
|
13
32
|
name?: string;
|
|
14
33
|
}): Accessor<MappedItem[]>;
|
|
15
34
|
/**
|
|
16
|
-
* Reactively
|
|
35
|
+
* Reactively renders a callback `count` times, reusing previously-rendered
|
|
36
|
+
* entries when only the count changes. Underlying helper for `<Repeat>`.
|
|
37
|
+
*
|
|
38
|
+
* - `options.from` — start index (default `0`); useful for offset/windowed
|
|
39
|
+
* rendering.
|
|
40
|
+
* - `options.fallback` — accessor returning a value to show when count is `0`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const view = repeat(count, i => `Item ${i}`, { fallback: () => "empty" });
|
|
45
|
+
* ```
|
|
17
46
|
*
|
|
18
47
|
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
|
|
19
48
|
*/
|