floppy-disk 2.12.1 → 2.12.2-beta.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.
- package/esm/react/create-query.d.ts +12 -3
- package/esm/react/create-store.d.ts +7 -3
- package/esm/react/create-store.js +1 -1
- package/esm/react/create-stores.d.ts +7 -3
- package/esm/react/create-stores.js +1 -1
- package/lib/react/create-query.d.ts +12 -3
- package/lib/react/create-store.d.ts +7 -3
- package/lib/react/create-store.js +1 -1
- package/lib/react/create-stores.d.ts +7 -3
- package/lib/react/create-stores.js +1 -1
- package/package.json +1 -1
|
@@ -39,7 +39,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
39
39
|
*
|
|
40
40
|
* @returns function to revert the changes & function to invalidate the query
|
|
41
41
|
*
|
|
42
|
-
* IMPORTANT NOTE
|
|
42
|
+
* **IMPORTANT NOTE:** This won't work well on infinite query.
|
|
43
43
|
*/
|
|
44
44
|
optimisticUpdate: (response: TResponse | ((prevState: QueryState<TKey, TResponse, TData, TError, TPageParam>) => TResponse)) => {
|
|
45
45
|
revert: () => void;
|
|
@@ -233,11 +233,15 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
233
233
|
};
|
|
234
234
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown, TPageParam = any> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError, TPageParam>> & {
|
|
235
235
|
/**
|
|
236
|
+
* ⚛️ (**_Hook_**)
|
|
237
|
+
*
|
|
236
238
|
* Set query's initial response.
|
|
237
239
|
*
|
|
238
240
|
* This is used for server-side rendered page or static page.
|
|
239
241
|
*
|
|
240
|
-
* IMPORTANT NOTE
|
|
242
|
+
* **IMPORTANT NOTE:**
|
|
243
|
+
* - This is a hook, put it inside of a React component
|
|
244
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
241
245
|
*/
|
|
242
246
|
setInitialResponse: (options: {
|
|
243
247
|
key?: Maybe<TKey>;
|
|
@@ -265,7 +269,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
265
269
|
*
|
|
266
270
|
* @returns function to revert the changes & function to invalidate the query
|
|
267
271
|
*
|
|
268
|
-
* IMPORTANT NOTE
|
|
272
|
+
* **IMPORTANT NOTE:** This won't work well on infinite query.
|
|
269
273
|
*/
|
|
270
274
|
optimisticUpdate: (options: {
|
|
271
275
|
key?: Maybe<TKey>;
|
|
@@ -275,7 +279,12 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
275
279
|
invalidate: () => void;
|
|
276
280
|
};
|
|
277
281
|
/**
|
|
282
|
+
* ⚛️ (**_Hook_**)
|
|
283
|
+
*
|
|
278
284
|
* Use query with suspense mode.
|
|
285
|
+
*
|
|
286
|
+
* **IMPORTANT NOTE:**
|
|
287
|
+
* - This is a hook, put it inside of a React component
|
|
279
288
|
*/
|
|
280
289
|
suspend: (key?: Maybe<TKey>) => Extract<QueryState<TKey, TResponse, TData, TError, TPageParam>, {
|
|
281
290
|
status: 'success';
|
|
@@ -8,7 +8,7 @@ export type UseStore<T extends StoreData> = {
|
|
|
8
8
|
* @param selectDeps A function that return the dependency array (just like in `useEffect`), to trigger reactivity.
|
|
9
9
|
* Defaults to `undefined` (reactive to all state change) if you didn't set `defaultDeps` on `createStore`.
|
|
10
10
|
*
|
|
11
|
-
* IMPORTANT NOTE
|
|
11
|
+
* **IMPORTANT NOTE:** `selectDeps` must not be changed after initialization.
|
|
12
12
|
*/
|
|
13
13
|
(selectDeps?: SelectDeps<T>): T;
|
|
14
14
|
get: () => T;
|
|
@@ -16,9 +16,13 @@ export type UseStore<T extends StoreData> = {
|
|
|
16
16
|
subscribe: (fn: (state: T) => void, selectDeps?: SelectDeps<T>) => () => void;
|
|
17
17
|
getSubscribers: () => Subscribers<T>;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* ⚛️ (**_Hook_**)
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Set default values **inside of a component**.
|
|
22
|
+
*
|
|
23
|
+
* **IMPORTANT NOTE:**
|
|
24
|
+
* - This is a hook, put it inside of a React component
|
|
25
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
22
26
|
*/
|
|
23
27
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
28
|
Watch: (props: WatchProps<T>) => any;
|
|
@@ -7,7 +7,7 @@ export const createStore = (initializer, options = {}) => {
|
|
|
7
7
|
const { get, set, subscribe, getSubscribers } = initStore(initializer, options);
|
|
8
8
|
const { defaultDeps } = options;
|
|
9
9
|
/**
|
|
10
|
-
* IMPORTANT NOTE
|
|
10
|
+
* **IMPORTANT NOTE:** `selectDeps` function must not be changed after initialization.
|
|
11
11
|
*/
|
|
12
12
|
const useStore = (selectDeps = defaultDeps) => {
|
|
13
13
|
const [state, setState] = useState(get);
|
|
@@ -15,7 +15,7 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
15
15
|
* @param selectDeps A function that return the dependency array (just like in `useEffect`), to trigger reactivity.
|
|
16
16
|
* Defaults to `undefined` (reactive to all state change) if you didn't set `defaultDeps` on `createStores`.
|
|
17
17
|
*
|
|
18
|
-
* IMPORTANT NOTE
|
|
18
|
+
* **IMPORTANT NOTE:** `selectDeps` must not be changed after initialization.
|
|
19
19
|
*/
|
|
20
20
|
(...args: [Maybe<TKey>, SelectDeps<T>?] | [SelectDeps<T>?]): T;
|
|
21
21
|
get: (key?: Maybe<TKey>) => T;
|
|
@@ -28,9 +28,13 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
28
28
|
getStore: (key?: Maybe<TKey>) => InitStoreReturn<T>;
|
|
29
29
|
getStores: () => Map<string, InitStoreReturn<T>>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* ⚛️ (**_Hook_**)
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* Set default values **inside of a component**.
|
|
34
|
+
*
|
|
35
|
+
* **IMPORTANT NOTE:**
|
|
36
|
+
* - This is a hook, put it inside of a React component
|
|
37
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
34
38
|
*/
|
|
35
39
|
setDefaultValues: (key: Maybe<TKey>, values: SetStoreData<T>) => void;
|
|
36
40
|
Watch: (props: WatchProps<T> & {
|
|
@@ -17,7 +17,7 @@ export const createStores = (initializer, options = {}) => {
|
|
|
17
17
|
return stores.get(keyHash);
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
|
-
* IMPORTANT NOTE
|
|
20
|
+
* **IMPORTANT NOTE:** `selectDeps` function must not be changed after initialization.
|
|
21
21
|
*/
|
|
22
22
|
const useStores = (...args) => {
|
|
23
23
|
const [_key, selectDeps = defaultDeps] = (typeof args[0] === 'function' ? [{}, args[0]] : args);
|
|
@@ -39,7 +39,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
|
|
|
39
39
|
*
|
|
40
40
|
* @returns function to revert the changes & function to invalidate the query
|
|
41
41
|
*
|
|
42
|
-
* IMPORTANT NOTE
|
|
42
|
+
* **IMPORTANT NOTE:** This won't work well on infinite query.
|
|
43
43
|
*/
|
|
44
44
|
optimisticUpdate: (response: TResponse | ((prevState: QueryState<TKey, TResponse, TData, TError, TPageParam>) => TResponse)) => {
|
|
45
45
|
revert: () => void;
|
|
@@ -233,11 +233,15 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
233
233
|
};
|
|
234
234
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown, TPageParam = any> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError, TPageParam>> & {
|
|
235
235
|
/**
|
|
236
|
+
* ⚛️ (**_Hook_**)
|
|
237
|
+
*
|
|
236
238
|
* Set query's initial response.
|
|
237
239
|
*
|
|
238
240
|
* This is used for server-side rendered page or static page.
|
|
239
241
|
*
|
|
240
|
-
* IMPORTANT NOTE
|
|
242
|
+
* **IMPORTANT NOTE:**
|
|
243
|
+
* - This is a hook, put it inside of a React component
|
|
244
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
241
245
|
*/
|
|
242
246
|
setInitialResponse: (options: {
|
|
243
247
|
key?: Maybe<TKey>;
|
|
@@ -265,7 +269,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
265
269
|
*
|
|
266
270
|
* @returns function to revert the changes & function to invalidate the query
|
|
267
271
|
*
|
|
268
|
-
* IMPORTANT NOTE
|
|
272
|
+
* **IMPORTANT NOTE:** This won't work well on infinite query.
|
|
269
273
|
*/
|
|
270
274
|
optimisticUpdate: (options: {
|
|
271
275
|
key?: Maybe<TKey>;
|
|
@@ -275,7 +279,12 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
275
279
|
invalidate: () => void;
|
|
276
280
|
};
|
|
277
281
|
/**
|
|
282
|
+
* ⚛️ (**_Hook_**)
|
|
283
|
+
*
|
|
278
284
|
* Use query with suspense mode.
|
|
285
|
+
*
|
|
286
|
+
* **IMPORTANT NOTE:**
|
|
287
|
+
* - This is a hook, put it inside of a React component
|
|
279
288
|
*/
|
|
280
289
|
suspend: (key?: Maybe<TKey>) => Extract<QueryState<TKey, TResponse, TData, TError, TPageParam>, {
|
|
281
290
|
status: 'success';
|
|
@@ -8,7 +8,7 @@ export type UseStore<T extends StoreData> = {
|
|
|
8
8
|
* @param selectDeps A function that return the dependency array (just like in `useEffect`), to trigger reactivity.
|
|
9
9
|
* Defaults to `undefined` (reactive to all state change) if you didn't set `defaultDeps` on `createStore`.
|
|
10
10
|
*
|
|
11
|
-
* IMPORTANT NOTE
|
|
11
|
+
* **IMPORTANT NOTE:** `selectDeps` must not be changed after initialization.
|
|
12
12
|
*/
|
|
13
13
|
(selectDeps?: SelectDeps<T>): T;
|
|
14
14
|
get: () => T;
|
|
@@ -16,9 +16,13 @@ export type UseStore<T extends StoreData> = {
|
|
|
16
16
|
subscribe: (fn: (state: T) => void, selectDeps?: SelectDeps<T>) => () => void;
|
|
17
17
|
getSubscribers: () => Subscribers<T>;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* ⚛️ (**_Hook_**)
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Set default values **inside of a component**.
|
|
22
|
+
*
|
|
23
|
+
* **IMPORTANT NOTE:**
|
|
24
|
+
* - This is a hook, put it inside of a React component
|
|
25
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
22
26
|
*/
|
|
23
27
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
28
|
Watch: (props: WatchProps<T>) => any;
|
|
@@ -10,7 +10,7 @@ const createStore = (initializer, options = {}) => {
|
|
|
10
10
|
const { get, set, subscribe, getSubscribers } = (0, vanilla_1.initStore)(initializer, options);
|
|
11
11
|
const { defaultDeps } = options;
|
|
12
12
|
/**
|
|
13
|
-
* IMPORTANT NOTE
|
|
13
|
+
* **IMPORTANT NOTE:** `selectDeps` function must not be changed after initialization.
|
|
14
14
|
*/
|
|
15
15
|
const useStore = (selectDeps = defaultDeps) => {
|
|
16
16
|
const [state, setState] = (0, react_1.useState)(get);
|
|
@@ -15,7 +15,7 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
15
15
|
* @param selectDeps A function that return the dependency array (just like in `useEffect`), to trigger reactivity.
|
|
16
16
|
* Defaults to `undefined` (reactive to all state change) if you didn't set `defaultDeps` on `createStores`.
|
|
17
17
|
*
|
|
18
|
-
* IMPORTANT NOTE
|
|
18
|
+
* **IMPORTANT NOTE:** `selectDeps` must not be changed after initialization.
|
|
19
19
|
*/
|
|
20
20
|
(...args: [Maybe<TKey>, SelectDeps<T>?] | [SelectDeps<T>?]): T;
|
|
21
21
|
get: (key?: Maybe<TKey>) => T;
|
|
@@ -28,9 +28,13 @@ export type UseStores<TKey extends StoreKey = StoreKey, T extends StoreData = St
|
|
|
28
28
|
getStore: (key?: Maybe<TKey>) => InitStoreReturn<T>;
|
|
29
29
|
getStores: () => Map<string, InitStoreReturn<T>>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* ⚛️ (**_Hook_**)
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* Set default values **inside of a component**.
|
|
34
|
+
*
|
|
35
|
+
* **IMPORTANT NOTE:**
|
|
36
|
+
* - This is a hook, put it inside of a React component
|
|
37
|
+
* - Put this on the root component or parent component, before any component subscribed!
|
|
34
38
|
*/
|
|
35
39
|
setDefaultValues: (key: Maybe<TKey>, values: SetStoreData<T>) => void;
|
|
36
40
|
Watch: (props: WatchProps<T> & {
|
|
@@ -20,7 +20,7 @@ const createStores = (initializer, options = {}) => {
|
|
|
20
20
|
return stores.get(keyHash);
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
|
-
* IMPORTANT NOTE
|
|
23
|
+
* **IMPORTANT NOTE:** `selectDeps` function must not be changed after initialization.
|
|
24
24
|
*/
|
|
25
25
|
const useStores = (...args) => {
|
|
26
26
|
const [_key, selectDeps = defaultDeps] = (typeof args[0] === 'function' ? [{}, args[0]] : args);
|