@solidjs/signals 0.6.3 → 0.7.0

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.
@@ -6,7 +6,7 @@ export declare class CollectionQueue extends Queue {
6
6
  _disabled: Computation<boolean>;
7
7
  constructor(type: number);
8
8
  run(type: number): void;
9
- notify(node: Effect, type: number, flags: number): any;
9
+ notify(node: Effect, type: number, flags: number): boolean;
10
10
  merge(queue: CollectionQueue): void;
11
11
  }
12
12
  export declare enum BoundaryMode {
@@ -77,6 +77,7 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
77
77
  _forceNotify: boolean;
78
78
  _transition?: Transition | undefined;
79
79
  _cloned?: Computation;
80
+ _optimistic?: boolean;
80
81
  constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
81
82
  _read(): T;
82
83
  /**
@@ -148,12 +149,6 @@ export declare function isPending(fn: () => any, loadingValue: boolean): boolean
148
149
  */
149
150
  export declare function latest<T>(fn: () => T): T;
150
151
  export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
151
- /**
152
- * Runs the given function in the given observer.
153
- *
154
- * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
155
- */
156
- export declare function runWithObserver<T>(observer: Computation, run: () => T): T | undefined;
157
152
  /**
158
153
  * A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
159
154
  * to reset the global context after the computation is finished even if an error is thrown.
@@ -24,6 +24,14 @@ export declare class Effect<T = any> extends Computation<T> {
24
24
  _disposeNode(): void;
25
25
  _run(type: number): void;
26
26
  }
27
+ export declare class TrackedEffect extends Computation {
28
+ _type: number;
29
+ _cleanup: (() => void) | undefined;
30
+ constructor(compute: () => void | (() => void), options?: SignalOptions<undefined>);
31
+ _notify(state: number, skipQueue?: boolean): void;
32
+ _disposeNode(): void;
33
+ _run(type: number): void;
34
+ }
27
35
  export declare class EagerComputation<T = any> extends Computation<T> {
28
36
  constructor(initialValue: T, compute: () => T, options?: SignalOptions<T> & {
29
37
  defer?: boolean;
@@ -1,6 +1,6 @@
1
1
  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
- export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
3
+ export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flush, Queue, incrementClock, transition, ActiveTransition, type IQueue } from "./scheduler.js";
6
6
  export * from "./constants.js";
@@ -79,7 +79,7 @@ export declare class Transition implements IQueue {
79
79
  * @description https://docs.solidjs.com/reference/advanced-reactivity/transition
80
80
  */
81
81
  export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any> | Iterable<any>): void;
82
- export declare function cloneGraph(node: Computation): Computation;
82
+ export declare function cloneGraph(node: Computation, optimistic?: boolean): Computation;
83
83
  export declare function getOGSource<T extends Computation>(input: T): T;
84
84
  export declare function getTransitionSource<T extends Computation>(input: T): T;
85
85
  export declare function getQueue(node: Computation): IQueue;
@@ -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, transition, 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, 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";
@@ -1,6 +1,5 @@
1
1
  import type { SignalOptions } from "./core/index.js";
2
2
  import { Owner } from "./core/index.js";
3
- import { type Store, type StoreSetter } from "./store/index.js";
4
3
  export type Accessor<T> = () => T;
