@solidjs/signals 0.4.11 → 0.6.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.
@@ -78,7 +78,7 @@ export declare class Transition implements IQueue {
78
78
  *
79
79
  * @description https://docs.solidjs.com/reference/advanced-reactivity/transition
80
80
  */
81
- export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any>): void;
81
+ export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any> | Iterable<any>): void;
82
82
  export declare function cloneGraph(node: Computation): 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;
@@ -1,5 +1,6 @@
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";
3
4
  export type Accessor<T> = () => T;
4
5
  export type Setter<in out T> = {
5
6
  <U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
@@ -146,28 +147,34 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
146
147
  * @param fn a reactive expression to resolve
147
148
  */
148
149
  export declare function resolve<T>(fn: () => T): Promise<T>;
149
- /**
150
- * Runs the given function and returns a tuple with the result or an error.
151
- * If the function throws an error, it will be caught and returned as the first element of the tuple.
152
- * If the function returns a promise, it will resolve to a tuple with the result or an error.
150
+ /** Allows the user to mark a state change as non-urgent.
153
151
  *
154
- * @param fn The function to run.
155
- * @returns A tuple with either [undefined, result] or [error].
152
+ * @see {@link https://docs.solidjs.com/reference/advanced-reactivity/transition}
156
153
  *
157
- * @description https://docs.solidjs.com/reference/reactive-utilities/try-catch
154
+ * @returns A tuple containing an accessor for the pending state and a function to start a transition.
158
155
  */
159
- export type TryCatchResult<T, E> = [undefined, T] | [E];
160
- export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
161
- export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
156
+ export declare function useTransition(): [
157
+ get: Accessor<boolean>,
158
+ start: (fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any> | Iterable<any>) => void
159
+ ];
162
160
  /**
163
- * Creates an optimistic signal that can be used to optimistically update a value
161
+ * Creates an optimistic store that can be used to optimistically update a value
164
162
  * and then revert it back to the previous value at end of transition.
165
- *
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
166
171
  * @param initial The initial value of the signal.
167
- * @param compute An optional function to compute the next value based on the previous value and change.
168
172
  * @param options Optional signal options.
169
173
  *
170
174
  * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
171
175
  */
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];
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>];
@@ -1,7 +1,7 @@
1
- import { type Store } from "./store.js";
1
+ import { type Store, type StoreOptions } from "./store.js";
2
2
  /**
3
3
  * Creates a mutable derived value
4
4
  *
5
5
  * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
6
6
  */
7
- export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): Store<T>;
7
+ export declare function createProjection<T extends Object>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): Store<T>;
@@ -1,6 +1,10 @@
1
1
  import { Computation } from "../core/index.js";
2
2
  export type Store<T> = Readonly<T>;
3
- export type StoreSetter<T> = (fn: (state: T) => void) => void;
3
+ export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
4
+ export type StoreOptions = {
5
+ key?: string | ((item: NonNullable<any>) => any);
6
+ all?: boolean;
7
+ };
4
8
  type DataNode = Computation<any>;
5
9
  type DataNodes = Record<PropertyKey, DataNode>;
6
10
  export declare const $TRACK: unique symbol, $DEEP: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
@@ -26,8 +30,8 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
26
30
  export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
27
31
  export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
28
32
  export declare const storeTraps: ProxyHandler<StoreNode>;
29
- export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => void): void;
33
+ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
30
34
  export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
31
- export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
32
- export declare function deep<T extends object>(store: Store<T>): Store<any>;
35
+ export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>, options?: StoreOptions): [get: Store<T>, set: StoreSetter<T>];
36
+ export declare function deep<T extends object>(store: Store<T>): Store<T>;
33
37
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.4.11",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",