floppy-disk 3.4.0 → 3.5.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.
- package/esm/react/create-mutation.d.mts +1 -1
- package/esm/react/create-query.d.mts +5 -3
- package/esm/react/create-store.d.mts +1 -1
- package/esm/react/create-stores.d.mts +7 -2
- package/esm/react/use-mutation.d.mts +1 -1
- package/esm/react.mjs +2 -1
- package/package.json +3 -2
- package/react/create-mutation.d.ts +1 -1
- package/react/create-query.d.ts +5 -3
- package/react/create-store.d.ts +1 -1
- package/react/create-stores.d.ts +7 -2
- package/react/use-mutation.d.ts +1 -1
- package/react.js +2 -1
|
@@ -105,7 +105,7 @@ export type MutationOptions<TData, TVariable, TError = Error> = InitStoreOptions
|
|
|
105
105
|
* const { isPending } = useCreateUser();
|
|
106
106
|
* const result = await useCreateUser.execute({ name: 'John' });
|
|
107
107
|
*
|
|
108
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
108
|
+
* @see https://floppy-disk.vercel.app/docs/mutation
|
|
109
109
|
*/
|
|
110
110
|
export declare const createMutation: <TData, TVariable = undefined, TError = Error>(mutationFn: (variable: TVariable, stateBeforeExecute: MutationState<TData, TVariable, TError>) => Promise<TData>, options?: MutationOptions<TData, TVariable, TError>) => (() => MutationState<TData, TVariable, TError>) & {
|
|
111
111
|
subscribe: (subscriber: import("../vanilla.d.mts").Subscriber<MutationState<TData, TVariable, TError>>) => () => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InitStoreOptions, type SetState } from "../vanilla.mjs";
|
|
2
|
+
import type { StoreKey } from "./create-stores.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Represents the state of a query.
|
|
4
5
|
*
|
|
@@ -68,7 +69,7 @@ export type QueryState<TData, TError> = {
|
|
|
68
69
|
* @remarks
|
|
69
70
|
* Controls caching, retry behavior, lifecycle, and side effects of an async operation.
|
|
70
71
|
*/
|
|
71
|
-
export type QueryOptions<TData, TVariable extends
|
|
72
|
+
export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
|
|
72
73
|
variableHash: string;
|
|
73
74
|
}> & {
|
|
74
75
|
/**
|
|
@@ -164,9 +165,9 @@ export type QueryOptions<TData, TVariable extends Record<string, any>, TError =
|
|
|
164
165
|
* // ...
|
|
165
166
|
* }
|
|
166
167
|
*
|
|
167
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
168
|
+
* @see https://floppy-disk.vercel.app/docs/query
|
|
168
169
|
*/
|
|
169
|
-
export declare const createQuery: <TData, TVariable extends
|
|
170
|
+
export declare const createQuery: <TData, TVariable extends StoreKey = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
|
|
170
171
|
/**
|
|
171
172
|
* Whether the query should be ravalidated automatically on mount.
|
|
172
173
|
*
|
|
@@ -218,6 +219,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
|
|
|
218
219
|
initialData?: never;
|
|
219
220
|
initialDataIsStale?: never;
|
|
220
221
|
})) => QueryState<TData, TError>) & {
|
|
222
|
+
variableHash: string;
|
|
221
223
|
/**
|
|
222
224
|
* Internal data, do not mutate!
|
|
223
225
|
*/
|
|
@@ -25,7 +25,7 @@ import { type InitStoreOptions } from "../vanilla.mjs";
|
|
|
25
25
|
*
|
|
26
26
|
* useMyStore.setState({ foo: 2 }); // only components using foo will re-render
|
|
27
27
|
*
|
|
28
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
28
|
+
* @see https://floppy-disk.vercel.app/docs/store
|
|
29
29
|
*/
|
|
30
30
|
export declare const createStore: <TState extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState>) => ((options?: {
|
|
31
31
|
/**
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type InitStoreOptions } from "../vanilla.mjs";
|
|
2
|
+
type GoodInputForHash = string | number | boolean | null | Date;
|
|
3
|
+
export type StoreKey = GoodInputForHash | {
|
|
4
|
+
[key: string | number]: StoreKey | StoreKey[];
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Creates a factory for multiple stores identified by a key.
|
|
4
8
|
*
|
|
@@ -30,9 +34,9 @@ import { type InitStoreOptions } from "../vanilla.mjs";
|
|
|
30
34
|
* return <div>{state.name}</div>;
|
|
31
35
|
* }
|
|
32
36
|
*
|
|
33
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/stores
|
|
34
38
|
*/
|
|
35
|
-
export declare const createStores: <TState extends Record<string, any>, TKey extends
|
|
39
|
+
export declare const createStores: <TState extends Record<string, any>, TKey extends StoreKey>(initialState: TState, options?: InitStoreOptions<TState, {
|
|
36
40
|
key: TKey;
|
|
37
41
|
keyHash: string;
|
|
38
42
|
}>) => (key?: TKey) => ((options?: {
|
|
@@ -51,3 +55,4 @@ export declare const createStores: <TState extends Record<string, any>, TKey ext
|
|
|
51
55
|
key: TKey;
|
|
52
56
|
keyHash: string;
|
|
53
57
|
};
|
|
58
|
+
export {};
|
|
@@ -21,7 +21,7 @@ import { type MutationOptions, type MutationState } from "./create-mutation.mjs"
|
|
|
21
21
|
* - Only the latest execution is allowed to update the state.
|
|
22
22
|
* - Results from previous executions are ignored if a newer one exists.
|
|
23
23
|
*
|
|
24
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
24
|
+
* @see https://floppy-disk.vercel.app/docs/mutation
|
|
25
25
|
*/
|
|
26
26
|
export declare const useMutation: <TData, TVariable = undefined, TError = Error>(
|
|
27
27
|
/**
|
package/esm/react.mjs
CHANGED
|
@@ -482,7 +482,8 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
482
482
|
console.debug("Manual setState (not via provided actions) on query store");
|
|
483
483
|
store.setState(value);
|
|
484
484
|
},
|
|
485
|
-
...internals.get(store)
|
|
485
|
+
...internals.get(store),
|
|
486
|
+
variableHash
|
|
486
487
|
});
|
|
487
488
|
};
|
|
488
489
|
return Object.assign(getStore, {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "floppy-disk",
|
|
3
3
|
"description": "Lightweight unified state management for sync and async data.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.5.0",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utilities",
|
|
8
8
|
"store",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
+
"packageManager": "pnpm@10.32.1",
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"@types/react": ">=17.0",
|
|
73
74
|
"react": ">=17.0"
|
|
@@ -80,4 +81,4 @@
|
|
|
80
81
|
"optional": true
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
}
|
|
84
|
+
}
|
|
@@ -105,7 +105,7 @@ export type MutationOptions<TData, TVariable, TError = Error> = InitStoreOptions
|
|
|
105
105
|
* const { isPending } = useCreateUser();
|
|
106
106
|
* const result = await useCreateUser.execute({ name: 'John' });
|
|
107
107
|
*
|
|
108
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
108
|
+
* @see https://floppy-disk.vercel.app/docs/mutation
|
|
109
109
|
*/
|
|
110
110
|
export declare const createMutation: <TData, TVariable = undefined, TError = Error>(mutationFn: (variable: TVariable, stateBeforeExecute: MutationState<TData, TVariable, TError>) => Promise<TData>, options?: MutationOptions<TData, TVariable, TError>) => (() => MutationState<TData, TVariable, TError>) & {
|
|
111
111
|
subscribe: (subscriber: import("../vanilla.ts").Subscriber<MutationState<TData, TVariable, TError>>) => () => void;
|
package/react/create-query.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InitStoreOptions, type SetState } from "../vanilla.ts";
|
|
2
|
+
import type { StoreKey } from "./create-stores.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Represents the state of a query.
|
|
4
5
|
*
|
|
@@ -68,7 +69,7 @@ export type QueryState<TData, TError> = {
|
|
|
68
69
|
* @remarks
|
|
69
70
|
* Controls caching, retry behavior, lifecycle, and side effects of an async operation.
|
|
70
71
|
*/
|
|
71
|
-
export type QueryOptions<TData, TVariable extends
|
|
72
|
+
export type QueryOptions<TData, TVariable extends StoreKey, TError = Error> = InitStoreOptions<QueryState<TData, TError>, {
|
|
72
73
|
variableHash: string;
|
|
73
74
|
}> & {
|
|
74
75
|
/**
|
|
@@ -164,9 +165,9 @@ export type QueryOptions<TData, TVariable extends Record<string, any>, TError =
|
|
|
164
165
|
* // ...
|
|
165
166
|
* }
|
|
166
167
|
*
|
|
167
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
168
|
+
* @see https://floppy-disk.vercel.app/docs/query
|
|
168
169
|
*/
|
|
169
|
-
export declare const createQuery: <TData, TVariable extends
|
|
170
|
+
export declare const createQuery: <TData, TVariable extends StoreKey = never, TError = Error>(queryFn: (variable: TVariable, currentState: QueryState<TData, TError>, variableHash: string) => Promise<TData>, options?: QueryOptions<TData, TVariable, TError>) => ((variable?: TVariable) => ((options?: {
|
|
170
171
|
/**
|
|
171
172
|
* Whether the query should be ravalidated automatically on mount.
|
|
172
173
|
*
|
|
@@ -218,6 +219,7 @@ export declare const createQuery: <TData, TVariable extends Record<string, any>
|
|
|
218
219
|
initialData?: never;
|
|
219
220
|
initialDataIsStale?: never;
|
|
220
221
|
})) => QueryState<TData, TError>) & {
|
|
222
|
+
variableHash: string;
|
|
221
223
|
/**
|
|
222
224
|
* Internal data, do not mutate!
|
|
223
225
|
*/
|
package/react/create-store.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { type InitStoreOptions } from "../vanilla.ts";
|
|
|
25
25
|
*
|
|
26
26
|
* useMyStore.setState({ foo: 2 }); // only components using foo will re-render
|
|
27
27
|
*
|
|
28
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
28
|
+
* @see https://floppy-disk.vercel.app/docs/store
|
|
29
29
|
*/
|
|
30
30
|
export declare const createStore: <TState extends Record<string, any>>(initialState: TState, options?: InitStoreOptions<TState>) => ((options?: {
|
|
31
31
|
/**
|
package/react/create-stores.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { type InitStoreOptions } from "../vanilla.ts";
|
|
2
|
+
type GoodInputForHash = string | number | boolean | null | Date;
|
|
3
|
+
export type StoreKey = GoodInputForHash | {
|
|
4
|
+
[key: string | number]: StoreKey | StoreKey[];
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Creates a factory for multiple stores identified by a key.
|
|
4
8
|
*
|
|
@@ -30,9 +34,9 @@ import { type InitStoreOptions } from "../vanilla.ts";
|
|
|
30
34
|
* return <div>{state.name}</div>;
|
|
31
35
|
* }
|
|
32
36
|
*
|
|
33
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/stores
|
|
34
38
|
*/
|
|
35
|
-
export declare const createStores: <TState extends Record<string, any>, TKey extends
|
|
39
|
+
export declare const createStores: <TState extends Record<string, any>, TKey extends StoreKey>(initialState: TState, options?: InitStoreOptions<TState, {
|
|
36
40
|
key: TKey;
|
|
37
41
|
keyHash: string;
|
|
38
42
|
}>) => (key?: TKey) => ((options?: {
|
|
@@ -51,3 +55,4 @@ export declare const createStores: <TState extends Record<string, any>, TKey ext
|
|
|
51
55
|
key: TKey;
|
|
52
56
|
keyHash: string;
|
|
53
57
|
};
|
|
58
|
+
export {};
|
package/react/use-mutation.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { type MutationOptions, type MutationState } from "./create-mutation.ts";
|
|
|
21
21
|
* - Only the latest execution is allowed to update the state.
|
|
22
22
|
* - Results from previous executions are ignored if a newer one exists.
|
|
23
23
|
*
|
|
24
|
-
* @see https://floppy-disk.vercel.app/docs/
|
|
24
|
+
* @see https://floppy-disk.vercel.app/docs/mutation
|
|
25
25
|
*/
|
|
26
26
|
export declare const useMutation: <TData, TVariable = undefined, TError = Error>(
|
|
27
27
|
/**
|
package/react.js
CHANGED
|
@@ -484,7 +484,8 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
484
484
|
console.debug("Manual setState (not via provided actions) on query store");
|
|
485
485
|
store.setState(value);
|
|
486
486
|
},
|
|
487
|
-
...internals.get(store)
|
|
487
|
+
...internals.get(store),
|
|
488
|
+
variableHash
|
|
488
489
|
});
|
|
489
490
|
};
|
|
490
491
|
return Object.assign(getStore, {
|