@solidjs/signals 0.4.1 → 0.4.2
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 +497 -224
- package/dist/node.cjs +847 -574
- package/dist/prod.js +845 -572
- package/dist/types/core/core.d.ts +7 -3
- package/dist/types/core/effect.d.ts +2 -0
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +44 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +2 -11
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { type Flags } from "./flags.js";
|
|
30
30
|
import { Owner } from "./owner.js";
|
|
31
|
+
import { type Transition } from "./scheduler.js";
|
|
31
32
|
export interface SignalOptions<T> {
|
|
32
33
|
id?: string;
|
|
33
34
|
name?: string;
|
|
@@ -35,14 +36,16 @@ export interface SignalOptions<T> {
|
|
|
35
36
|
pureWrite?: boolean;
|
|
36
37
|
unobserved?: () => void;
|
|
37
38
|
}
|
|
38
|
-
interface SourceType {
|
|
39
|
+
export interface SourceType {
|
|
39
40
|
_observers: ObserverType[] | null;
|
|
40
41
|
_unobserved?: () => void;
|
|
41
42
|
_updateIfNecessary: () => void;
|
|
43
|
+
_transition?: Transition;
|
|
44
|
+
_cloned?: Computation;
|
|
42
45
|
_stateFlags: Flags;
|
|
43
46
|
_time: number;
|
|
44
47
|
}
|
|
45
|
-
interface ObserverType {
|
|
48
|
+
export interface ObserverType {
|
|
46
49
|
_sources: SourceType[] | null;
|
|
47
50
|
_notify: (state: number, skipQueue?: boolean) => void;
|
|
48
51
|
_handlerMask: Flags;
|
|
@@ -71,6 +74,8 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
|
|
|
71
74
|
_handlerMask: number;
|
|
72
75
|
_time: number;
|
|
73
76
|
_forceNotify: boolean;
|
|
77
|
+
_transition?: Transition | undefined;
|
|
78
|
+
_cloned?: Computation;
|
|
74
79
|
constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
|
|
75
80
|
_read(): T;
|
|
76
81
|
/**
|
|
@@ -154,4 +159,3 @@ export declare function runWithObserver<T>(observer: Computation, run: () => T):
|
|
|
154
159
|
*/
|
|
155
160
|
export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
|
|
156
161
|
export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
|
|
157
|
-
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EFFECT_RENDER, EFFECT_USER } from "./constants.js";
|
|
2
2
|
import { Computation, type SignalOptions } from "./core.js";
|
|
3
|
+
import { type Flags } from "./flags.js";
|
|
3
4
|
/**
|
|
4
5
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
5
6
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
@@ -18,6 +19,7 @@ export declare class Effect<T = any> extends Computation<T> {
|
|
|
18
19
|
});
|
|
19
20
|
write(value: T, flags?: number): T;
|
|
20
21
|
_notify(state: number, skipQueue?: boolean): void;
|
|
22
|
+
_notifyFlags(mask: Flags, newFlags: Flags): void;
|
|
21
23
|
_setError(error: unknown): void;
|
|
22
24
|
_disposeNode(): void;
|
|
23
25
|
_run(type: number): void;
|
|
@@ -2,6 +2,6 @@ export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./error.js";
|
|
|
2
2
|
export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
|
|
3
3
|
export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
|
|
4
4
|
export { Effect, EagerComputation } from "./effect.js";
|
|
5
|
-
export { flush, Queue, incrementClock,
|
|
5
|
+
export { flush, Queue, incrementClock, transition, ActiveTransition, type IQueue } from "./scheduler.js";
|
|
6
6
|
export * from "./constants.js";
|
|
7
7
|
export * from "./flags.js";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Computation, ObserverType } from "./core.js";
|
|
2
|
+
import type { Effect } from "./effect.js";
|
|
3
|
+
export declare let clock: number;
|
|
2
4
|
export declare function incrementClock(): void;
|
|
3
|
-
|
|
5
|
+
export declare let ActiveTransition: Transition | null;
|
|
6
|
+
export type QueueCallback = (type: number) => void;
|
|
4
7
|
export interface IQueue {
|
|
5
8
|
enqueue(type: number, fn: QueueCallback): void;
|
|
6
9
|
run(type: number): boolean | void;
|
|
@@ -30,4 +33,42 @@ export declare const globalQueue: Queue;
|
|
|
30
33
|
* the queue synchronously to get the latest updates by calling `flush()`.
|
|
31
34
|
*/
|
|
32
35
|
export declare function flush(): void;
|
|
33
|
-
export {
|
|
36
|
+
export declare class Transition implements IQueue {
|
|
37
|
+
_sources: Map<Computation, Computation>;
|
|
38
|
+
_pendingNodes: Set<Effect>;
|
|
39
|
+
_promises: Set<Promise<any>>;
|
|
40
|
+
_optimistic: Set<(() => void) & {
|
|
41
|
+
_transition?: Transition;
|
|
42
|
+
}>;
|
|
43
|
+
_done: Transition | boolean;
|
|
44
|
+
_queues: [QueueCallback[], QueueCallback[]];
|
|
45
|
+
_pureQueue: QueueCallback[];
|
|
46
|
+
_children: IQueue[];
|
|
47
|
+
_parent: IQueue | null;
|
|
48
|
+
_running: boolean;
|
|
49
|
+
_scheduled: boolean;
|
|
50
|
+
created: number;
|
|
51
|
+
enqueue(type: number, fn: QueueCallback): void;
|
|
52
|
+
run(type: number): void;
|
|
53
|
+
flush(): void;
|
|
54
|
+
addChild(child: IQueue): void;
|
|
55
|
+
removeChild(child: IQueue): void;
|
|
56
|
+
notify(node: Effect, type: number, flags: number): boolean;
|
|
57
|
+
schedule(): void;
|
|
58
|
+
runTransition(fn: () => any | Promise<any>, force?: boolean): void;
|
|
59
|
+
addOptimistic(fn: (() => void) & {
|
|
60
|
+
_transition?: Transition;
|
|
61
|
+
}): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Runs the given function in a transition scope, allowing for batch updates and optimizations.
|
|
65
|
+
* This is useful for grouping multiple state updates together to avoid unnecessary re-renders.
|
|
66
|
+
*
|
|
67
|
+
* @param fn A function that receives a resume function to continue the transition.
|
|
68
|
+
* The resume function can be called with another function to continue the transition.
|
|
69
|
+
*
|
|
70
|
+
* @description https://docs.solidjs.com/reference/advanced-reactivity/transition
|
|
71
|
+
*/
|
|
72
|
+
export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any>): void;
|
|
73
|
+
export declare function cloneGraph(node: Computation): Computation;
|
|
74
|
+
export declare function removeSourceObservers(node: ObserverType, index: number): void;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, runWithObserver, SUPPORTS_PROXY } from "./core/index.js";
|
|
1
|
+
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, runWithObserver, transition, SUPPORTS_PROXY } from "./core/index.js";
|
|
2
2
|
export type { SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
|
|
3
3
|
export { mapArray, repeat, type Maybe } from "./map.js";
|
|
4
4
|
export * from "./signals.js";
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -159,16 +159,6 @@ export declare function resolve<T>(fn: () => T): Promise<T>;
|
|
|
159
159
|
export type TryCatchResult<T, E> = [undefined, T] | [E];
|
|
160
160
|
export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
|
|
161
161
|
export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
|
|
162
|
-
/**
|
|
163
|
-
* Runs the given function in a transition scope, allowing for batch updates and optimizations.
|
|
164
|
-
* This is useful for grouping multiple state updates together to avoid unnecessary re-renders.
|
|
165
|
-
*
|
|
166
|
-
* @param fn A function that receives a resume function to continue the transition.
|
|
167
|
-
* The resume function can be called with another function to continue the transition.
|
|
168
|
-
*
|
|
169
|
-
* @description https://docs.solidjs.com/reference/advanced-reactivity/transition
|
|
170
|
-
*/
|
|
171
|
-
export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any>): void;
|
|
172
162
|
/**
|
|
173
163
|
* Creates an optimistic signal that can be used to optimistically update a value
|
|
174
164
|
* and then revert it back to the previous value at end of transition.
|
|
@@ -179,4 +169,5 @@ export declare function transition(fn: (resume: (fn: () => any | Promise<any>) =
|
|
|
179
169
|
*
|
|
180
170
|
* @returns A tuple containing an accessor for the current value and a setter function to apply changes.
|
|
181
171
|
*/
|
|
182
|
-
export declare function createOptimistic<T
|
|
172
|
+
export declare function createOptimistic<T>(initial: Exclude<T, Function>, compute?: never): [Accessor<T>, (value: T | ((v?: T) => T)) => void];
|
|
173
|
+
export declare function createOptimistic<T extends object, U>(initial: T | Accessor<T>, compute: (prev: T, change: U) => void, key: string | ((item: any) => any)): [Accessor<T>, (value: U | ((v?: U) => U)) => void];
|