5
4
  export type Setter<in out T> = {
6
5
  <U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
@@ -124,6 +123,34 @@ export declare function createEffect<Next, Init = Next>(compute: ComputeFunction
124
123
  */
125
124
  export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
126
125
  export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
126
+ /**
127
+ * Creates a tracked reactive effect that only tracks dependencies inside the effect itself
128
+ * ```typescript
129
+ * export function createTrackedEffect(
130
+ * compute: () => (() => void) | void,
131
+ * options?: { name?: string, defer?: boolean }
132
+ * ): void;
133
+ * ```
134
+ * @param compute a function that contains reactive reads to track and returns an optional cleanup function to run on disposal or before next execution
135
+ * @param options allows to set a name in dev mode for debugging purposes
136
+ *
137
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-tracked-effect
138
+ */
139
+ export declare function createTrackedEffect(compute: () => void | (() => void), options?: EffectOptions): void;
140
+ /**
141
+ * Creates a reactive computation that runs after the render phase with flexible tracking
142
+ * ```typescript
143
+ * export function createReaction(
144
+ * onInvalidate: () => void,
145
+ * options?: { name?: string }
146
+ * ): (fn: () => void) => void;
147
+ * ```
148
+ * @param invalidated a function that is called when tracked function is invalidated.
149
+ * @param options allows to set a name in dev mode for debugging purposes
150
+ *
151
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
152
+ */
153
+ export declare function createReaction(effect: EffectFunction<undefined> | EffectBundle<undefined>, options?: EffectOptions): (tracking: () => void) => void;
127
154
  /**
128
155
  * Creates a new non-tracked reactive context with manual disposal
129
156
  *
@@ -147,6 +174,9 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
147
174
  * @param fn a reactive expression to resolve
148
175
  */
149
176
  export declare function resolve<T>(fn: () => T): Promise<T>;
177
+ export declare function createOptimistic<T>(): Signal<T | undefined>;
178
+ export declare function createOptimistic<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
179
+ export declare function createOptimistic<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
150
180
  /** Allows the user to mark a state change as non-urgent.
151
181
  *
152
182
  * @see {@link https://docs.solidjs.com/reference/advanced-reactivity/transition}
@@ -157,24 +187,3 @@ export declare function useTransition(): [
157
187
  get: Accessor<boolean>,
158
188
  start: (fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any> | Iterable<any>) => void
159
189
  ];
160
- /**
161
- * Creates an optimistic store that can be used to optimistically update a value
162
- * and then revert it back to the previous value at end of transition.
163
- * ```typescript
164
- * export function createOptimistic<T>(
165
- * fn: (store: T) => void,
166
- * initial: T,
167
- * options?: { key?: string | ((item: NonNullable<any>) => any); all?: boolean }
168
- * ): [get: Store<T>, set: StoreSetter<T>];
169
- * ```
170
- * @param fn a function that receives the current store and can be used to mutate it directly inside a transition
171
- * @param initial The initial value of the signal.
172
- * @param options Optional signal options.
173
- *
174
- * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
175
- */
176
- export declare function createOptimistic<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
177
- export declare function createOptimistic<T extends object = {}>(fn: (store: T) => void, initial: T | Store<T>, options?: {
178
- key?: string | ((item: NonNullable<any>) => any);
179
- all?: boolean;
180
- }): [get: Store<T>, set: StoreSetter<T>];
@@ -2,5 +2,6 @@ export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./
2
2
  export type { Merge, Omit } from "./utils.js";
3
3
  export { isWrappable, createStore, deep, $TRACK, $PROXY, $TARGET } from "./store.js";
4
4
  export { createProjection } from "./projection.js";
5
+ export { createOptimisticStore } from "./optimistic.js";
5
6
  export { reconcile } from "./reconcile.js";
6
7
  export { snapshot, merge, omit } from "./utils.js";
@@ -0,0 +1,22 @@
1
+ import { type Store, type StoreSetter } from "./store.js";
2
+ /**
3
+ * Creates an optimistic store that can be used to optimistically update a value
4
+ * and then revert it back to the previous value at end of transition.
5
+ * ```typescript
6
+ * export function createOptimistic<T>(
7
+ * fn: (store: T) => void,
8
+ * initial: T,
9
+ * options?: { key?: string | ((item: NonNullable<any>) => any); all?: boolean }
10
+ * ): [get: Store<T>, set: StoreSetter<T>];
11
+ * ```
12
+ * @param fn a function that receives the current store and can be used to mutate it directly inside a transition
13
+ * @param initial The initial value of the signal.
14
+ * @param options Optional signal options.
15
+ *
16
+ * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
17
+ */
18
+ export declare function createOptimisticStore<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
19
+ export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => T | void, initial: T | Store<T>, options?: {
20
+ key?: string | ((item: NonNullable<any>) => any);
21
+ all?: boolean;
22
+ }): [get: Store<T>, set: StoreSetter<T>];
@@ -1,7 +1,12 @@
1
+ import { FirewallComputation } from "../core/effect.js";
1
2
  import { type Store, type StoreOptions } from "./store.js";
3
+ export declare function createProjectionInternal<T extends object = {}>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): {
4
+ store: Readonly<T>;
5
+ node: FirewallComputation;
6
+ };
2
7
  /**
3
8
  * Creates a mutable derived value
4
9
  *
5
10
  * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
6
11
  */
7
- export declare function createProjection<T extends Object>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): Store<T>;
12
+ export declare function createProjection<T extends Object = {}>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): Store<T>;
@@ -32,6 +32,6 @@ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>,
32
32
  export declare const storeTraps: ProxyHandler<StoreNode>;
33
33
  export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
34
34
  export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
35
- export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>, options?: StoreOptions): [get: Store<T>, set: StoreSetter<T>];
35
+ export declare function createStore<T extends object = {}>(fn: (store: T) => void | T, store: T | Store<T>, options?: StoreOptions): [get: Store<T>, set: StoreSetter<T>];
36
36
  export declare function deep<T extends object>(store: Store<T>): Store<T>;
37
37
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",