@solidjs/signals 0.0.6 → 0.0.8

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.
@@ -42,7 +42,7 @@ interface SourceType {
42
42
  }
43
43
  interface ObserverType {
44
44
  _sources: SourceType[] | null;
45
- _notify: (state: number) => void;
45
+ _notify: (state: number, skipQueue?: boolean) => void;
46
46
  _handlerMask: Flags;
47
47
  _notifyFlags: (mask: Flags, newFlags: Flags) => void;
48
48
  _time: number;
@@ -51,6 +51,7 @@ interface ObserverType {
51
51
  * Returns the current observer.
52
52
  */
53
53
  export declare function getObserver(): ObserverType | null;
54
+ export declare function getClock(): number;
54
55
  export declare function incrementClock(): void;
55
56
  export declare const UNCHANGED: unique symbol;
56
57
  export type UNCHANGED = typeof UNCHANGED;
@@ -66,9 +67,9 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
66
67
  _stateFlags: number;
67
68
  /** Which flags raised by sources are handled, vs. being passed through. */
68
69
  _handlerMask: number;
69
- _error: Computation<boolean> | null;
70
70
  _loading: Computation<boolean> | null;
71
71
  _time: number;
72
+ _forceNotify: boolean;
72
73
  constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
73
74
  _read(): T;
74
75
  /**
@@ -92,17 +93,12 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
92
93
  * loading state changes
93
94
  */
94
95
  loading(): boolean;
95
- /**
96
- * Return true if the computation is the computation threw an error
97
- * Triggers re-execution of the computation when the error state changes
98
- */
99
- error(): boolean;
100
96
  /** Update the computation with a new value. */
101
97
  write(value: T | ((currentValue: T) => T) | UNCHANGED, flags?: number, raw?: boolean): T;
102
98
  /**
103
99
  * Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
104
100
  */
105
- _notify(state: number): void;
101
+ _notify(state: number, skipQueue?: boolean): void;
106
102
  /**
107
103
  * Notify the computation that one of its sources has changed flags.
108
104
  *
@@ -147,7 +143,15 @@ export declare function hasUpdated(fn: () => any): boolean;
147
143
  * Returns true if the given function contains async signals that are not ready yet.
148
144
  */
149
145
  export declare function isPending(fn: () => any): boolean;
150
- export declare function latest<T>(fn: () => T): T | undefined;
146
+ export type PossiblyResolved<T> = T extends Object ? RecursivePartial<T> : T;
147
+ export type RecursivePartial<T> = {
148
+ [P in keyof T]?: PossiblyResolved<T[P]>;
149
+ };
150
+ /**
151
+ * Attempts to resolve value of expression synchronously returning the last resolved value for any async computation.
152
+ */
153
+ export declare function resolveSync<T>(fn: () => T): PossiblyResolved<T> | undefined;
154
+ export declare function catchError(fn: () => void): unknown | undefined;
151
155
  /**
152
156
  * A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
153
157
  * to reset the global context after the computation is finished even if an error is thrown.
@@ -7,16 +7,19 @@ import { type IQueue } from "./scheduler.js";
7
7
  * sources and recompute
8
8
  */
9
9
  export declare class Effect<T = any> extends Computation<T> {
10
- _effect: (val: T, prev: T | undefined) => void;
10
+ _effect: (val: T, prev: T | undefined) => void | (() => void);
11
+ _error: ((err: unknown) => void | (() => void)) | undefined;
12
+ _cleanup: (() => void) | undefined;
11
13
  _modified: boolean;
12
14
  _prevValue: T | undefined;
13
15
  _type: typeof EFFECT_RENDER | typeof EFFECT_USER;
14
16
  _queue: IQueue;
15
- constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void, options?: SignalOptions<T> & {
17
+ constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown) => void | (() => void), options?: SignalOptions<T> & {
16
18
  render?: boolean;
19
+ defer?: boolean;
17
20
  });
18
21
  write(value: T, flags?: number): T;
19
- _notify(state: number): void;
22
+ _notify(state: number, skipQueue?: boolean): void;
20
23
  _setError(error: unknown): void;
21
24
  _disposeNode(): void;
22
25
  _runEffect(): void;
@@ -24,5 +27,5 @@ export declare class Effect<T = any> extends Computation<T> {
24
27
  export declare class EagerComputation<T = any> extends Computation<T> {
25
28
  _queue: IQueue;
26
29
  constructor(initialValue: T, compute: () => T, options?: SignalOptions<T>);
27
- _notify(state: number): void;
30
+ _notify(state: number, skipQueue?: boolean): void;
28
31
  }
@@ -6,6 +6,9 @@ export declare class NoOwnerError extends Error {
6
6
  export declare class ContextNotFoundError extends Error {
7
7
  constructor();
8
8
  }
9
+ export declare class EffectError extends Error {
10
+ constructor(effect: Function, cause: unknown);
11
+ }
9
12
  export interface ErrorHandler {
10
13
  (error: unknown): void;
11
14
  }
@@ -1,8 +1,8 @@
1
1
  export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler } from "./error.js";
2
2
  export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
3
- export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, type SignalOptions } from "./core.js";
3
+ export { Computation, getObserver, isEqual, untrack, getClock, hasUpdated, isPending, resolveSync, catchError, UNCHANGED, compute, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
- export { flushSync, createBoundary, queueTask, type IQueue, Queue } from "./scheduler.js";
5
+ export { flushSync, createBoundary, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
7
7
  export { SUPPORTS_PROXY } from "./constants.js";
8
8
  export * from "./flags.js";
@@ -2,7 +2,7 @@ import { Computation } from "./core.js";
2
2
  import type { Effect } from "./effect.js";
3
3
  export interface IQueue {
4
4
  enqueue<T extends Computation | Effect>(type: number, node: T): void;
5
- run(type: number): void;
5
+ run(type: number): boolean | void;
6
6
  flush(): void;
7
7
  addChild(child: IQueue): void;
8
8
  removeChild(child: IQueue): void;
@@ -12,7 +12,7 @@ export declare class Queue implements IQueue {
12
12
  _queues: [Computation[], Effect[], Effect[]];
13
13
  _children: IQueue[];
14
14
  enqueue<T extends Computation | Effect>(type: number, node: T): void;
15
- run(type: number): void;
15
+ run(type: number): true | undefined;
16
16
  flush(): void;
17
17
  addChild(child: IQueue): void;
18
18
  removeChild(child: IQueue): void;
@@ -23,5 +23,4 @@ export declare const globalQueue: Queue;
23
23
  * the queue synchronously to get the latest updates by calling `flushSync()`.
24
24
  */
25
25
  export declare function flushSync(): void;
26
- export declare function queueTask(fn: () => void): void;
27
26
  export declare function createBoundary<T>(fn: () => T, queue: IQueue): T;
@@ -5,7 +5,7 @@ export declare class SuspenseQueue extends Queue {
5
5
  _nodes: Set<Effect>;
6
6
  _fallback: boolean;
7
7
  _signal: Computation<boolean>;
8
- run(type: number): void;
8
+ run(type: number): true | undefined;
9
9
  _update(node: Effect): void;
10
10
  }
11
11
  export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
@@ -1,5 +1,5 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, resolveSync, catchError, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
2
2
  export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
3
- export { mapArray, type Maybe } from "./map.js";
3
+ export { mapArray, repeat, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
5
5
  export * from "./store/index.js";
@@ -3,7 +3,7 @@ export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
4
  * Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
5
5
  *
6
- * similar to `Array.prototype.map`, but gets the value and index as accessos, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
6
+ * similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
7
7
  *
8
8
  * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
9
9
  */
@@ -11,3 +11,11 @@ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly
11
11
  keyed?: boolean | ((item: Item) => any);
12
12
  fallback?: Accessor<any>;
13
13
  }): Accessor<MappedItem[]>;
14
+ /**
15
+ * Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
16
+ *
17
+ * @description https://docs.solidjs.com/reference/reactive-utilities/repeat
18
+ */
19
+ export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
20
+ fallback?: Accessor<any>;
21
+ }): Accessor<any[]>;
@@ -87,14 +87,15 @@ export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | Async
87
87
  * ): void;
88
88
  * ```
89
89
  * @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
90
- * @param effect a function that receives the new value and is used to perform side effects
90
+ * @param effect a function that receives the new value and is used to perform side effects, return a cleanup function to run on disposal
91
+ * @param error an optional function that receives an error if thrown during the computation
91
92
  * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
92
93
  * @param options allows to set a name in dev mode for debugging purposes
93
94
  *
94
95
  * @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
95
96
  */
96
- export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
97
- export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
97
+ export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>, error?: (err: unknown) => void): void;
98
+ export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, error: (err: unknown) => void | undefined, value: Init, options?: EffectOptions): void;
98
99
  /**
99
100
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
100
101
  * ```typescript
@@ -139,3 +140,23 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T |
139
140
  * @description https://docs.solidjs.com/reference/reactive-utilities/catch-error
140
141
  */
141
142
  export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: unknown, reset: () => void) => U): Accessor<T | U>;
