@storesjs/stores 0.9.0 → 0.10.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/README.md +55 -29
- package/dist/createBaseStore.d.ts +6 -6
- package/dist/createDerivedStore.d.ts +9 -17
- package/dist/createQueryStore.d.ts +4 -3
- package/dist/createVirtualStore.d.ts +1 -2
- package/dist/env.native.d.ts +0 -2
- package/dist/env.web.d.ts +0 -1
- package/dist/hooks/useListen.d.ts +2 -2
- package/dist/index.d.ts +1 -16
- package/dist/index.shared.d.ts +14 -0
- package/dist/index.vanilla.d.ts +2 -0
- package/dist/internal/baseStore.d.ts +2 -0
- package/dist/{config.d.ts → internal/config.d.ts} +5 -11
- package/dist/{utils → internal}/createStoreActions.d.ts +4 -5
- package/dist/{derivedStore → internal/derivedStore}/deriveProxy.d.ts +2 -2
- package/dist/{derivedStore → internal/derivedStore}/pathFinder.d.ts +1 -2
- package/dist/internal/derivedStore.d.ts +2 -0
- package/dist/{errors.d.ts → internal/errors.d.ts} +0 -4
- package/dist/{logger.d.ts → internal/logger.d.ts} +0 -2
- package/dist/internal/middleware/createHydrationGate.d.ts +20 -0
- package/dist/internal/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/internal/queryStore.d.ts +2 -0
- package/dist/internal/runtime.d.ts +13 -0
- package/dist/internal/signal.d.ts +12 -0
- package/dist/internal/storage/storageCreators.d.ts +12 -0
- package/dist/{utils → internal}/storeUtils.d.ts +3 -21
- package/dist/internal/sync/browserSyncEngine.d.ts +3 -0
- package/dist/internal/sync/noopSyncEngine.d.ts +3 -0
- package/dist/internal/sync/syncEnhancer.d.ts +26 -0
- package/dist/{sync → internal/sync}/syncUtils.d.ts +1 -1
- package/dist/internal/utils/persistUtils.d.ts +9 -0
- package/dist/internal/virtualStore.d.ts +2 -0
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/queryStore/queryKey.d.ts +3 -0
- package/dist/queryStore/signalTypes.d.ts +4 -3
- package/dist/queryStore/types.d.ts +5 -4
- package/dist/store/attachStoreHook.react.d.ts +5 -0
- package/dist/store/attachStoreHook.vanilla.d.ts +6 -0
- package/dist/store/batchStoreNotifications.native.d.ts +3 -0
- package/dist/store/batchStoreNotifications.web.d.ts +2 -0
- package/dist/store/createStore.d.ts +6 -0
- package/dist/store/persist.d.ts +14 -0
- package/dist/store/stateUpdate.d.ts +10 -0
- package/dist/store/types.d.ts +108 -0
- package/dist/types/setState.d.ts +22 -0
- package/dist/types/subscribe.d.ts +28 -0
- package/dist/types/useStoreCallSignatures.d.ts +2 -0
- package/dist/types/useStoreCallSignatures.react.d.ts +6 -0
- package/dist/types/useStoreCallSignatures.vanilla.d.ts +2 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types.d.ts +43 -93
- package/dist/utils/time.d.ts +0 -7
- package/dist/vanilla/createBaseStore.d.ts +35 -0
- package/dist/vanilla/createDerivedStore.d.ts +62 -0
- package/dist/vanilla/createQueryStore.d.ts +116 -0
- package/dist/vanilla/createVirtualStore.d.ts +39 -0
- package/dist/vanilla/env.web.d.ts +6 -0
- package/dist/vanilla/index.d.ts +1 -0
- package/dist/vanilla/index.js +1 -0
- package/dist/vanilla/index.mjs +1 -0
- package/dist/vanilla/index.shared.d.ts +13 -0
- package/dist/vanilla/index.vanilla.d.ts +1 -0
- package/dist/vanilla/internal/baseStore.d.ts +1 -0
- package/dist/vanilla/internal/config.d.ts +63 -0
- package/dist/vanilla/internal/createStoreActions.d.ts +23 -0
- package/dist/vanilla/internal/derivedStore/cascadeScheduler.d.ts +30 -0
- package/dist/vanilla/internal/derivedStore/deriveProxy.d.ts +14 -0
- package/dist/vanilla/internal/derivedStore/pathFinder.d.ts +25 -0
- package/dist/vanilla/internal/derivedStore.d.ts +1 -0
- package/dist/vanilla/internal/errors.d.ts +9 -0
- package/dist/vanilla/internal/logger.d.ts +9 -0
- package/dist/{middleware → vanilla/internal/middleware}/createHydrationGate.d.ts +1 -2
- package/dist/{queryStore → vanilla/internal/queryStore}/queryStoreDefaults.d.ts +1 -2
- package/dist/vanilla/internal/queryStore.d.ts +1 -0
- package/dist/vanilla/internal/runtime.d.ts +12 -0
- package/dist/vanilla/internal/signal.d.ts +11 -0
- package/dist/vanilla/internal/storage/storageCreators.d.ts +11 -0
- package/dist/vanilla/internal/storeUtils.d.ts +45 -0
- package/dist/vanilla/internal/sync/browserSyncEngine.d.ts +2 -0
- package/dist/vanilla/internal/sync/noopSyncEngine.d.ts +2 -0
- package/dist/{sync → vanilla/internal/sync}/syncEnhancer.d.ts +2 -3
- package/dist/{utils → vanilla/internal/utils}/persistUtils.d.ts +1 -2
- package/dist/vanilla/internal/virtualStore.d.ts +1 -0
- package/dist/vanilla/queryStore/classes/SubscriptionManager.d.ts +66 -0
- package/dist/vanilla/queryStore/queryKey.d.ts +2 -0
- package/dist/vanilla/queryStore/signalTypes.d.ts +13 -0
- package/dist/vanilla/queryStore/types.d.ts +402 -0
- package/dist/vanilla/storage/storageTypes.d.ts +12 -0
- package/dist/vanilla/store/attachStoreHook.d.ts +5 -0
- package/dist/vanilla/store/attachStoreHook.vanilla.d.ts +5 -0
- package/dist/vanilla/store/batchStoreNotifications.web.d.ts +1 -0
- package/dist/vanilla/store/createStore.d.ts +5 -0
- package/dist/vanilla/store/persist.d.ts +13 -0
- package/dist/vanilla/store/stateUpdate.d.ts +9 -0
- package/dist/vanilla/store/types.d.ts +107 -0
- package/dist/vanilla/storesStorage.web.d.ts +2 -0
- package/dist/vanilla/sync/types.d.ts +114 -0
- package/dist/vanilla/types/functions.d.ts +23 -0
- package/dist/vanilla/types/objects.d.ts +10 -0
- package/dist/vanilla/types/setState.d.ts +21 -0
- package/dist/vanilla/types/subscribe.d.ts +27 -0
- package/dist/vanilla/types/useStoreCallSignatures.d.ts +1 -0
- package/dist/vanilla/types/useStoreCallSignatures.vanilla.d.ts +1 -0
- package/dist/vanilla/types/utils.d.ts +12 -0
- package/dist/vanilla/types.d.ts +285 -0
- package/dist/vanilla/utils/core.d.ts +25 -0
- package/dist/vanilla/utils/createAsyncMicrotaskScheduler.d.ts +34 -0
- package/dist/vanilla/utils/createMicrotaskScheduler.d.ts +27 -0
- package/dist/vanilla/utils/debounce.d.ts +21 -0
- package/dist/vanilla/utils/equality.d.ts +37 -0
- package/dist/vanilla/utils/hydrationCoordinator.d.ts +12 -0
- package/dist/vanilla/utils/promiseUtils.d.ts +1 -0
- package/dist/vanilla/utils/serialization.d.ts +13 -0
- package/dist/vanilla/utils/stringUtils.d.ts +6 -0
- package/dist/vanilla/utils/time.d.ts +36 -0
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-QJLWBD7M.mjs +1 -0
- package/dist/web/chunk-V4LHP7LR.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/dist/web/internal/runtime.js +1 -0
- package/dist/web/internal/runtime.mjs +1 -0
- package/package.json +13 -11
- package/dist/createStoreWithEqualityFn.d.ts +0 -5
- package/dist/hooks/compareHooks.d.ts +0 -50
- package/dist/signal.d.ts +0 -11
- package/dist/storage/storageCreators.d.ts +0 -22
- package/dist/sync/browserSyncEngine.d.ts +0 -3
- package/dist/sync/noopSyncEngine.d.ts +0 -3
- package/dist/web/chunk-3U5A7HQV.mjs +0 -1
- /package/dist/{derivedStore → internal/derivedStore}/cascadeScheduler.d.ts +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Mutate, StateCreator, StoreApi, StoreMutators } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the internal core store API.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createStore<State, Mutators extends StoreMutators = []>(createState: StateCreator<State, [], Mutators>): Mutate<StoreApi<State>, Mutators>;
|
|
6
|
+
//# sourceMappingURL=createStore.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PersistOptions, StateCreator, StoreMutators } from './types';
|
|
2
|
+
type PersistMutators<PersistedState, PersistReturn, Mutators extends StoreMutators> = [
|
|
3
|
+
[
|
|
4
|
+
'stores/persist',
|
|
5
|
+
[PersistedState, PersistReturn]
|
|
6
|
+
],
|
|
7
|
+
...Mutators
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Wraps a state creator with persistence.
|
|
11
|
+
*/
|
|
12
|
+
export declare function persist<State, PersistedState extends Partial<State>, PersistReturn extends void | Promise<void> = void, Mutators extends StoreMutators = []>(createState: StateCreator<State, [], Mutators>, initialOptions: PersistOptions<State, PersistedState>): StateCreator<State, [], PersistMutators<PersistedState, PersistReturn, Mutators>>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=persist.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SetStateArgs, SetStateOverloads } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calls a `setState` function with captured `setState` arguments.
|
|
4
|
+
*/
|
|
5
|
+
export declare function applySetState<S, SetReturn extends Promise<void> | void>(set: SetStateOverloads<S, SetReturn>, args: SetStateArgs<S>): SetReturn;
|
|
6
|
+
/**
|
|
7
|
+
* Applies a `setState` payload to the current state.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyStateUpdate<S>(state: S, ...setArgs: SetStateArgs<S>): S;
|
|
10
|
+
//# sourceMappingURL=stateUpdate.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { StorageValue } from '../storage/storageTypes';
|
|
2
|
+
import type { SetStateOverloads } from '../types/setState';
|
|
3
|
+
import type { SubscribeOverloads } from '../types/subscribe';
|
|
4
|
+
/**
|
|
5
|
+
* Store object contract shared by creators, middleware, and internal store utilities.
|
|
6
|
+
*/
|
|
7
|
+
export type StoreApi<S> = {
|
|
8
|
+
getInitialState: () => S;
|
|
9
|
+
getState: () => S;
|
|
10
|
+
setState: SetStateOverloads<S>;
|
|
11
|
+
subscribe: SubscribeOverloads<S>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Callback that builds store state from the set/get/store API supplied during construction.
|
|
15
|
+
*/
|
|
16
|
+
export type StateCreator<S, Mutators extends StoreMutators = [], StoreMutatorOutput extends StoreMutators = [], U = S> = ((setState: Get<Mutate<StoreApi<S>, Mutators>, 'setState', never>, getState: Get<Mutate<StoreApi<S>, Mutators>, 'getState', never>, store: Mutate<StoreApi<S>, Mutators>) => U) & {
|
|
17
|
+
$$storeMutators?: StoreMutatorOutput;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Synchronous storage adapter consumed by the persistence wrapper.
|
|
21
|
+
*/
|
|
22
|
+
export type SyncPersistStorage<State, PersistedState = Partial<State>> = {
|
|
23
|
+
getItem: (name: string) => StorageValue<PersistedState> | null;
|
|
24
|
+
removeItem: (name: string) => void;
|
|
25
|
+
setItem: (name: string, state: State, version: number | undefined) => void;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Asynchronous storage adapter consumed by the persistence wrapper.
|
|
29
|
+
*/
|
|
30
|
+
export type AsyncPersistStorage<State, PersistedState = Partial<State>> = {
|
|
31
|
+
getItem: (name: string) => Promise<StorageValue<PersistedState> | null>;
|
|
32
|
+
removeItem: (name: string) => Promise<void>;
|
|
33
|
+
setItem: (name: string, state: State, version: number | undefined) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Accepted storage adapter types for sync or async persistence.
|
|
37
|
+
*/
|
|
38
|
+
export type PersistStorage<State, PersistedState = Partial<State>> = AsyncPersistStorage<State, PersistedState> | SyncPersistStorage<State, PersistedState>;
|
|
39
|
+
/**
|
|
40
|
+
* Resolved storage config for persisted stores.
|
|
41
|
+
*/
|
|
42
|
+
export type PersistStorageConfig<State, PersistedState extends Partial<State>> = {
|
|
43
|
+
async: false;
|
|
44
|
+
persistStorage: SyncPersistStorage<State, PersistedState>;
|
|
45
|
+
version: number;
|
|
46
|
+
} | {
|
|
47
|
+
async: true;
|
|
48
|
+
persistStorage: AsyncPersistStorage<State, PersistedState>;
|
|
49
|
+
version: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Persistence options consumed by the persistence wrapper.
|
|
53
|
+
*/
|
|
54
|
+
export type PersistOptions<S, PersistedState = Partial<S>> = {
|
|
55
|
+
merge?: (persistedState: PersistedState | undefined, currentState: S) => S;
|
|
56
|
+
migrate?: (persistedState: PersistedState, version: number) => PersistedState | Promise<PersistedState>;
|
|
57
|
+
name: string;
|
|
58
|
+
onRehydrateStorage?: (state: S) => ((state?: S, error?: unknown) => void) | void;
|
|
59
|
+
skipHydration?: boolean;
|
|
60
|
+
storage: PersistStorage<S, PersistedState>;
|
|
61
|
+
version: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Methods attached by the persistence wrapper before async hydration state is added.
|
|
65
|
+
*/
|
|
66
|
+
export type PersistMethods<S, PersistedState> = {
|
|
67
|
+
clearStorage: () => void;
|
|
68
|
+
getOptions: () => Partial<PersistOptions<S, PersistedState>>;
|
|
69
|
+
hasHydrated: () => boolean;
|
|
70
|
+
onHydrate: (listener: (state: S) => void) => () => void;
|
|
71
|
+
onFinishHydration: (listener: (state: S) => void) => () => void;
|
|
72
|
+
rehydrate: () => Promise<void> | void;
|
|
73
|
+
setOptions: (options: Partial<PersistOptions<S, PersistedState>>) => void;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Store shape after the persistence wrapper adds persistence methods, write-through `setState`,
|
|
77
|
+
* and async hydration state when applicable.
|
|
78
|
+
*/
|
|
79
|
+
export type WithPersist<Store, PersistedState, PersistReturn extends void | Promise<void>> = Store extends StoreApi<infer S> ? Write<Store, {
|
|
80
|
+
persist: PersistMethods<S, PersistedState> & HydrationPromise<PersistReturn>;
|
|
81
|
+
setState: SetStateOverloads<S, PersistReturn>;
|
|
82
|
+
}> : Store;
|
|
83
|
+
type HydrationPromise<PersistReturn> = PersistReturn extends Promise<void> ? {
|
|
84
|
+
/** Invoke to get a promise that resolves once hydration completes. */
|
|
85
|
+
hydrationPromise: () => Promise<void>;
|
|
86
|
+
} : {
|
|
87
|
+
hydrationPromise?: undefined;
|
|
88
|
+
};
|
|
89
|
+
type Get<T, K, Fallback> = K extends keyof T ? T[K] : Fallback;
|
|
90
|
+
type Write<T, U> = Omit<T, keyof U> & U;
|
|
91
|
+
type PersistMutator<Store, Args> = Args extends [infer PersistedState, infer PersistReturn extends void | Promise<void>] ? WithPersist<Store, PersistedState, PersistReturn> : Store;
|
|
92
|
+
type StoreMutatorIdentifier = keyof StoreMutatorMap<unknown, unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Mapping from store mutator identifiers to the store API shape they add.
|
|
95
|
+
*/
|
|
96
|
+
export interface StoreMutatorMap<Store, Args> {
|
|
97
|
+
'stores/persist': PersistMutator<Store, Args>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Ordered list of store mutators applied to a state creator.
|
|
101
|
+
*/
|
|
102
|
+
export type StoreMutators = [StoreMutatorIdentifier, unknown][];
|
|
103
|
+
/**
|
|
104
|
+
* Applies a list of store mutators to a store API type.
|
|
105
|
+
*/
|
|
106
|
+
export type Mutate<Store, Mutators> = number extends Mutators['length' & keyof Mutators] ? Store : Mutators extends [] ? Store : Mutators extends [[infer Identifier, infer Args], ...infer Rest] ? Identifier extends StoreMutatorIdentifier ? Rest extends StoreMutators ? Mutate<StoreMutatorMap<Store, Args>[Identifier], Rest> : StoreMutatorMap<Store, Args>[Identifier] : Store : Store;
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BivariantMethod } from './functions';
|
|
2
|
+
export type SetPartial<S> = S | Partial<S> | BivariantMethod<{
|
|
3
|
+
updater(state: S): S | Partial<S>;
|
|
4
|
+
}>;
|
|
5
|
+
export type SetFull<S> = S | BivariantMethod<{
|
|
6
|
+
updater(state: S): S;
|
|
7
|
+
}>;
|
|
8
|
+
export type SetStateReplaceArgs<S, ExtraArgs extends unknown[] = []> = [update: SetFull<S>, replace: true, ...extraArgs: ExtraArgs];
|
|
9
|
+
export type SetStatePartialArgs<S, ExtraArgs extends unknown[] = []> = [update: SetPartial<S>, replace?: false, ...extraArgs: ExtraArgs];
|
|
10
|
+
export type SetStateArgs<S, ExtraArgs extends unknown[] = []> = SetStatePartialArgs<S, ExtraArgs> | SetStateReplaceArgs<S, ExtraArgs>;
|
|
11
|
+
/**
|
|
12
|
+
* Rest-argument form of `setState`, used when forwarding calls.
|
|
13
|
+
*/
|
|
14
|
+
export type SetState<S, ExtraArgs extends unknown[] = [], PersistReturn extends Promise<void> | void = void> = (...args: SetStateArgs<S, ExtraArgs>) => PersistReturn;
|
|
15
|
+
/**
|
|
16
|
+
* Store `setState` method overloads for partial updates and full replacement.
|
|
17
|
+
*/
|
|
18
|
+
export type SetStateOverloads<S, PersistReturn extends Promise<void> | void = void> = BivariantMethod<{
|
|
19
|
+
setState(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
20
|
+
setState(update: SetFull<S>, replace: true): PersistReturn;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=setState.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type Listener<S> = (state: S, prevState: S) => void;
|
|
2
|
+
export type Selector<S, Selected> = (state: S) => Selected;
|
|
3
|
+
export type EqualityFn<T = unknown> = (a: T, b: T) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Minimum store API required for subscription.
|
|
6
|
+
*/
|
|
7
|
+
export type SubscribableStore = {
|
|
8
|
+
subscribe(selector: Selector<unknown, unknown>, listener: () => void, options?: SubscribeOptions<unknown>): UnsubscribeFn;
|
|
9
|
+
};
|
|
10
|
+
export type SubscribeOptions<Selected> = {
|
|
11
|
+
equalityFn?: EqualityFn<Selected>;
|
|
12
|
+
fireImmediately?: boolean;
|
|
13
|
+
isDerivedStore?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ListenerArgs<S> = [listener: Listener<S>];
|
|
16
|
+
export type SelectorArgs<S, Selected> = [
|
|
17
|
+
selector: Selector<S, Selected>,
|
|
18
|
+
listener: Listener<Selected>,
|
|
19
|
+
options?: SubscribeOptions<Selected>
|
|
20
|
+
];
|
|
21
|
+
export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
|
|
22
|
+
export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
|
|
23
|
+
export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
|
|
24
|
+
export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
|
|
25
|
+
(listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
|
|
26
|
+
<Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EqualityFn, Selector } from './subscribe';
|
|
2
|
+
export type UseStoreCallSignatures<State> = {
|
|
3
|
+
(): State;
|
|
4
|
+
<Selected>(selector: Selector<State, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=useStoreCallSignatures.react.d.ts.map
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export declare function hasOwn<T extends Record<string, unknown>, K extends stri
|
|
|
6
6
|
* Checks prototype is `Object.prototype` or `null`. Excludes arrays, class instances, etc.
|
|
7
7
|
*/
|
|
8
8
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Checks for non-null, non-array objects.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isRecordLike(value: unknown): value is Record<string, unknown>;
|
|
9
13
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,59 +1,42 @@
|
|
|
1
|
-
import type { Mutate, StateCreator as ZustandStateCreator, StoreApi, StoreMutatorIdentifier } from 'zustand';
|
|
2
|
-
import type { PersistOptions } from 'zustand/middleware';
|
|
3
1
|
import type { StorageValue } from './storage/storageTypes';
|
|
2
|
+
import type { PersistOptions, StateCreator as StoreStateCreator, StoreApi, StoreMutators, WithPersist } from './store/types';
|
|
4
3
|
import type { SyncConfig } from './sync/types';
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
} ? {
|
|
21
|
-
setState(...args: SetPartialArgs): PersistReturn;
|
|
22
|
-
setState(...args: SetFullArgs): PersistReturn;
|
|
23
|
-
persist: {
|
|
24
|
-
clearStorage: () => void;
|
|
25
|
-
getOptions: () => Partial<PersistOptions<S, PersistedState>>;
|
|
26
|
-
hasHydrated: () => boolean;
|
|
27
|
-
onHydrate: (listener: (state: S) => void) => () => void;
|
|
28
|
-
onFinishHydration: (listener: (state: S) => void) => () => void;
|
|
29
|
-
rehydrate: () => Promise<void> | void;
|
|
30
|
-
setOptions: (options: Partial<PersistOptions<S, PersistedState, PersistReturn>>) => void;
|
|
31
|
-
} & HydrationPromise<PersistReturn>;
|
|
32
|
-
} : never;
|
|
33
|
-
export type StateCreator<S, U = S> = ZustandStateCreator<S, [SubscribeWithSelector], [SubscribeWithSelector], U>;
|
|
34
|
-
export type UseBoundStoreWithEqualityFn<Store extends StoreApi<unknown>, State = InferStoreState<Store>> = UseStoreCallSignatures<State> & Store;
|
|
35
|
-
export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<Mutate<StoreApi<S>, [SubscribeWithSelector]>> & {
|
|
4
|
+
import type { FunctionKeys } from './types/functions';
|
|
5
|
+
import type { SetFull, SetPartial, SetStateArgs } from './types/setState';
|
|
6
|
+
import type { EqualityFn, Selector, SubscribeOverloads } from './types/subscribe';
|
|
7
|
+
import type { UseStoreCallSignatures } from './types/useStoreCallSignatures';
|
|
8
|
+
export type { StoreMutators } from './store/types';
|
|
9
|
+
export type * from './types/setState';
|
|
10
|
+
export type * from './types/subscribe';
|
|
11
|
+
export type * from './types/useStoreCallSignatures';
|
|
12
|
+
export type StoreMutatorsWithSelector<Mutators extends StoreMutators = StoreMutators> = Mutators;
|
|
13
|
+
export type StateCreator<S, U = S> = StoreStateCreator<S, [], [], U>;
|
|
14
|
+
export type UseBoundStoreWithEqualityFn<Store extends {
|
|
15
|
+
getState: () => unknown;
|
|
16
|
+
}, State = InferStoreState<Store>> = UseStoreCallSignatures<State> & Store;
|
|
17
|
+
export type BaseStore<S, ExtraSubscribeOptions extends boolean = false> = UseBoundStoreWithEqualityFn<StoreApi<S>> & {
|
|
36
18
|
subscribe: SubscribeOverloads<S, ExtraSubscribeOptions>;
|
|
37
19
|
};
|
|
38
|
-
export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn =
|
|
39
|
-
export type Store<S, PersistedState extends Partial<S> = never, PersistReturn =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
export type PersistedStore<S, PersistedState = Partial<S>, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = UseStoreCallSignatures<S> & WithPersist<BaseStore<S, ExtraSubscribeOptions>, PersistedState, PersistReturn>;
|
|
21
|
+
export type Store<S, PersistedState extends Partial<S> = never, PersistReturn extends void | Promise<void> = void | Promise<void>, ExtraSubscribeOptions extends boolean = false> = [PersistedState] extends [never] ? BaseStore<S, ExtraSubscribeOptions> : PersistedStore<S, PersistedState, PersistReturn, ExtraSubscribeOptions>;
|
|
22
|
+
/**
|
|
23
|
+
* Store returned by creators that accept optional persistence options.
|
|
24
|
+
* `persist` exists only when persistence is configured.
|
|
25
|
+
*/
|
|
26
|
+
export type OptionallyPersistedStore<S, PersistedState, PersistReturn extends void | Promise<void> = void> = UseStoreCallSignatures<S> & Omit<BaseStore<S>, 'setState'> & {
|
|
43
27
|
persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
|
|
28
|
+
setState(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
29
|
+
setState(update: SetFull<S>, replace: true): PersistReturn;
|
|
44
30
|
};
|
|
45
31
|
export type NoInfer<T> = [T][T extends unknown ? 0 : never];
|
|
46
32
|
export type Timeout = ReturnType<typeof setTimeout>;
|
|
47
|
-
export type
|
|
48
|
-
export type Selector<S, Selected> = (state: S) => Selected;
|
|
49
|
-
export type EqualityFn<T = unknown> = (a: T, b: T) => boolean;
|
|
50
|
-
export type UseStoreCallSignatures<S> = {
|
|
51
|
-
(): S;
|
|
52
|
-
<Selected>(selector: Selector<S, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
53
|
-
};
|
|
54
|
-
export type InferStoreState<Store extends StoreApi<unknown>> = Store extends {
|
|
33
|
+
export type InferStoreState<Store> = Store extends {
|
|
55
34
|
getState: () => infer T;
|
|
56
35
|
} ? T : never;
|
|
36
|
+
/**
|
|
37
|
+
* Action methods returned by `createStoreActions(store)`.
|
|
38
|
+
*/
|
|
39
|
+
export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState<Store>, FunctionKeys<InferStoreState<Store>>>;
|
|
57
40
|
/**
|
|
58
41
|
* Extracts a store's `setState` return type.
|
|
59
42
|
* - `void` for non-persisted or synchronous persisted stores.
|
|
@@ -67,45 +50,15 @@ export type InferSetStateReturn<Store> = Store extends {
|
|
|
67
50
|
* Returns `never` if the store doesn't use persistence.
|
|
68
51
|
*/
|
|
69
52
|
export type InferPersistedState<PersistedStore> = PersistedStore extends Store<infer _, infer PersistedState> ? PersistedState : never;
|
|
70
|
-
export type SetPartial<S> = Partial<S> | ((state: S) => Partial<S>);
|
|
71
|
-
export type SetFull<S> = S | ((state: S) => S);
|
|
72
|
-
export type SetStateReplaceArgs<S, ExtraArgs extends unknown[] = []> = [update: SetFull<S>, replace: true, ...extraArgs: ExtraArgs];
|
|
73
|
-
export type SetStatePartialArgs<S, ExtraArgs extends unknown[] = []> = [update: SetPartial<S>, replace?: false, ...extraArgs: ExtraArgs];
|
|
74
|
-
export type SetStateArgs<S, ExtraArgs extends unknown[] = []> = SetStatePartialArgs<S, ExtraArgs> | SetStateReplaceArgs<S, ExtraArgs>;
|
|
75
|
-
export type SetState<S, ExtraArgs extends unknown[] = [], PersistReturn extends Promise<void> | void = void> = (...args: SetStateArgs<S, ExtraArgs>) => PersistReturn;
|
|
76
|
-
export type SetStateOverloads<S, PersistReturn extends Promise<void> | void = void> = {
|
|
77
|
-
(update: SetPartial<S>, replace?: false): PersistReturn;
|
|
78
|
-
(update: SetFull<S>, replace: true): PersistReturn;
|
|
79
|
-
};
|
|
80
|
-
export type WithAsyncSet<Store extends StoreApi<unknown>, S, PersistedState, PersistReturn> = Omit<Store, 'persist' | 'setState'> & {
|
|
81
|
-
persist?: PersistedStore<S, PersistedState, PersistReturn, false>['persist'];
|
|
82
|
-
setState(update: SetPartial<InferStoreState<Store>>, replace?: false): PersistReturn;
|
|
83
|
-
setState(update: SetFull<InferStoreState<Store>>, replace: true): PersistReturn;
|
|
84
|
-
};
|
|
85
53
|
/**
|
|
86
|
-
*
|
|
54
|
+
* Reads store state and records the dependencies of a derived computation.
|
|
55
|
+
* - `$(store, selector, equalityFn?)` depends on the selected state
|
|
56
|
+
* - `$(store)` depends on accessed state paths
|
|
87
57
|
*/
|
|
88
|
-
export type
|
|
89
|
-
|
|
58
|
+
export type DeriveGetter = {
|
|
59
|
+
<S extends Store<InferStoreState<S>>>(store: S): InferStoreState<S>;
|
|
60
|
+
<S extends Store<InferStoreState<S>>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
90
61
|
};
|
|
91
|
-
export type SubscribeOptions<Selected> = {
|
|
92
|
-
equalityFn?: EqualityFn<Selected>;
|
|
93
|
-
fireImmediately?: boolean;
|
|
94
|
-
isDerivedStore?: boolean;
|
|
95
|
-
};
|
|
96
|
-
export type ListenerArgs<S> = [listener: Listener<S>];
|
|
97
|
-
export type SelectorArgs<S, Selected> = [
|
|
98
|
-
selector: Selector<S, Selected>,
|
|
99
|
-
listener: Listener<Selected>,
|
|
100
|
-
options?: SubscribeOptions<Selected>
|
|
101
|
-
];
|
|
102
|
-
export type SubscribeOverloads<S, ExtraOptions extends boolean = false> = {
|
|
103
|
-
(listener: Listener<S>): UnsubscribeFn<ExtraOptions>;
|
|
104
|
-
<Selected>(selector: Selector<S, Selected>, listener: Listener<Selected>, options?: SubscribeOptions<Selected>): UnsubscribeFn<ExtraOptions>;
|
|
105
|
-
};
|
|
106
|
-
export type SubscribeArgs<S, Selected = unknown> = ListenerArgs<S> | SelectorArgs<S, Selected>;
|
|
107
|
-
export type UnsubscribeFn<Options extends boolean = false> = Options extends true ? (skipAbortFetch?: boolean) => void : () => void;
|
|
108
|
-
export type SubscribeFn<S, Selected = S> = (...args: SubscribeArgs<S, Selected>) => UnsubscribeFn;
|
|
109
62
|
export type DerivedStore<S> = WithFlushUpdates<ReadOnlyDerivedStore<BaseStore<S>>>;
|
|
110
63
|
export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
|
|
111
64
|
/**
|
|
@@ -123,8 +76,7 @@ export type WithFlushUpdates<Store extends StoreApi<unknown>> = Store & {
|
|
|
123
76
|
};
|
|
124
77
|
export type WithGetSnapshot<Store extends StoreApi<unknown>> = Store & {
|
|
125
78
|
/**
|
|
126
|
-
*
|
|
127
|
-
* store when it gets the initial state before subscribing to the store.
|
|
79
|
+
* Reads the current snapshot while activating lazy derived stores before subscription.
|
|
128
80
|
*/
|
|
129
81
|
getSnapshot: () => InferStoreState<Store>;
|
|
130
82
|
};
|
|
@@ -199,7 +151,7 @@ export type Serializer<SerializedState> = <PersistedState>(storageValue: Storage
|
|
|
199
151
|
* Synchronous storage interface.
|
|
200
152
|
* Used for localStorage and MMKV implementations.
|
|
201
153
|
*/
|
|
202
|
-
export
|
|
154
|
+
export type SyncStorageInterface<SerializedState = unknown> = {
|
|
203
155
|
readonly async?: false;
|
|
204
156
|
/**
|
|
205
157
|
* Adapter-level deserializer used when a store does not supply its own.
|
|
@@ -217,7 +169,7 @@ export interface SyncStorageInterface<SerializedState = unknown> {
|
|
|
217
169
|
get(key: string): SerializedState | undefined;
|
|
218
170
|
getAllKeys(): string[];
|
|
219
171
|
set(key: string, value: SerializedState): void;
|
|
220
|
-
}
|
|
172
|
+
};
|
|
221
173
|
/**
|
|
222
174
|
* Asynchronous storage interface.
|
|
223
175
|
* Used for Chrome storage and other async storage implementations.
|
|
@@ -244,7 +196,7 @@ export type AsyncStorageInterface<SerializedState = unknown> = {
|
|
|
244
196
|
/**
|
|
245
197
|
* Configuration options for creating a persistable store.
|
|
246
198
|
*/
|
|
247
|
-
export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void> = {
|
|
199
|
+
export type PersistConfig<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = {
|
|
248
200
|
/**
|
|
249
201
|
* A function to convert the serialized value back into the state object.
|
|
250
202
|
* If not provided, the storage adapter's `deserializer` is used before falling back to the default implementation.
|
|
@@ -252,7 +204,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
252
204
|
deserializer?: (serializedState: unknown) => StorageValue<PersistedState>;
|
|
253
205
|
/**
|
|
254
206
|
* A function to merge persisted state with current state during hydration.
|
|
255
|
-
* By default,
|
|
207
|
+
* By default, persisted state is shallow-merged into the current state.
|
|
256
208
|
*/
|
|
257
209
|
merge?: PersistOptions<S, PersistedState>['merge'];
|
|
258
210
|
/**
|
|
@@ -270,7 +222,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
270
222
|
* A function that determines which parts of the state should be persisted.
|
|
271
223
|
* By default, the entire state is persisted.
|
|
272
224
|
*/
|
|
273
|
-
partialize?: (state: S) => PersistedState;
|
|
225
|
+
partialize?: (state: Readonly<S>) => PersistedState;
|
|
274
226
|
/**
|
|
275
227
|
* The throttle rate for the persist operation in milliseconds.
|
|
276
228
|
* @default iOS: time.seconds(3) | Android: time.seconds(5)
|
|
@@ -300,7 +252,7 @@ export type PersistConfig<S, PersistedState = Partial<S>, PersistReturn = void>
|
|
|
300
252
|
export type EnforceStorageKey<Options> = {
|
|
301
253
|
storageKey: string;
|
|
302
254
|
} extends Options ? Options : never;
|
|
303
|
-
export type BaseStoreOptions<S, PersistedState = Partial<S>, PersistReturn = void> = (PersistConfig<S, PersistedState, PersistReturn> & {
|
|
255
|
+
export type BaseStoreOptions<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn = void> = (PersistConfig<S, PersistedState, PersistReturn> & {
|
|
304
256
|
sync?: S extends Record<string, unknown> ? SyncOption<S> : undefined;
|
|
305
257
|
}) | ({
|
|
306
258
|
sync: S extends Record<string, unknown> ? SyncWithoutStorageOption<NoInfer<S>> : undefined;
|
|
@@ -315,12 +267,11 @@ export type SyncOption<S extends Record<string, unknown>> = SyncConfig<S> | stri
|
|
|
315
267
|
type SyncWithoutStorageOption<S extends Record<string, unknown>> = string | (Omit<SyncConfig<S>, 'injectStorageMetadata' | 'key'> & {
|
|
316
268
|
injectStorageMetadata?: never;
|
|
317
269
|
key: SyncWithoutStorageKey<SyncConfig<S>>;
|
|
318
|
-
readonly __syncStateBrand?: (state: S) => S;
|
|
319
270
|
});
|
|
320
271
|
type SyncWithoutStorageKey<Config> = Config extends {
|
|
321
272
|
key?: infer Key;
|
|
322
273
|
} ? Extract<Key, string> extends never ? string : Extract<Key, string> : string;
|
|
323
|
-
type UndefinedPersistKeys<S, PersistedState
|
|
274
|
+
type UndefinedPersistKeys<S, PersistedState extends Partial<S>, PersistReturn> = {
|
|
324
275
|
[K in keyof PersistConfig<S, PersistedState, PersistReturn>]?: undefined;
|
|
325
276
|
};
|
|
326
277
|
/**
|
|
@@ -332,5 +283,4 @@ export type DebounceOptions = {
|
|
|
332
283
|
maxWait?: number;
|
|
333
284
|
trailing?: boolean;
|
|
334
285
|
};
|
|
335
|
-
export {};
|
|
336
286
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/utils/time.d.ts
CHANGED
|
@@ -33,12 +33,5 @@ type TimeUtils = {
|
|
|
33
33
|
* time.zero // 0
|
|
34
34
|
*/
|
|
35
35
|
export declare const time: TimeUtils;
|
|
36
|
-
/**
|
|
37
|
-
* Waits for microtasks to complete.
|
|
38
|
-
* Uses setTimeout(0) to allow microtasks scheduled via queueMicrotask to execute.
|
|
39
|
-
*
|
|
40
|
-
* Useful in tests when waiting for async operations scheduled via microtasks.
|
|
41
|
-
*/
|
|
42
|
-
export declare function waitForMicrotask(): Promise<void>;
|
|
43
36
|
export {};
|
|
44
37
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a base store without persistence.
|
|
4
|
+
* @param createState - The state creator function for the base store.
|
|
5
|
+
* @returns A store with the specified state.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createBaseStore<S>(createState: StateCreator<S>): Store<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a base store with persistence.
|
|
10
|
+
* @param createState - The state creator function for the base store.
|
|
11
|
+
* @param options - The configuration options for persistence and sync.
|
|
12
|
+
* @returns A store with the specified state and persistence.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a base store with async persistence.
|
|
17
|
+
* @param createState - The state creator function for the base store.
|
|
18
|
+
* @param options - The configuration options for persistence and sync.
|
|
19
|
+
* @returns A store with the specified state and persistence.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options: BaseStoreOptions<S, PersistedState, PersistReturn>): Store<S, PersistedState, PersistReturn, false>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a base store with optional persistence.
|
|
24
|
+
* @param createState - The state creator function for the base store.
|
|
25
|
+
* @param options - The configuration options for persistence and sync.
|
|
26
|
+
* @returns A store with the specified state and optional persistence.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends void = void>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a base store with optional async persistence.
|
|
31
|
+
* @param createState - The state creator function for the base store.
|
|
32
|
+
* @param options - The configuration options for persistence and sync.
|
|
33
|
+
* @returns A store with the specified state and optional persistence.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createBaseStore<S, PersistedState extends Partial<S> = Partial<S>, PersistReturn extends Promise<void> = Promise<void>>(createState: StateCreator<S>, options?: BaseStoreOptions<S, PersistedState, PersistReturn>): OptionallyPersistedStore<S, PersistedState, PersistReturn>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { DeriveGetter, DeriveOptions, DerivedStore } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* ### `createDerivedStore`
|
|
4
|
+
*
|
|
5
|
+
* Creates a **read-only** store derived from one or more source stores.
|
|
6
|
+
*
|
|
7
|
+
* ---
|
|
8
|
+
* The `deriveFunction` is called whenever its dependencies change, producing a new derived state.
|
|
9
|
+
* Dependencies are automatically tracked through a special `$` helper, which supports:
|
|
10
|
+
*
|
|
11
|
+
* 1) **Selector-based** usage:
|
|
12
|
+
* ```ts
|
|
13
|
+
* $ => {
|
|
14
|
+
* const user = $(useUserStore, s => s.user, shallowEqual);
|
|
15
|
+
* const theme = $(useSettingsStore, s => s.appearance.theme);
|
|
16
|
+
* return { user, theme, isAdmin: user?.roles.includes('admin') };
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* 2) **Proxy-based** usage (auto-built selectors for nested properties):
|
|
21
|
+
* ```ts
|
|
22
|
+
* $ => {
|
|
23
|
+
* const { user } = $(useUserStore); // Subscribe to `user`
|
|
24
|
+
* const theme = $(useSettingsStore).appearance.theme; // Subscribe to `theme`
|
|
25
|
+
* return { isAdmin: user?.roles.includes('admin'), theme, user };
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ---
|
|
30
|
+
* Derived stores automatically unsubscribe from all dependencies when no consumers remain, and
|
|
31
|
+
* resubscribe when new consumers appear. The returned store exposes:
|
|
32
|
+
*
|
|
33
|
+
* - A **store object** with `getState()`, `subscribe()`, and `destroy()`
|
|
34
|
+
* - In the React build, a **React hook** (`const state = derivedStore(selector, equalityFn?)`)
|
|
35
|
+
*
|
|
36
|
+
* ---
|
|
37
|
+
* You can optionally pass a second parameter (either an equality function or a config object)
|
|
38
|
+
* to enable debouncing, customize the equality function, or set `lockDependencies: true`.
|
|
39
|
+
*
|
|
40
|
+
* (When dependencies are locked, subscriptions created via `$` are established once and are
|
|
41
|
+
* not rebuilt on subsequent re-derives, which can be a performance win for certain workloads.)
|
|
42
|
+
*
|
|
43
|
+
* ---
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Create a derived store
|
|
47
|
+
* const searchResultsStore = createDerivedStore($ => {
|
|
48
|
+
* const query = $(searchStore).query.trim().toLowerCase();
|
|
49
|
+
* const items = $(itemsStore).items;
|
|
50
|
+
* return findResults(query, items);
|
|
51
|
+
* }, shallowEqual);
|
|
52
|
+
*
|
|
53
|
+
* const results = searchResultsStore.getState();
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* ---
|
|
57
|
+
* @param deriveFunction - Function that reads from other stores via `$` to produce derived state.
|
|
58
|
+
* @param optionsOrEqualityFn - Either an equality function or a config object (see `DeriveOptions`).
|
|
59
|
+
*
|
|
60
|
+
* @returns A read-only derived store. In the React build, it is also callable as a hook.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createDerivedStore<Derived>(deriveFunction: ($: DeriveGetter) => Derived, optionsOrEqualityFn?: DeriveOptions<Derived>): DerivedStore<Derived>;
|