floppy-disk 2.4.0-beta.2 → 2.4.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/preact/create-mutation.d.ts +3 -0
- package/esm/preact/create-mutation.js +3 -0
- package/esm/preact/create-query.d.ts +7 -2
- package/esm/preact/create-query.js +9 -4
- package/esm/preact/create-store.d.ts +3 -0
- package/esm/preact/create-store.js +3 -0
- package/esm/preact/create-stores.d.ts +3 -0
- package/esm/preact/create-stores.js +3 -0
- package/esm/react/create-mutation.d.ts +3 -0
- package/esm/react/create-mutation.js +3 -0
- package/esm/react/create-query.d.ts +7 -2
- package/esm/react/create-query.js +9 -4
- package/esm/react/create-store.d.ts +3 -0
- package/esm/react/create-store.js +3 -0
- package/esm/react/create-stores.d.ts +3 -0
- package/esm/react/create-stores.js +3 -0
- package/lib/preact/create-mutation.d.ts +3 -0
- package/lib/preact/create-mutation.js +3 -0
- package/lib/preact/create-query.d.ts +7 -2
- package/lib/preact/create-query.js +9 -4
- package/lib/preact/create-store.d.ts +3 -0
- package/lib/preact/create-store.js +3 -0
- package/lib/preact/create-stores.d.ts +3 -0
- package/lib/preact/create-stores.js +3 -0
- package/lib/react/create-mutation.d.ts +3 -0
- package/lib/react/create-mutation.js +3 -0
- package/lib/react/create-query.d.ts +7 -2
- package/lib/react/create-query.js +9 -4
- package/lib/react/create-store.d.ts +3 -0
- package/lib/react/create-store.js +3 -0
- package/lib/react/create-stores.d.ts +3 -0
- package/lib/react/create-stores.js +3 -0
- package/package.json +1 -1
|
@@ -33,4 +33,7 @@ export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = Ini
|
|
|
33
33
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
34
34
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
38
|
+
*/
|
|
36
39
|
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { noop } from '../utils';
|
|
2
2
|
import { createStore } from './create-store';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
5
|
+
*/
|
|
3
6
|
export const createMutation = (mutationFn, options = {}) => {
|
|
4
7
|
const { onMutate = noop, onSuccess = noop, onError = noop, onSettled = noop, ...createStoreOptions } = options;
|
|
5
8
|
const useMutation = createStore(({ set, get }) => ({
|
|
@@ -198,9 +198,11 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
198
198
|
*
|
|
199
199
|
* Disabled by default.
|
|
200
200
|
*
|
|
201
|
-
* If
|
|
201
|
+
* If last data fetching is failed, the polling interval will be disabled, and it will use `retry` mechanism instead.
|
|
202
|
+
*
|
|
203
|
+
* @see https://floppy-disk.vercel.app/docs/query/polling
|
|
202
204
|
*/
|
|
203
|
-
refetchInterval?: number | false | (() => number | false);
|
|
205
|
+
refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
|
|
204
206
|
};
|
|
205
207
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
206
208
|
/**
|
|
@@ -258,4 +260,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
258
260
|
error?: FunctionComponent<TKey>;
|
|
259
261
|
}) => JSX.Element;
|
|
260
262
|
};
|
|
263
|
+
/**
|
|
264
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
265
|
+
*/
|
|
261
266
|
export declare const createQuery: <TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown>(queryFn: (key: TKey, state: QueryState<TKey, TResponse, TData, TError>) => Promise<TResponse>, options?: CreateQueryOptions<TKey, TResponse, TData, TError>) => UseQuery<TKey, TResponse, TData, TError>;
|
|
@@ -32,6 +32,9 @@ const useQueryDefaultDeps = (state) => [
|
|
|
32
32
|
state.isWaitingNextPage,
|
|
33
33
|
state.hasNextPage,
|
|
34
34
|
];
|
|
35
|
+
/**
|
|
36
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
37
|
+
*/
|
|
35
38
|
export const createQuery = (queryFn, options = {}) => {
|
|
36
39
|
const defaultFetchOnWindowFocus = options.fetchOnMount ?? true;
|
|
37
40
|
const { onFirstSubscribe = noop, onSubscribe = noop, onLastUnsubscribe = noop, onBeforeChangeKey = noop, defaultDeps = useQueryDefaultDeps, select = identityFn, staleTime = 3000, // 3 seconds
|
|
@@ -94,7 +97,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
94
97
|
callQuery();
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
const nextState = {
|
|
98
101
|
isWaiting: false,
|
|
99
102
|
status: 'success',
|
|
100
103
|
isLoading: false,
|
|
@@ -115,13 +118,15 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
115
118
|
pageParam: newPageParam,
|
|
116
119
|
pageParams: newPageParams,
|
|
117
120
|
hasNextPage: hasValue(newPageParam),
|
|
118
|
-
}
|
|
119
|
-
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
121
|
+
};
|
|
122
|
+
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
123
|
+
getValueOrComputedValue(refetchInterval, { ...get(), ...nextState });
|
|
120
124
|
if (refetchIntervalValue) {
|
|
121
125
|
refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
122
126
|
forceFetch();
|
|
123
127
|
}, refetchIntervalValue));
|
|
124
128
|
}
|
|
129
|
+
set(nextState);
|
|
125
130
|
onSuccess(response, stateBeforeCallQuery);
|
|
126
131
|
resolve(get());
|
|
127
132
|
})
|
|
@@ -247,7 +252,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
247
252
|
defaultDeps,
|
|
248
253
|
onFirstSubscribe: (state) => {
|
|
249
254
|
if (state.isSuccess) {
|
|
250
|
-
const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
|
|
255
|
+
const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval, state);
|
|
251
256
|
if (refetchIntervalValue) {
|
|
252
257
|
refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
|
|
253
258
|
state.forceFetch();
|
|
@@ -23,6 +23,9 @@ export type UseStore<T extends StoreData> = {
|
|
|
23
23
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
24
|
Watch: (props: WatchProps<T>) => any;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
28
|
+
*/
|
|
26
29
|
export declare const createStore: <T extends StoreData>(initializer: StoreInitializer<T>, options?: InitStoreOptions<T> & {
|
|
27
30
|
defaultDeps?: SelectDeps<T>;
|
|
28
31
|
}) => UseStore<T>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { useEffect, useState } from 'preact/hooks';
|
|
2
2
|
import { initStore, } from '../vanilla';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
5
|
+
*/
|
|
3
6
|
export const createStore = (initializer, options = {}) => {
|
|
4
7
|
const { get, set, subscribe, getSubscribers } = initStore(initializer, options);
|
|
5
8
|
const { defaultDeps } = options;
|
|
@@ -46,5 +46,8 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
46
46
|
defaultDeps?: SelectDeps<T>;
|
|
47
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
51
|
+
*/
|
|
49
52
|
export declare const createStores: <TKey extends StoreKey = StoreKey, T extends StoreData = StoreData>(initializer: StoresInitializer<TKey, T>, options?: CreateStoresOptions<TKey, T>) => UseStores<TKey, T>;
|
|
50
53
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
2
2
|
import { hashStoreKey, noop } from '../utils';
|
|
3
3
|
import { initStore, } from '../vanilla';
|
|
4
|
+
/**
|
|
5
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
6
|
+
*/
|
|
4
7
|
export const createStores = (initializer, options = {}) => {
|
|
5
8
|
const { onBeforeChangeKey = noop, onStoreInitialized = noop, defaultDeps, hashKeyFn = hashStoreKey, } = options;
|
|
6
9
|
const stores = new Map();
|
|
@@ -33,4 +33,7 @@ export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = Ini
|
|
|
33
33
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
34
34
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
38
|
+
*/
|
|
36
39
|
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { noop } from '../utils';
|
|
2
2
|
import { createStore } from './create-store';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
5
|
+
*/
|
|
3
6
|
export const createMutation = (mutationFn, options = {}) => {
|
|
4
7
|
const { onMutate = noop, onSuccess = noop, onError = noop, onSettled = noop, ...createStoreOptions } = options;
|
|
5
8
|
const useMutation = createStore(({ set, get }) => ({
|
|
@@ -197,9 +197,11 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
197
197
|
*
|
|
198
198
|
* Disabled by default.
|
|
199
199
|
*
|
|
200
|
-
* If
|
|
200
|
+
* If last data fetching is failed, the polling interval will be disabled, and it will use `retry` mechanism instead.
|
|
201
|
+
*
|
|
202
|
+
* @see https://floppy-disk.vercel.app/docs/query/polling
|
|
201
203
|
*/
|
|
202
|
-
refetchInterval?: number | false | (() => number | false);
|
|
204
|
+
refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
|
|
203
205
|
};
|
|
204
206
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
205
207
|
/**
|
|
@@ -257,4 +259,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
257
259
|
error?: FunctionComponent<TKey>;
|
|
258
260
|
}) => JSX.Element;
|
|
259
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
264
|
+
*/
|
|
260
265
|
export declare const createQuery: <TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown>(queryFn: (key: TKey, state: QueryState<TKey, TResponse, TData, TError>) => Promise<TResponse>, options?: CreateQueryOptions<TKey, TResponse, TData, TError>) => UseQuery<TKey, TResponse, TData, TError>;
|
|
@@ -31,6 +31,9 @@ const useQueryDefaultDeps = (state) => [
|
|
|
31
31
|
state.isWaitingNextPage,
|
|
32
32
|
state.hasNextPage,
|
|
33
33
|
];
|
|
34
|
+
/**
|
|
35
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
36
|
+
*/
|
|
34
37
|
export const createQuery = (queryFn, options = {}) => {
|
|
35
38
|
const defaultFetchOnWindowFocus = options.fetchOnMount ?? true;
|
|
36
39
|
const { onFirstSubscribe = noop, onSubscribe = noop, onLastUnsubscribe = noop, onBeforeChangeKey = noop, defaultDeps = useQueryDefaultDeps, select = identityFn, staleTime = 3000, // 3 seconds
|
|
@@ -93,7 +96,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
93
96
|
callQuery();
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
96
|
-
|
|
99
|
+
const nextState = {
|
|
97
100
|
isWaiting: false,
|
|
98
101
|
status: 'success',
|
|
99
102
|
isLoading: false,
|
|
@@ -114,13 +117,15 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
114
117
|
pageParam: newPageParam,
|
|
115
118
|
pageParams: newPageParams,
|
|
116
119
|
hasNextPage: hasValue(newPageParam),
|
|
117
|
-
}
|
|
118
|
-
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
120
|
+
};
|
|
121
|
+
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
122
|
+
getValueOrComputedValue(refetchInterval, { ...get(), ...nextState });
|
|
119
123
|
if (refetchIntervalValue) {
|
|
120
124
|
refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
121
125
|
forceFetch();
|
|
122
126
|
}, refetchIntervalValue));
|
|
123
127
|
}
|
|
128
|
+
set(nextState);
|
|
124
129
|
onSuccess(response, stateBeforeCallQuery);
|
|
125
130
|
resolve(get());
|
|
126
131
|
})
|
|
@@ -246,7 +251,7 @@ export const createQuery = (queryFn, options = {}) => {
|
|
|
246
251
|
defaultDeps,
|
|
247
252
|
onFirstSubscribe: (state) => {
|
|
248
253
|
if (state.isSuccess) {
|
|
249
|
-
const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
|
|
254
|
+
const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval, state);
|
|
250
255
|
if (refetchIntervalValue) {
|
|
251
256
|
refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
|
|
252
257
|
state.forceFetch();
|
|
@@ -23,6 +23,9 @@ export type UseStore<T extends StoreData> = {
|
|
|
23
23
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
24
|
Watch: (props: WatchProps<T>) => any;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
28
|
+
*/
|
|
26
29
|
export declare const createStore: <T extends StoreData>(initializer: StoreInitializer<T>, options?: InitStoreOptions<T> & {
|
|
27
30
|
defaultDeps?: SelectDeps<T>;
|
|
28
31
|
}) => UseStore<T>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { initStore, } from '../vanilla';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
5
|
+
*/
|
|
3
6
|
export const createStore = (initializer, options = {}) => {
|
|
4
7
|
const { get, set, subscribe, getSubscribers } = initStore(initializer, options);
|
|
5
8
|
const { defaultDeps } = options;
|
|
@@ -46,5 +46,8 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
46
46
|
defaultDeps?: SelectDeps<T>;
|
|
47
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
51
|
+
*/
|
|
49
52
|
export declare const createStores: <TKey extends StoreKey = StoreKey, T extends StoreData = StoreData>(initializer: StoresInitializer<TKey, T>, options?: CreateStoresOptions<TKey, T>) => UseStores<TKey, T>;
|
|
50
53
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { hashStoreKey, noop } from '../utils';
|
|
3
3
|
import { initStore, } from '../vanilla';
|
|
4
|
+
/**
|
|
5
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
6
|
+
*/
|
|
4
7
|
export const createStores = (initializer, options = {}) => {
|
|
5
8
|
const { onBeforeChangeKey = noop, onStoreInitialized = noop, defaultDeps, hashKeyFn = hashStoreKey, } = options;
|
|
6
9
|
const stores = new Map();
|
|
@@ -33,4 +33,7 @@ export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = Ini
|
|
|
33
33
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
34
34
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
38
|
+
*/
|
|
36
39
|
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createMutation = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const create_store_1 = require("./create-store");
|
|
6
|
+
/**
|
|
7
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
8
|
+
*/
|
|
6
9
|
const createMutation = (mutationFn, options = {}) => {
|
|
7
10
|
const { onMutate = utils_1.noop, onSuccess = utils_1.noop, onError = utils_1.noop, onSettled = utils_1.noop, ...createStoreOptions } = options;
|
|
8
11
|
const useMutation = (0, create_store_1.createStore)(({ set, get }) => ({
|
|
@@ -198,9 +198,11 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
198
198
|
*
|
|
199
199
|
* Disabled by default.
|
|
200
200
|
*
|
|
201
|
-
* If
|
|
201
|
+
* If last data fetching is failed, the polling interval will be disabled, and it will use `retry` mechanism instead.
|
|
202
|
+
*
|
|
203
|
+
* @see https://floppy-disk.vercel.app/docs/query/polling
|
|
202
204
|
*/
|
|
203
|
-
refetchInterval?: number | false | (() => number | false);
|
|
205
|
+
refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
|
|
204
206
|
};
|
|
205
207
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
206
208
|
/**
|
|
@@ -258,4 +260,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
258
260
|
error?: FunctionComponent<TKey>;
|
|
259
261
|
}) => JSX.Element;
|
|
260
262
|
};
|
|
263
|
+
/**
|
|
264
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
265
|
+
*/
|
|
261
266
|
export declare const createQuery: <TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown>(queryFn: (key: TKey, state: QueryState<TKey, TResponse, TData, TError>) => Promise<TResponse>, options?: CreateQueryOptions<TKey, TResponse, TData, TError>) => UseQuery<TKey, TResponse, TData, TError>;
|
|
@@ -35,6 +35,9 @@ const useQueryDefaultDeps = (state) => [
|
|
|
35
35
|
state.isWaitingNextPage,
|
|
36
36
|
state.hasNextPage,
|
|
37
37
|
];
|
|
38
|
+
/**
|
|
39
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
40
|
+
*/
|
|
38
41
|
const createQuery = (queryFn, options = {}) => {
|
|
39
42
|
const defaultFetchOnWindowFocus = options.fetchOnMount ?? true;
|
|
40
43
|
const { onFirstSubscribe = utils_1.noop, onSubscribe = utils_1.noop, onLastUnsubscribe = utils_1.noop, onBeforeChangeKey = utils_1.noop, defaultDeps = useQueryDefaultDeps, select = utils_1.identityFn, staleTime = 3000, // 3 seconds
|
|
@@ -97,7 +100,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
97
100
|
callQuery();
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
|
-
|
|
103
|
+
const nextState = {
|
|
101
104
|
isWaiting: false,
|
|
102
105
|
status: 'success',
|
|
103
106
|
isLoading: false,
|
|
@@ -118,13 +121,15 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
118
121
|
pageParam: newPageParam,
|
|
119
122
|
pageParams: newPageParams,
|
|
120
123
|
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
121
|
-
}
|
|
122
|
-
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
124
|
+
};
|
|
125
|
+
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
126
|
+
(0, utils_1.getValueOrComputedValue)(refetchInterval, { ...get(), ...nextState });
|
|
123
127
|
if (refetchIntervalValue) {
|
|
124
128
|
refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
125
129
|
forceFetch();
|
|
126
130
|
}, refetchIntervalValue));
|
|
127
131
|
}
|
|
132
|
+
set(nextState);
|
|
128
133
|
onSuccess(response, stateBeforeCallQuery);
|
|
129
134
|
resolve(get());
|
|
130
135
|
})
|
|
@@ -250,7 +255,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
250
255
|
defaultDeps,
|
|
251
256
|
onFirstSubscribe: (state) => {
|
|
252
257
|
if (state.isSuccess) {
|
|
253
|
-
const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
|
|
258
|
+
const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval, state);
|
|
254
259
|
if (refetchIntervalValue) {
|
|
255
260
|
refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
|
|
256
261
|
state.forceFetch();
|
|
@@ -23,6 +23,9 @@ export type UseStore<T extends StoreData> = {
|
|
|
23
23
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
24
|
Watch: (props: WatchProps<T>) => any;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
28
|
+
*/
|
|
26
29
|
export declare const createStore: <T extends StoreData>(initializer: StoreInitializer<T>, options?: InitStoreOptions<T> & {
|
|
27
30
|
defaultDeps?: SelectDeps<T>;
|
|
28
31
|
}) => UseStore<T>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createStore = void 0;
|
|
4
4
|
const hooks_1 = require("preact/hooks");
|
|
5
5
|
const vanilla_1 = require("../vanilla");
|
|
6
|
+
/**
|
|
7
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
8
|
+
*/
|
|
6
9
|
const createStore = (initializer, options = {}) => {
|
|
7
10
|
const { get, set, subscribe, getSubscribers } = (0, vanilla_1.initStore)(initializer, options);
|
|
8
11
|
const { defaultDeps } = options;
|
|
@@ -46,5 +46,8 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
46
46
|
defaultDeps?: SelectDeps<T>;
|
|
47
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
51
|
+
*/
|
|
49
52
|
export declare const createStores: <TKey extends StoreKey = StoreKey, T extends StoreData = StoreData>(initializer: StoresInitializer<TKey, T>, options?: CreateStoresOptions<TKey, T>) => UseStores<TKey, T>;
|
|
50
53
|
export {};
|
|
@@ -4,6 +4,9 @@ exports.createStores = void 0;
|
|
|
4
4
|
const hooks_1 = require("preact/hooks");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const vanilla_1 = require("../vanilla");
|
|
7
|
+
/**
|
|
8
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
9
|
+
*/
|
|
7
10
|
const createStores = (initializer, options = {}) => {
|
|
8
11
|
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey, } = options;
|
|
9
12
|
const stores = new Map();
|
|
@@ -33,4 +33,7 @@ export type CreateMutationOptions<TVar, TResponse = any, TError = unknown> = Ini
|
|
|
33
33
|
onError?: (error: TError, variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
34
34
|
onSettled?: (variables: TVar, stateBeforeMutate: MutationState<TVar, TResponse, TError>) => void;
|
|
35
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
38
|
+
*/
|
|
36
39
|
export declare const createMutation: <TVar, TResponse = any, TError = unknown>(mutationFn: (variables: TVar, state: MutationState<TVar, TResponse, TError>) => Promise<TResponse>, options?: CreateMutationOptions<TVar, TResponse, TError>) => UseMutation<TVar, TResponse, TError>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createMutation = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const create_store_1 = require("./create-store");
|
|
6
|
+
/**
|
|
7
|
+
* @see https://floppy-disk.vercel.app/docs/api#createmutation
|
|
8
|
+
*/
|
|
6
9
|
const createMutation = (mutationFn, options = {}) => {
|
|
7
10
|
const { onMutate = utils_1.noop, onSuccess = utils_1.noop, onError = utils_1.noop, onSettled = utils_1.noop, ...createStoreOptions } = options;
|
|
8
11
|
const useMutation = (0, create_store_1.createStore)(({ set, get }) => ({
|
|
@@ -197,9 +197,11 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
|
|
|
197
197
|
*
|
|
198
198
|
* Disabled by default.
|
|
199
199
|
*
|
|
200
|
-
* If
|
|
200
|
+
* If last data fetching is failed, the polling interval will be disabled, and it will use `retry` mechanism instead.
|
|
201
|
+
*
|
|
202
|
+
* @see https://floppy-disk.vercel.app/docs/query/polling
|
|
201
203
|
*/
|
|
202
|
-
refetchInterval?: number | false | (() => number | false);
|
|
204
|
+
refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
|
|
203
205
|
};
|
|
204
206
|
export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
|
|
205
207
|
/**
|
|
@@ -257,4 +259,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
|
|
|
257
259
|
error?: FunctionComponent<TKey>;
|
|
258
260
|
}) => JSX.Element;
|
|
259
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
264
|
+
*/
|
|
260
265
|
export declare const createQuery: <TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown>(queryFn: (key: TKey, state: QueryState<TKey, TResponse, TData, TError>) => Promise<TResponse>, options?: CreateQueryOptions<TKey, TResponse, TData, TError>) => UseQuery<TKey, TResponse, TData, TError>;
|
|
@@ -34,6 +34,9 @@ const useQueryDefaultDeps = (state) => [
|
|
|
34
34
|
state.isWaitingNextPage,
|
|
35
35
|
state.hasNextPage,
|
|
36
36
|
];
|
|
37
|
+
/**
|
|
38
|
+
* @see https://floppy-disk.vercel.app/docs/api#createquery
|
|
39
|
+
*/
|
|
37
40
|
const createQuery = (queryFn, options = {}) => {
|
|
38
41
|
const defaultFetchOnWindowFocus = options.fetchOnMount ?? true;
|
|
39
42
|
const { onFirstSubscribe = utils_1.noop, onSubscribe = utils_1.noop, onLastUnsubscribe = utils_1.noop, onBeforeChangeKey = utils_1.noop, defaultDeps = useQueryDefaultDeps, select = utils_1.identityFn, staleTime = 3000, // 3 seconds
|
|
@@ -96,7 +99,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
96
99
|
callQuery();
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
|
-
|
|
102
|
+
const nextState = {
|
|
100
103
|
isWaiting: false,
|
|
101
104
|
status: 'success',
|
|
102
105
|
isLoading: false,
|
|
@@ -117,13 +120,15 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
117
120
|
pageParam: newPageParam,
|
|
118
121
|
pageParams: newPageParams,
|
|
119
122
|
hasNextPage: (0, utils_1.hasValue)(newPageParam),
|
|
120
|
-
}
|
|
121
|
-
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
123
|
+
};
|
|
124
|
+
const refetchIntervalValue = typeof window !== 'undefined' &&
|
|
125
|
+
(0, utils_1.getValueOrComputedValue)(refetchInterval, { ...get(), ...nextState });
|
|
122
126
|
if (refetchIntervalValue) {
|
|
123
127
|
refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
|
|
124
128
|
forceFetch();
|
|
125
129
|
}, refetchIntervalValue));
|
|
126
130
|
}
|
|
131
|
+
set(nextState);
|
|
127
132
|
onSuccess(response, stateBeforeCallQuery);
|
|
128
133
|
resolve(get());
|
|
129
134
|
})
|
|
@@ -249,7 +254,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
249
254
|
defaultDeps,
|
|
250
255
|
onFirstSubscribe: (state) => {
|
|
251
256
|
if (state.isSuccess) {
|
|
252
|
-
const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
|
|
257
|
+
const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval, state);
|
|
253
258
|
if (refetchIntervalValue) {
|
|
254
259
|
refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
|
|
255
260
|
state.forceFetch();
|
|
@@ -23,6 +23,9 @@ export type UseStore<T extends StoreData> = {
|
|
|
23
23
|
setDefaultValues: (values: SetStoreData<T>) => void;
|
|
24
24
|
Watch: (props: WatchProps<T>) => any;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
28
|
+
*/
|
|
26
29
|
export declare const createStore: <T extends StoreData>(initializer: StoreInitializer<T>, options?: InitStoreOptions<T> & {
|
|
27
30
|
defaultDeps?: SelectDeps<T>;
|
|
28
31
|
}) => UseStore<T>;
|
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createStore = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const vanilla_1 = require("../vanilla");
|
|
6
|
+
/**
|
|
7
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
8
|
+
*/
|
|
6
9
|
const createStore = (initializer, options = {}) => {
|
|
7
10
|
const { get, set, subscribe, getSubscribers } = (0, vanilla_1.initStore)(initializer, options);
|
|
8
11
|
const { defaultDeps } = options;
|
|
@@ -46,5 +46,8 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
46
46
|
defaultDeps?: SelectDeps<T>;
|
|
47
47
|
hashKeyFn?: (obj: TKey) => string;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
51
|
+
*/
|
|
49
52
|
export declare const createStores: <TKey extends StoreKey = StoreKey, T extends StoreData = StoreData>(initializer: StoresInitializer<TKey, T>, options?: CreateStoresOptions<TKey, T>) => UseStores<TKey, T>;
|
|
50
53
|
export {};
|
|
@@ -4,6 +4,9 @@ exports.createStores = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
6
|
const vanilla_1 = require("../vanilla");
|
|
7
|
+
/**
|
|
8
|
+
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
9
|
+
*/
|
|
7
10
|
const createStores = (initializer, options = {}) => {
|
|
8
11
|
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn = utils_1.hashStoreKey, } = options;
|
|
9
12
|
const stores = new Map();
|