@solidjs/signals 0.5.0 → 0.6.1

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;
@@ -147,36 +147,34 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
147
147
  * @param fn a reactive expression to resolve
148
148
  */
149
149
  export declare function resolve<T>(fn: () => T): Promise<T>;
150
- /**
151
- * Runs the given function and returns a tuple with the result or an error.
152
- * If the function throws an error, it will be caught and returned as the first element of the tuple.
153
- * 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.
154
151
  *
155
- * @param fn The function to run.
156
- * @returns A tuple with either [undefined, result] or [error].
152
+ * @see {@link https://docs.solidjs.com/reference/advanced-reactivity/transition}
157
153
  *
158
- * @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.
159
155
  */
160
- export type TryCatchResult<T, E> = [undefined, T] | [E];
161
- export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
162
- 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
+ ];
163
160
  /**
164
- * 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
165
162
  * and then revert it back to the previous value at end of transition.
166
- *
167
- * @param initial The initial value of the signal.
168
- *
169
- * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
170
- */
171
- export declare function createOptimistic<T>(initial: Exclude<T, Function>): Signal<T>;
172
- /**
173
- * Creates an optimistic signal that can be used to optimistically update a value
174
- * and then revert it back to the previous value at end of transition.
175
- *
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
176
171
  * @param initial The initial value of the signal.
177
172
  * @param options Optional signal options.
178
173
  *
179
174
  * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
180
175
  */
181
- export declare function createOptimisticStore<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
182
- export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void, initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
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
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;
@@ -28,6 +32,6 @@ export declare function getPropertyDescriptor(source: Record<PropertyKey, any>,
28
32
  export declare const storeTraps: ProxyHandler<StoreNode>;
29
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.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",