@solidjs/signals 0.13.13 → 2.0.0-beta.11
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/README.md +8 -7
- package/dist/dev.js +1230 -598
- package/dist/node.cjs +2064 -1555
- package/dist/prod.js +1783 -1251
- package/dist/types/boundaries.d.ts +126 -5
- package/dist/types/core/action.d.ts +34 -0
- package/dist/types/core/constants.d.ts +26 -0
- package/dist/types/core/context.d.ts +10 -2
- package/dist/types/core/core.d.ts +129 -9
- package/dist/types/core/dev.d.ts +1 -1
- package/dist/types/core/effect.d.ts +4 -2
- package/dist/types/core/error.d.ts +24 -0
- package/dist/types/core/external.d.ts +19 -0
- package/dist/types/core/graph.d.ts +2 -0
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/owner.d.ts +93 -3
- package/dist/types/core/scheduler.d.ts +43 -2
- package/dist/types/core/types.d.ts +5 -6
- package/dist/types/index.d.ts +3 -3
- package/dist/types/map.d.ts +32 -3
- package/dist/types/signals.d.ts +362 -42
- package/dist/types/src/boundaries.d.ts +173 -0
- package/dist/types/src/core/action.d.ts +35 -0
- package/dist/types/src/core/async.d.ts +6 -0
- package/dist/types/src/core/constants.d.ts +51 -0
- package/dist/types/src/core/context.d.ts +36 -0
- package/dist/types/src/core/core.d.ts +174 -0
- package/dist/types/src/core/dev.d.ts +49 -0
- package/dist/types/src/core/effect.d.ts +32 -0
- package/dist/types/src/core/error.d.ts +38 -0
- package/dist/types/src/core/external.d.ts +45 -0
- package/dist/types/src/core/graph.d.ts +5 -0
- package/dist/types/src/core/heap.d.ts +14 -0
- package/dist/types/src/core/index.d.ts +12 -0
- package/dist/types/src/core/lanes.d.ts +54 -0
- package/dist/types/src/core/owner.d.ts +116 -0
- package/dist/types/src/core/scheduler.d.ts +122 -0
- package/dist/types/src/core/types.d.ts +85 -0
- package/dist/types/src/index.d.ts +9 -0
- package/dist/types/src/map.d.ts +53 -0
- package/dist/types/src/signals.d.ts +512 -0
- package/dist/types/src/store/index.d.ts +9 -0
- package/dist/types/src/store/optimistic.d.ts +45 -0
- package/dist/types/src/store/projection.d.ts +66 -0
- package/dist/types/src/store/reconcile.d.ts +23 -0
- package/dist/types/src/store/store.d.ts +125 -0
- package/dist/types/src/store/storePath.d.ts +58 -0
- package/dist/types/src/store/utils.d.ts +114 -0
- package/dist/types/store/optimistic.d.ts +38 -12
- package/dist/types/store/projection.d.ts +55 -15
- package/dist/types/store/reconcile.d.ts +22 -0
- package/dist/types/store/store.d.ts +72 -15
- 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 +173 -0
- package/dist/types-cjs/core/action.d.cts +35 -0
- package/dist/types-cjs/core/async.d.cts +6 -0
- package/dist/types-cjs/core/constants.d.cts +51 -0
- package/dist/types-cjs/core/context.d.cts +36 -0
- package/dist/types-cjs/core/core.d.cts +174 -0
- package/dist/types-cjs/core/dev.d.cts +49 -0
- package/dist/types-cjs/core/effect.d.cts +32 -0
- package/dist/types-cjs/core/error.d.cts +38 -0
- package/dist/types-cjs/core/external.d.cts +45 -0
- package/dist/types-cjs/core/graph.d.cts +5 -0
- package/dist/types-cjs/core/heap.d.cts +14 -0
- package/dist/types-cjs/core/index.d.cts +12 -0
- package/dist/types-cjs/core/lanes.d.cts +54 -0
- package/dist/types-cjs/core/owner.d.cts +116 -0
- package/dist/types-cjs/core/scheduler.d.cts +122 -0
- package/dist/types-cjs/core/types.d.cts +85 -0
- package/dist/types-cjs/index.d.cts +9 -0
- package/dist/types-cjs/map.d.cts +53 -0
- package/dist/types-cjs/package.json +3 -0
- package/dist/types-cjs/signals.d.cts +512 -0
- package/dist/types-cjs/src/boundaries.d.cts +173 -0
- package/dist/types-cjs/src/core/action.d.cts +35 -0
- package/dist/types-cjs/src/core/async.d.cts +6 -0
- package/dist/types-cjs/src/core/constants.d.cts +51 -0
- package/dist/types-cjs/src/core/context.d.cts +36 -0
- package/dist/types-cjs/src/core/core.d.cts +174 -0
- package/dist/types-cjs/src/core/dev.d.cts +49 -0
- package/dist/types-cjs/src/core/effect.d.cts +32 -0
- package/dist/types-cjs/src/core/error.d.cts +38 -0
- package/dist/types-cjs/src/core/external.d.cts +45 -0
- package/dist/types-cjs/src/core/graph.d.cts +5 -0
- package/dist/types-cjs/src/core/heap.d.cts +14 -0
- package/dist/types-cjs/src/core/index.d.cts +12 -0
- package/dist/types-cjs/src/core/lanes.d.cts +54 -0
- package/dist/types-cjs/src/core/owner.d.cts +116 -0
- package/dist/types-cjs/src/core/scheduler.d.cts +122 -0
- package/dist/types-cjs/src/core/types.d.cts +85 -0
- package/dist/types-cjs/src/index.d.cts +9 -0
- package/dist/types-cjs/src/map.d.cts +53 -0
- package/dist/types-cjs/src/signals.d.cts +512 -0
- package/dist/types-cjs/src/store/index.d.cts +9 -0
- package/dist/types-cjs/src/store/optimistic.d.cts +45 -0
- package/dist/types-cjs/src/store/projection.d.cts +66 -0
- package/dist/types-cjs/src/store/reconcile.d.cts +23 -0
- package/dist/types-cjs/src/store/store.d.cts +125 -0
- package/dist/types-cjs/src/store/storePath.d.cts +58 -0
- package/dist/types-cjs/src/store/utils.d.cts +114 -0
- package/dist/types-cjs/store/index.d.cts +9 -0
- package/dist/types-cjs/store/optimistic.d.cts +45 -0
- package/dist/types-cjs/store/projection.d.cts +66 -0
- package/dist/types-cjs/store/reconcile.d.cts +23 -0
- package/dist/types-cjs/store/store.d.cts +125 -0
- package/dist/types-cjs/store/storePath.d.cts +58 -0
- package/dist/types-cjs/store/utils.d.cts +114 -0
- package/package.json +35 -27
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./error.js";
|
|
2
|
+
export { isEqual, untrack, runWithOwner, computed, signal, read, setSignal, setMemo, suppressComputedRecompute, optimisticSignal, optimisticComputed, isPending, latest, refresh, isRefreshing, staleValues, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots } from "./core.js";
|
|
3
|
+
export { enableExternalSource, _resetExternalSourceConfig, type ExternalSourceFactory, type ExternalSource, type ExternalSourceConfig } from "./external.js";
|
|
4
|
+
export { createOwner, createRoot, dispose, getNextChildId, getObserver, getOwner, isDisposed, cleanup, peekNextChildId } from "./owner.js";
|
|
5
|
+
export { createContext, getContext, setContext, type Context, type ContextRecord } from "./context.js";
|
|
6
|
+
export { handleAsync } from "./async.js";
|
|
7
|
+
export type { Computed, Disposable, FirewallSignal, Link, Owner, Root, Signal, NodeOptions } from "./types.js";
|
|
8
|
+
export { effect, trackedEffect, type Effect, type TrackedEffect } from "./effect.js";
|
|
9
|
+
export { action } from "./action.js";
|
|
10
|
+
export { flush, Queue, GlobalQueue, trackOptimisticStore, enforceLoadingBoundary, type IQueue, type QueueCallback } from "./scheduler.js";
|
|
11
|
+
export { DEV, type Dev, type DevHooks, type DiagnosticCapture, type DiagnosticCode, type DiagnosticEvent, type DiagnosticKind, type Diagnostics, type DiagnosticSeverity } from "./dev.js";
|
|
12
|
+
export * from "./constants.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type QueueCallback, type Transition } from "./scheduler.js";
|
|
2
|
+
import type { Computed, Signal } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* OptimisticLane represents the context for a single optimistic write.
|
|
5
|
+
* Each optimistic signal creates its own lane. Lanes merge when their
|
|
6
|
+
* dependency graphs overlap.
|
|
7
|
+
*/
|
|
8
|
+
export interface OptimisticLane {
|
|
9
|
+
_source: Signal<any>;
|
|
10
|
+
_pendingAsync: Set<Computed<any>>;
|
|
11
|
+
_effectQueues: [QueueCallback[], QueueCallback[]];
|
|
12
|
+
_mergedInto: OptimisticLane | null;
|
|
13
|
+
_transition: Transition | null;
|
|
14
|
+
_parentLane: OptimisticLane | null;
|
|
15
|
+
}
|
|
16
|
+
export declare const signalLanes: WeakMap<Signal<any>, OptimisticLane>;
|
|
17
|
+
export declare const activeLanes: Set<OptimisticLane>;
|
|
18
|
+
/**
|
|
19
|
+
* Get an existing lane for a signal or create a new one.
|
|
20
|
+
* Reuses lane for multiple writes to the same signal.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getOrCreateLane(signal: Signal<any>): OptimisticLane;
|
|
23
|
+
/**
|
|
24
|
+
* Union-find: find the root lane.
|
|
25
|
+
*/
|
|
26
|
+
export declare function findLane(lane: OptimisticLane): OptimisticLane;
|
|
27
|
+
/**
|
|
28
|
+
* Merge two lanes when their dependency graphs overlap.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeLanes(lane1: OptimisticLane, lane2: OptimisticLane): OptimisticLane;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a node's lane: follow union-find chain, verify active, clear if stale.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveLane(el: {
|
|
35
|
+
_optimisticLane?: OptimisticLane;
|
|
36
|
+
}): OptimisticLane | undefined;
|
|
37
|
+
export declare function resolveTransition(el: {
|
|
38
|
+
_optimisticLane?: OptimisticLane;
|
|
39
|
+
_transition?: Transition | null;
|
|
40
|
+
}): Transition | null | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a node has an active optimistic override.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hasActiveOverride(el: {
|
|
45
|
+
_overrideValue?: any;
|
|
46
|
+
}): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Assign or merge a lane onto a node. At convergence points (node already has
|
|
49
|
+
* a different active lane), merge unless the node has an active override.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assignOrMergeLane(el: {
|
|
52
|
+
_optimisticLane?: OptimisticLane;
|
|
53
|
+
_overrideValue?: any;
|
|
54
|
+
}, sourceLane: OptimisticLane): void;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Computed, Disposable, Owner, Root } from "./types.js";
|
|
2
|
+
export declare function markDisposal(el: Owner): void;
|
|
3
|
+
export declare function dispose(node: Computed<unknown>): void;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
85
|
+
export declare function createOwner(options?: {
|
|
86
|
+
id?: string;
|
|
87
|
+
transparent?: boolean;
|
|
88
|
+
}): Root;
|
|
89
|
+
/**
|
|
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
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // Later, to tear everything down:
|
|
108
|
+
* dispose();
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/create-root
|
|
112
|
+
*/
|
|
113
|
+
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T), options?: {
|
|
114
|
+
id?: string;
|
|
115
|
+
transparent?: boolean;
|
|
116
|
+
}): T;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type Heap } from "./heap.js";
|
|
2
|
+
import { activeLanes, assignOrMergeLane, findLane } from "./lanes.js";
|
|
3
|
+
import type { Computed, Signal } from "./types.js";
|
|
4
|
+
export { activeLanes, assignOrMergeLane, findLane };
|
|
5
|
+
export { getOrCreateLane, hasActiveOverride, mergeLanes, resolveLane } from "./lanes.js";
|
|
6
|
+
export declare const dirtyQueue: Heap;
|
|
7
|
+
export declare const zombieQueue: Heap;
|
|
8
|
+
export declare let clock: number;
|
|
9
|
+
export declare let activeTransition: Transition | null;
|
|
10
|
+
export declare let projectionWriteActive: boolean;
|
|
11
|
+
export declare let _hitUnhandledAsync: boolean;
|
|
12
|
+
export declare function registerTransientStoreNode(node: Signal<any>): void;
|
|
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
|
+
*/
|
|
22
|
+
export declare function enforceLoadingBoundary(enabled: boolean): void;
|
|
23
|
+
export declare function shouldReadStashedOptimisticValue(node: Signal<any>): boolean;
|
|
24
|
+
export declare function setProjectionWriteActive(value: boolean): void;
|
|
25
|
+
export declare function setTrackedQueueCallback(value: boolean): void;
|
|
26
|
+
export type QueueCallback = (type: number) => void;
|
|
27
|
+
type QueueStub = {
|
|
28
|
+
_queues: [QueueCallback[], QueueCallback[]];
|
|
29
|
+
_children: QueueStub[];
|
|
30
|
+
};
|
|
31
|
+
type OptimisticNode = Signal<any> | Computed<any>;
|
|
32
|
+
export interface Transition {
|
|
33
|
+
_time: number;
|
|
34
|
+
_asyncReporters: Map<Computed<any>, Set<Computed<any>>>;
|
|
35
|
+
_pendingNodes: Signal<any>[];
|
|
36
|
+
_optimisticNodes: OptimisticNode[];
|
|
37
|
+
_optimisticStores: Set<any>;
|
|
38
|
+
_actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
|
|
39
|
+
_queueStash: QueueStub;
|
|
40
|
+
_done: boolean | Transition;
|
|
41
|
+
_gatedSubs: Set<Computed<any>>;
|
|
42
|
+
}
|
|
43
|
+
export declare function schedule(): void;
|
|
44
|
+
export interface IQueue {
|
|
45
|
+
enqueue(type: number, fn: QueueCallback): void;
|
|
46
|
+
run(type: number): boolean | void;
|
|
47
|
+
addChild(child: IQueue): void;
|
|
48
|
+
removeChild(child: IQueue): void;
|
|
49
|
+
created: number;
|
|
50
|
+
notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
|
|
51
|
+
stashQueues(stub: QueueStub): void;
|
|
52
|
+
restoreQueues(stub: QueueStub): void;
|
|
53
|
+
_parent: IQueue | null;
|
|
54
|
+
}
|
|
55
|
+
export declare class Queue implements IQueue {
|
|
56
|
+
_parent: IQueue | null;
|
|
57
|
+
_queues: [QueueCallback[], QueueCallback[]];
|
|
58
|
+
_children: IQueue[];
|
|
59
|
+
created: number;
|
|
60
|
+
addChild(child: IQueue): void;
|
|
61
|
+
removeChild(child: IQueue): void;
|
|
62
|
+
notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
|
|
63
|
+
run(type: number): void;
|
|
64
|
+
enqueue(type: number, fn: QueueCallback): void;
|
|
65
|
+
stashQueues(stub: QueueStub): void;
|
|
66
|
+
restoreQueues(stub: QueueStub): void;
|
|
67
|
+
}
|
|
68
|
+
export declare class GlobalQueue extends Queue {
|
|
69
|
+
_running: boolean;
|
|
70
|
+
_pendingNode: Signal<any> | null;
|
|
71
|
+
_pendingNodes: Signal<any>[];
|
|
72
|
+
_optimisticNodes: OptimisticNode[];
|
|
73
|
+
_optimisticStores: Set<any>;
|
|
74
|
+
static _update: (el: Computed<unknown>) => void;
|
|
75
|
+
static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
|
|
76
|
+
static _runEffect: (el: Computed<unknown>) => void;
|
|
77
|
+
static _clearOptimisticStore: ((store: any) => void) | null;
|
|
78
|
+
flush(): void;
|
|
79
|
+
notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
|
|
80
|
+
initTransition(transition?: Transition | null): void;
|
|
81
|
+
}
|
|
82
|
+
export declare function queuePendingNode(node: Signal<any>): void;
|
|
83
|
+
export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
|
|
84
|
+
export declare function finalizePureQueue(completingTransition?: Transition | null, incomplete?: boolean): void;
|
|
85
|
+
export declare function trackOptimisticStore(store: any): void;
|
|
86
|
+
export declare const globalQueue: GlobalQueue;
|
|
87
|
+
/**
|
|
88
|
+
* Synchronously processes the pending reactive queue, or runs `fn` in a synchronous
|
|
89
|
+
* flush scope before draining the queue.
|
|
90
|
+
*
|
|
91
|
+
* Reactive updates are normally batched onto the microtask queue, so multiple
|
|
92
|
+
* writes in a row collapse into a single update pass. Call `flush()` when you
|
|
93
|
+
* need to *observe* the result of those writes synchronously — most commonly
|
|
94
|
+
* in tests, but also at the boundary of imperative integration code. Pass a
|
|
95
|
+
* callback when the writes themselves should bypass microtask scheduling and
|
|
96
|
+
* drain synchronously when the callback returns.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const [count, setCount] = createSignal(0);
|
|
101
|
+
* const doubled = createMemo(() => count() * 2);
|
|
102
|
+
*
|
|
103
|
+
* setCount(5);
|
|
104
|
+
* flush();
|
|
105
|
+
* expect(doubled()).toBe(10);
|
|
106
|
+
*
|
|
107
|
+
* flush(() => setCount(6));
|
|
108
|
+
* expect(doubled()).toBe(12);
|
|
109
|
+
*
|
|
110
|
+
* // Nested flushes drain at each level:
|
|
111
|
+
* flush(() => {
|
|
112
|
+
* setCount(7);
|
|
113
|
+
* flush(() => setCount(8)); // inner drain — effects fire here
|
|
114
|
+
* // outer continues with up-to-date state
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function flush(): void;
|
|
119
|
+
export declare function flush<T>(fn: () => T): T;
|
|
120
|
+
export declare function currentTransition(transition: Transition): Transition;
|
|
121
|
+
export declare function setActiveTransition(transition: Transition | null): void;
|
|
122
|
+
export declare function runInTransition<T>(transition: Transition, fn: () => T): T;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { NOT_PENDING } from "./constants.js";
|
|
2
|
+
import type { OptimisticLane } from "./lanes.js";
|
|
3
|
+
import type { IQueue, Transition } from "./scheduler.js";
|
|
4
|
+
export interface Disposable {
|
|
5
|
+
(): void;
|
|
6
|
+
}
|
|
7
|
+
export interface Link {
|
|
8
|
+
_dep: Signal<unknown> | Computed<unknown>;
|
|
9
|
+
_sub: Computed<unknown>;
|
|
10
|
+
_nextDep: Link | null;
|
|
11
|
+
_prevSub: Link | null;
|
|
12
|
+
_nextSub: Link | null;
|
|
13
|
+
}
|
|
14
|
+
export interface NodeOptions<T> {
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
transparent?: boolean;
|
|
18
|
+
equals?: ((prev: T, next: T) => boolean) | false;
|
|
19
|
+
ownedWrite?: boolean;
|
|
20
|
+
/** Exclude this signal from snapshot capture (internal — not part of public API) */
|
|
21
|
+
_noSnapshot?: boolean;
|
|
22
|
+
unobserved?: () => void;
|
|
23
|
+
lazy?: boolean;
|
|
24
|
+
sync?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RawSignal<T> {
|
|
27
|
+
_subs: Link | null;
|
|
28
|
+
_subsTail: Link | null;
|
|
29
|
+
_value: T;
|
|
30
|
+
_snapshotValue?: any;
|
|
31
|
+
_name?: string;
|
|
32
|
+
_equals: false | ((a: T, b: T) => boolean);
|
|
33
|
+
_config: number;
|
|
34
|
+
_unobserved?: () => void;
|
|
35
|
+
_time: number;
|
|
36
|
+
_transition: Transition | null;
|
|
37
|
+
_pendingValue: T | typeof NOT_PENDING;
|
|
38
|
+
_overrideValue?: T | typeof NOT_PENDING;
|
|
39
|
+
_optimisticLane?: OptimisticLane;
|
|
40
|
+
_pendingSignal?: Signal<boolean>;
|
|
41
|
+
_latestValueComputed?: Computed<T>;
|
|
42
|
+
_parentSource?: Signal<any> | Computed<any>;
|
|
43
|
+
}
|
|
44
|
+
export interface FirewallSignal<T> extends RawSignal<T> {
|
|
45
|
+
_firewall: Computed<any>;
|
|
46
|
+
_nextChild: FirewallSignal<unknown> | null;
|
|
47
|
+
}
|
|
48
|
+
export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
|
|
49
|
+
export interface Owner {
|
|
50
|
+
id?: string;
|
|
51
|
+
_config: number;
|
|
52
|
+
_snapshotScope?: boolean;
|
|
53
|
+
_disposal: Disposable | Disposable[] | null;
|
|
54
|
+
_parent: Owner | null;
|
|
55
|
+
_context: Record<symbol | string, unknown>;
|
|
56
|
+
_childCount: number;
|
|
57
|
+
_queue: IQueue;
|
|
58
|
+
_firstChild: Owner | null;
|
|
59
|
+
_nextSibling: Owner | null;
|
|
60
|
+
_prevSibling: Owner | null;
|
|
61
|
+
_pendingDisposal: Disposable | Disposable[] | null;
|
|
62
|
+
_pendingFirstChild: Owner | null;
|
|
63
|
+
}
|
|
64
|
+
export interface Computed<T> extends RawSignal<T>, Owner {
|
|
65
|
+
_deps: Link | null;
|
|
66
|
+
_depsTail: Link | null;
|
|
67
|
+
_flags: number;
|
|
68
|
+
_blocked?: boolean;
|
|
69
|
+
_pendingSource?: Computed<any>;
|
|
70
|
+
_pendingSources?: Set<Computed<any>>;
|
|
71
|
+
_error?: unknown;
|
|
72
|
+
_statusFlags: number;
|
|
73
|
+
_height: number;
|
|
74
|
+
_nextHeap: Computed<any> | undefined;
|
|
75
|
+
_prevHeap: Computed<any>;
|
|
76
|
+
_fn: (prev?: T) => T;
|
|
77
|
+
_inFlight: PromiseLike<T> | AsyncIterable<T> | null;
|
|
78
|
+
_child: FirewallSignal<any> | null;
|
|
79
|
+
_notifyStatus?: (status?: number, error?: any) => void;
|
|
80
|
+
}
|
|
81
|
+
export interface Root extends Owner {
|
|
82
|
+
_root: true;
|
|
83
|
+
_parentComputed: Computed<any> | null;
|
|
84
|
+
dispose(self?: boolean): void;
|
|
85
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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.js";
|
|
2
|
+
import { type Dev } from "./core/index.js";
|
|
3
|
+
export declare const DEV: Dev | undefined;
|
|
4
|
+
export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.js";
|
|
5
|
+
export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.js";
|
|
6
|
+
export type { Accessor, SourceAccessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.js";
|
|
7
|
+
export { mapArray, repeat, type Maybe } from "./map.js";
|
|
8
|
+
export * from "./store/index.js";
|
|
9
|
+
export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten, type RevealOrder } from "./boundaries.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Accessor } from "./signals.js";
|
|
2
|
+
export type Maybe<T> = T | void | null | undefined | false;
|
|
3
|
+
/**
|
|
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.
|
|
7
|
+
*
|
|
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
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
28
|
+
*/
|
|
29
|
+
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
|
|
30
|
+
keyed?: boolean | ((item: Item) => any);
|
|
31
|
+
fallback?: Accessor<any>;
|
|
32
|
+
name?: string;
|
|
33
|
+
}): Accessor<MappedItem[]>;
|
|
34
|
+
/**
|
|
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
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
|
|
48
|
+
*/
|
|
49
|
+
export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
|
|
50
|
+
from?: Accessor<number | undefined>;
|
|
51
|
+
fallback?: Accessor<any>;
|
|
52
|
+
name?: string;
|
|
53
|
+
}): Accessor<any[]>;
|