143
+ /**
144
+ * Returns a promise of the resolved value of a reactive expression
145
+ * @param fn a reactive expression to resolve
146
+ */
147
+ export declare function resolve<T>(fn: () => T): Promise<T>;
148
+ /**
149
+ * Creates a reactive computation that runs after the render phase with flexible tracking
150
+ * ```typescript
151
+ * export function createReaction(
152
+ * effect: () => void,
153
+ * options?: { name?: string }
154
+ * ): (fn: () => void) => void;
155
+ * ```
156
+ * @param effect a function that is called when tracked function is invalidated.
157
+ * @param error an optional function that receives an error if thrown during tracking
158
+ * @param options allows to set a name in dev mode for debugging purposes
159
+ *
160
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
161
+ */
162
+ export declare function createReaction(effect: () => (() => void) | void, error?: (err: unknown) => (() => void) | void, options?: EffectOptions): (tracking: () => void) => void;
@@ -1,5 +1,6 @@
1
1
  export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
2
2
  export type { Merge, Omit } from "./utilities.js";
3
- export { unwrap, isWrappable, createStore, createProjection, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
3
+ export { unwrap, isWrappable, createStore, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
4
+ export { createProjection } from "./projection.js";
4
5
  export { reconcile } from "./reconcile.js";
5
6
  export { merge, omit } from "./utilities.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Creates a mutable derived value
3
+ *
4
+ * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
5
+ */
6
+ export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): any;
@@ -32,9 +32,3 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
32
32
  export declare function unwrap<T>(item: T, deep?: boolean, set?: Set<unknown>): T;
33
33
  export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
34
34
  export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
35
- /**
36
- * Creates a mutable derived value
37
- *
38
- * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
39
- */
40
- export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): Readonly<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",