@isograph/pico 0.0.0-main-5f205c00
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/LICENSE-MIT +7 -0
- package/README.md +152 -0
- package/dist/index.cjs +1154 -0
- package/dist/index.d.cts +176 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +176 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1139 -0
- package/dist/index.mjs.map +1 -0
- package/docs/contracts.md +45 -0
- package/docs/correctness.md +233 -0
- package/docs/design.md +97 -0
- package/docs/disposing-nodes.md +171 -0
- package/docs/lifetimes.md +25 -0
- package/docs/performance.md +85 -0
- package/package.json +49 -0
- package/src/batch/batch.ts +133 -0
- package/src/batch/flush.ts +30 -0
- package/src/batch/notifications.ts +39 -0
- package/src/disposal/age-drain.ts +124 -0
- package/src/disposal/cleanup.ts +171 -0
- package/src/disposal/older-than-updates.ts +132 -0
- package/src/disposal/schedule.ts +78 -0
- package/src/disposal/take.ts +52 -0
- package/src/disposal/update-counter.ts +9 -0
- package/src/graph/edges.ts +167 -0
- package/src/graph/marking.ts +310 -0
- package/src/graph/nodes.ts +196 -0
- package/src/graph/read.ts +150 -0
- package/src/graph/recompute.ts +127 -0
- package/src/graph/refresh.ts +232 -0
- package/src/index.ts +18 -0
- package/src/retention/retain.ts +133 -0
- package/src/state.ts +39 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
//#region src/graph/nodes.d.ts
|
|
2
|
+
declare function createSourceNode<TValue>(value: TValue): SourceNode<TValue>;
|
|
3
|
+
type SourceNode<in out TValue> = {
|
|
4
|
+
/** The committed source value. Reading this field records no dependency. */readonly value: TValue;
|
|
5
|
+
readonly [sourceBrand]: (value: TValue) => TValue;
|
|
6
|
+
};
|
|
7
|
+
declare const sourceBrand: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Returns an `UNCOMPUTED` derived node.
|
|
10
|
+
*
|
|
11
|
+
* Contract: `computation` is synchronous. `computation` reads other nodes
|
|
12
|
+
* only through `readSource` and `readDerived`, called with the `callingNode`
|
|
13
|
+
* that `computation` receives, and does not keep that `callingNode` for use
|
|
14
|
+
* after it returns. `computation` does not write, start or end a batch, retain,
|
|
15
|
+
* release, dispose, or call `readDerivedOutsideComputation`.
|
|
16
|
+
*/
|
|
17
|
+
declare function createDerivedNode<TValue>(computation: (callingNode: CallingNode, previous: TValue | undefined) => TValue): DerivedNode<TValue>;
|
|
18
|
+
type CallingNode = {
|
|
19
|
+
readonly [callingNodeBrand]: true;
|
|
20
|
+
};
|
|
21
|
+
declare const callingNodeBrand: unique symbol;
|
|
22
|
+
type DerivedNode<TValue> = {
|
|
23
|
+
readonly [derivedBrand]: TValue;
|
|
24
|
+
};
|
|
25
|
+
declare const derivedBrand: unique symbol;
|
|
26
|
+
type Retain<TValue> = {
|
|
27
|
+
readonly [retainBrand]: TValue;
|
|
28
|
+
};
|
|
29
|
+
declare const retainBrand: unique symbol;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/batch/batch.d.ts
|
|
32
|
+
/** Stage a write in the open batch, or publish it immediately when no batch is open. */
|
|
33
|
+
declare function writeSource<TValue>(source: SourceNode<TValue>, value: TValue): void;
|
|
34
|
+
/** Open one synchronous write batch. Callers must not nest batches or read or retain nodes inside one. */
|
|
35
|
+
declare function startWriteBatch(): void;
|
|
36
|
+
/** Publish the last write to each source, refresh the graph, then notify subscribers. */
|
|
37
|
+
declare function endWriteBatch(): void;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/disposal/cleanup.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Pops one entry off the cleanup queue and disposes its node if the node is
|
|
42
|
+
* still unneeded and not `UNCOMPUTED`. Disposing a node puts each of its
|
|
43
|
+
* derived dependencies that becomes unneeded on the cleanup queue. Returns
|
|
44
|
+
* whether the cleanup queue is non-empty.
|
|
45
|
+
*
|
|
46
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
47
|
+
*/
|
|
48
|
+
declare function disposeNext(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Disposes every unneeded node on the cleanup queue, and each node that a
|
|
51
|
+
* disposal leaves unneeded.
|
|
52
|
+
*
|
|
53
|
+
* Guarantee: after `disposeNext` returns false, and after `disposeAll`
|
|
54
|
+
* returns, the cleanup queue is empty and no scheduler call is pending.
|
|
55
|
+
*
|
|
56
|
+
* Contract: as `disposeNext`.
|
|
57
|
+
*/
|
|
58
|
+
declare function disposeAll(): void;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/disposal/schedule.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* `scheduler.schedule` is called with no arguments at the end of an outermost
|
|
63
|
+
* operation after the cleanup queue went from empty to non-empty, or after a
|
|
64
|
+
* `disposeOlderThanUpdates` that left entries. A `writeSource` to a source that
|
|
65
|
+
* has no dependents, or that no computation read since the source was created
|
|
66
|
+
* or last written, returns before that call. `schedule` may call `disposeAll`
|
|
67
|
+
* synchronously. The default calls `disposeOlderThanUpdates(2)` once per call
|
|
68
|
+
* of `schedule`, with the time of a `requestIdleCallback` callback where that
|
|
69
|
+
* exists and of a 5 ms `setTimeout` task elsewhere, and requests another
|
|
70
|
+
* callback or task only when that drain ran out of time before an old entry.
|
|
71
|
+
* Assigning `scheduler.schedule` replaces the default.
|
|
72
|
+
*
|
|
73
|
+
* Contract: after a call, the scheduler calls `disposeNext` until it returns
|
|
74
|
+
* false, calls `disposeAll`, or calls `disposeOlderThanUpdates` once.
|
|
75
|
+
*/
|
|
76
|
+
declare const scheduler: {
|
|
77
|
+
schedule: () => void;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/disposal/older-than-updates.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* Disposes unneeded nodes whose newest cleanup entry is at least minAge
|
|
83
|
+
* updates old. Age starts at the first drain that sees an entry. A write
|
|
84
|
+
* or batch commit advances the update count. Repeated drains do not.
|
|
85
|
+
* Disposing a node can leave its inputs unneeded; these are eligible immediately.
|
|
86
|
+
*
|
|
87
|
+
* An optional idle deadline or performance.now() timestamp limits disposal.
|
|
88
|
+
* The queue scan always finishes, and the first eligible disposal always
|
|
89
|
+
* runs. Unfinished entries keep their ages for the next drain. If another
|
|
90
|
+
* disposal strategy removed the boundary marker between drains, the
|
|
91
|
+
* remaining entries start aging again at the current update count.
|
|
92
|
+
*
|
|
93
|
+
* Returns the number of entries still queued. When entries remain, request
|
|
94
|
+
* another scheduler call at the end of the next outermost operation.
|
|
95
|
+
* Call outside computations, batches, and callbacks, with an integer minAge.
|
|
96
|
+
*/
|
|
97
|
+
declare function disposeOlderThanUpdates<TDeadline extends {
|
|
98
|
+
timeRemaining(): number;
|
|
99
|
+
}>(minAge: number, budget?: TDeadline | number): number;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/graph/read.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* Returns the value of `source` and records it as a dependency of
|
|
104
|
+
* `callingNode`.
|
|
105
|
+
*
|
|
106
|
+
* Contract: called only while the computation of `callingNode` runs.
|
|
107
|
+
*/
|
|
108
|
+
declare function readSource<TValue>(callingNode: CallingNode, source: SourceNode<TValue>): TValue;
|
|
109
|
+
/**
|
|
110
|
+
* Brings `node` up to date, returns its value, and records it as a dependency
|
|
111
|
+
* of `callingNode`.
|
|
112
|
+
*
|
|
113
|
+
* Contract: called only while the computation of `callingNode` runs.
|
|
114
|
+
*/
|
|
115
|
+
declare function readDerived<TValue>(callingNode: CallingNode, node: DerivedNode<TValue>): TValue;
|
|
116
|
+
/**
|
|
117
|
+
* Top-level read of `node`: brings `node` up to date and returns its value. A
|
|
118
|
+
* recompute links edges as in a tracked read. A node left unneeded goes on the
|
|
119
|
+
* cleanup queue, so the scheduler can dispose it and each dependency that its
|
|
120
|
+
* disposal leaves unneeded.
|
|
121
|
+
*
|
|
122
|
+
* Contract: called outside computations and write batch bodies. Inside an
|
|
123
|
+
* `onChange`, it is allowed.
|
|
124
|
+
*/
|
|
125
|
+
declare function readDerivedOutsideComputation<TValue>(node: DerivedNode<TValue>): TValue;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/retention/retain.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Brings `node` up to date, adds a retain to the head of its retain list, and
|
|
130
|
+
* returns the retain. A retained node keeps its value and its edges to its
|
|
131
|
+
* dependencies until its last retain is released. A retain with an
|
|
132
|
+
* `onChange` gives the node a callback.
|
|
133
|
+
*
|
|
134
|
+
* Guarantee: the flush calls `onChange` with the node's value once for each
|
|
135
|
+
* update or batch that changed the node's value, after the flush has
|
|
136
|
+
* refreshed every node on the flush queue. The first recompute of a node does
|
|
137
|
+
* not call `onChange`.
|
|
138
|
+
*
|
|
139
|
+
* Contract: called outside computations, `onChange` callbacks, and write
|
|
140
|
+
* batch bodies, because retaining computes the node. `onChange` does not
|
|
141
|
+
* write, start or end a batch, retain, release, or dispose. It may call
|
|
142
|
+
* `readDerivedOutsideComputation`.
|
|
143
|
+
*/
|
|
144
|
+
declare function retainDerivedNode<TValue>(node: DerivedNode<TValue>, onChange?: (value: TValue) => void): Retain<TValue>;
|
|
145
|
+
/**
|
|
146
|
+
* Releases `retain`. A release that leaves the node unneeded puts the node on
|
|
147
|
+
* the cleanup queue. The node keeps its value and its edges until a disposal,
|
|
148
|
+
* or the marking of a write, reaches it.
|
|
149
|
+
*
|
|
150
|
+
* Contract: called once per retain, outside computations and `onChange`
|
|
151
|
+
* callbacks.
|
|
152
|
+
*/
|
|
153
|
+
declare function releaseRetain<TValue>(retain: Retain<TValue>): void;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/disposal/take.d.ts
|
|
156
|
+
/**
|
|
157
|
+
* Empties the cleanup queue and returns the node of each entry whose node is
|
|
158
|
+
* still unneeded and not `UNCOMPUTED`, oldest entry first. A node with several
|
|
159
|
+
* entries appears once per entry. pico-js no longer holds a taken node for
|
|
160
|
+
* disposal: it queues the node again only when the node becomes unneeded again
|
|
161
|
+
* after it is needed, or on a top-level read while it is unneeded.
|
|
162
|
+
*
|
|
163
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
164
|
+
*/
|
|
165
|
+
declare function takeUnneeded(): ReadonlyArray<DerivedNode<unknown>>;
|
|
166
|
+
/**
|
|
167
|
+
* Disposes `node` if it is unneeded and not `UNCOMPUTED`, and returns whether
|
|
168
|
+
* it did. The dependencies that the disposal leaves unneeded go on the cleanup
|
|
169
|
+
* queue.
|
|
170
|
+
*
|
|
171
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
172
|
+
*/
|
|
173
|
+
declare function disposeIfUnneeded(node: DerivedNode<unknown>): boolean;
|
|
174
|
+
//#endregion
|
|
175
|
+
export { type CallingNode, type DerivedNode, type Retain, type SourceNode, createDerivedNode, createSourceNode, disposeAll, disposeIfUnneeded, disposeNext, disposeOlderThanUpdates, endWriteBatch, readDerived, readDerivedOutsideComputation, readSource, releaseRetain, retainDerivedNode, scheduler, startWriteBatch, takeUnneeded, writeSource };
|
|
176
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/graph/nodes.ts","../src/batch/batch.ts","../src/disposal/cleanup.ts","../src/disposal/schedule.ts","../src/disposal/older-than-updates.ts","../src/graph/read.ts","../src/retention/retain.ts","../src/disposal/take.ts"],"mappings":";iBAgBgB,gBAAA,QAAA,CAAyB,KAAA,EAAO,MAAA,GAAS,UAAA,CAAW,MAAA;AAAA,KAmBxD,UAAA;EAnBoC,qFAqBrC,KAAA,EAAO,MAAA;EAAA,UACN,WAAA,IAAe,KAAA,EAAO,MAAA,KAAW,MAAA;AAAA;AAAA,cAG/B,WAAA;;AANd;;;;;;;;iBA4BgB,iBAAA,QAAA,CACd,WAAA,GACE,WAAA,EAAa,WAAA,EACb,QAAA,EAAU,MAAA,iBACP,MAAA,GACJ,WAAA,CAAY,MAAA;AAAA,KA0BH,WA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package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
//#region src/graph/nodes.d.ts
|
|
2
|
+
declare function createSourceNode<TValue>(value: TValue): SourceNode<TValue>;
|
|
3
|
+
type SourceNode<in out TValue> = {
|
|
4
|
+
/** The committed source value. Reading this field records no dependency. */readonly value: TValue;
|
|
5
|
+
readonly [sourceBrand]: (value: TValue) => TValue;
|
|
6
|
+
};
|
|
7
|
+
declare const sourceBrand: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* Returns an `UNCOMPUTED` derived node.
|
|
10
|
+
*
|
|
11
|
+
* Contract: `computation` is synchronous. `computation` reads other nodes
|
|
12
|
+
* only through `readSource` and `readDerived`, called with the `callingNode`
|
|
13
|
+
* that `computation` receives, and does not keep that `callingNode` for use
|
|
14
|
+
* after it returns. `computation` does not write, start or end a batch, retain,
|
|
15
|
+
* release, dispose, or call `readDerivedOutsideComputation`.
|
|
16
|
+
*/
|
|
17
|
+
declare function createDerivedNode<TValue>(computation: (callingNode: CallingNode, previous: TValue | undefined) => TValue): DerivedNode<TValue>;
|
|
18
|
+
type CallingNode = {
|
|
19
|
+
readonly [callingNodeBrand]: true;
|
|
20
|
+
};
|
|
21
|
+
declare const callingNodeBrand: unique symbol;
|
|
22
|
+
type DerivedNode<TValue> = {
|
|
23
|
+
readonly [derivedBrand]: TValue;
|
|
24
|
+
};
|
|
25
|
+
declare const derivedBrand: unique symbol;
|
|
26
|
+
type Retain<TValue> = {
|
|
27
|
+
readonly [retainBrand]: TValue;
|
|
28
|
+
};
|
|
29
|
+
declare const retainBrand: unique symbol;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/batch/batch.d.ts
|
|
32
|
+
/** Stage a write in the open batch, or publish it immediately when no batch is open. */
|
|
33
|
+
declare function writeSource<TValue>(source: SourceNode<TValue>, value: TValue): void;
|
|
34
|
+
/** Open one synchronous write batch. Callers must not nest batches or read or retain nodes inside one. */
|
|
35
|
+
declare function startWriteBatch(): void;
|
|
36
|
+
/** Publish the last write to each source, refresh the graph, then notify subscribers. */
|
|
37
|
+
declare function endWriteBatch(): void;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/disposal/cleanup.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Pops one entry off the cleanup queue and disposes its node if the node is
|
|
42
|
+
* still unneeded and not `UNCOMPUTED`. Disposing a node puts each of its
|
|
43
|
+
* derived dependencies that becomes unneeded on the cleanup queue. Returns
|
|
44
|
+
* whether the cleanup queue is non-empty.
|
|
45
|
+
*
|
|
46
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
47
|
+
*/
|
|
48
|
+
declare function disposeNext(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Disposes every unneeded node on the cleanup queue, and each node that a
|
|
51
|
+
* disposal leaves unneeded.
|
|
52
|
+
*
|
|
53
|
+
* Guarantee: after `disposeNext` returns false, and after `disposeAll`
|
|
54
|
+
* returns, the cleanup queue is empty and no scheduler call is pending.
|
|
55
|
+
*
|
|
56
|
+
* Contract: as `disposeNext`.
|
|
57
|
+
*/
|
|
58
|
+
declare function disposeAll(): void;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/disposal/schedule.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* `scheduler.schedule` is called with no arguments at the end of an outermost
|
|
63
|
+
* operation after the cleanup queue went from empty to non-empty, or after a
|
|
64
|
+
* `disposeOlderThanUpdates` that left entries. A `writeSource` to a source that
|
|
65
|
+
* has no dependents, or that no computation read since the source was created
|
|
66
|
+
* or last written, returns before that call. `schedule` may call `disposeAll`
|
|
67
|
+
* synchronously. The default calls `disposeOlderThanUpdates(2)` once per call
|
|
68
|
+
* of `schedule`, with the time of a `requestIdleCallback` callback where that
|
|
69
|
+
* exists and of a 5 ms `setTimeout` task elsewhere, and requests another
|
|
70
|
+
* callback or task only when that drain ran out of time before an old entry.
|
|
71
|
+
* Assigning `scheduler.schedule` replaces the default.
|
|
72
|
+
*
|
|
73
|
+
* Contract: after a call, the scheduler calls `disposeNext` until it returns
|
|
74
|
+
* false, calls `disposeAll`, or calls `disposeOlderThanUpdates` once.
|
|
75
|
+
*/
|
|
76
|
+
declare const scheduler: {
|
|
77
|
+
schedule: () => void;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/disposal/older-than-updates.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* Disposes unneeded nodes whose newest cleanup entry is at least minAge
|
|
83
|
+
* updates old. Age starts at the first drain that sees an entry. A write
|
|
84
|
+
* or batch commit advances the update count. Repeated drains do not.
|
|
85
|
+
* Disposing a node can leave its inputs unneeded; these are eligible immediately.
|
|
86
|
+
*
|
|
87
|
+
* An optional idle deadline or performance.now() timestamp limits disposal.
|
|
88
|
+
* The queue scan always finishes, and the first eligible disposal always
|
|
89
|
+
* runs. Unfinished entries keep their ages for the next drain. If another
|
|
90
|
+
* disposal strategy removed the boundary marker between drains, the
|
|
91
|
+
* remaining entries start aging again at the current update count.
|
|
92
|
+
*
|
|
93
|
+
* Returns the number of entries still queued. When entries remain, request
|
|
94
|
+
* another scheduler call at the end of the next outermost operation.
|
|
95
|
+
* Call outside computations, batches, and callbacks, with an integer minAge.
|
|
96
|
+
*/
|
|
97
|
+
declare function disposeOlderThanUpdates<TDeadline extends {
|
|
98
|
+
timeRemaining(): number;
|
|
99
|
+
}>(minAge: number, budget?: TDeadline | number): number;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/graph/read.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* Returns the value of `source` and records it as a dependency of
|
|
104
|
+
* `callingNode`.
|
|
105
|
+
*
|
|
106
|
+
* Contract: called only while the computation of `callingNode` runs.
|
|
107
|
+
*/
|
|
108
|
+
declare function readSource<TValue>(callingNode: CallingNode, source: SourceNode<TValue>): TValue;
|
|
109
|
+
/**
|
|
110
|
+
* Brings `node` up to date, returns its value, and records it as a dependency
|
|
111
|
+
* of `callingNode`.
|
|
112
|
+
*
|
|
113
|
+
* Contract: called only while the computation of `callingNode` runs.
|
|
114
|
+
*/
|
|
115
|
+
declare function readDerived<TValue>(callingNode: CallingNode, node: DerivedNode<TValue>): TValue;
|
|
116
|
+
/**
|
|
117
|
+
* Top-level read of `node`: brings `node` up to date and returns its value. A
|
|
118
|
+
* recompute links edges as in a tracked read. A node left unneeded goes on the
|
|
119
|
+
* cleanup queue, so the scheduler can dispose it and each dependency that its
|
|
120
|
+
* disposal leaves unneeded.
|
|
121
|
+
*
|
|
122
|
+
* Contract: called outside computations and write batch bodies. Inside an
|
|
123
|
+
* `onChange`, it is allowed.
|
|
124
|
+
*/
|
|
125
|
+
declare function readDerivedOutsideComputation<TValue>(node: DerivedNode<TValue>): TValue;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/retention/retain.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Brings `node` up to date, adds a retain to the head of its retain list, and
|
|
130
|
+
* returns the retain. A retained node keeps its value and its edges to its
|
|
131
|
+
* dependencies until its last retain is released. A retain with an
|
|
132
|
+
* `onChange` gives the node a callback.
|
|
133
|
+
*
|
|
134
|
+
* Guarantee: the flush calls `onChange` with the node's value once for each
|
|
135
|
+
* update or batch that changed the node's value, after the flush has
|
|
136
|
+
* refreshed every node on the flush queue. The first recompute of a node does
|
|
137
|
+
* not call `onChange`.
|
|
138
|
+
*
|
|
139
|
+
* Contract: called outside computations, `onChange` callbacks, and write
|
|
140
|
+
* batch bodies, because retaining computes the node. `onChange` does not
|
|
141
|
+
* write, start or end a batch, retain, release, or dispose. It may call
|
|
142
|
+
* `readDerivedOutsideComputation`.
|
|
143
|
+
*/
|
|
144
|
+
declare function retainDerivedNode<TValue>(node: DerivedNode<TValue>, onChange?: (value: TValue) => void): Retain<TValue>;
|
|
145
|
+
/**
|
|
146
|
+
* Releases `retain`. A release that leaves the node unneeded puts the node on
|
|
147
|
+
* the cleanup queue. The node keeps its value and its edges until a disposal,
|
|
148
|
+
* or the marking of a write, reaches it.
|
|
149
|
+
*
|
|
150
|
+
* Contract: called once per retain, outside computations and `onChange`
|
|
151
|
+
* callbacks.
|
|
152
|
+
*/
|
|
153
|
+
declare function releaseRetain<TValue>(retain: Retain<TValue>): void;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/disposal/take.d.ts
|
|
156
|
+
/**
|
|
157
|
+
* Empties the cleanup queue and returns the node of each entry whose node is
|
|
158
|
+
* still unneeded and not `UNCOMPUTED`, oldest entry first. A node with several
|
|
159
|
+
* entries appears once per entry. pico-js no longer holds a taken node for
|
|
160
|
+
* disposal: it queues the node again only when the node becomes unneeded again
|
|
161
|
+
* after it is needed, or on a top-level read while it is unneeded.
|
|
162
|
+
*
|
|
163
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
164
|
+
*/
|
|
165
|
+
declare function takeUnneeded(): ReadonlyArray<DerivedNode<unknown>>;
|
|
166
|
+
/**
|
|
167
|
+
* Disposes `node` if it is unneeded and not `UNCOMPUTED`, and returns whether
|
|
168
|
+
* it did. The dependencies that the disposal leaves unneeded go on the cleanup
|
|
169
|
+
* queue.
|
|
170
|
+
*
|
|
171
|
+
* Contract: called outside computations, batches, and `onChange` callbacks.
|
|
172
|
+
*/
|
|
173
|
+
declare function disposeIfUnneeded(node: DerivedNode<unknown>): boolean;
|
|
174
|
+
//#endregion
|
|
175
|
+
export { type CallingNode, type DerivedNode, type Retain, type SourceNode, createDerivedNode, createSourceNode, disposeAll, disposeIfUnneeded, disposeNext, disposeOlderThanUpdates, endWriteBatch, readDerived, readDerivedOutsideComputation, readSource, releaseRetain, retainDerivedNode, scheduler, startWriteBatch, takeUnneeded, writeSource };
|
|
176
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/graph/nodes.ts","../src/batch/batch.ts","../src/disposal/cleanup.ts","../src/disposal/schedule.ts","../src/disposal/older-than-updates.ts","../src/graph/read.ts","../src/retention/retain.ts","../src/disposal/take.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