@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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Stores
|
|
2
2
|
|
|
3
|
-
Stores provides a minimal, reactive state layer
|
|
3
|
+
Stores provides a minimal, reactive state layer that runs with or without React.
|
|
4
4
|
|
|
5
5
|
It defines three types of runtime-evaluated stores—**base**, **derived**, and **query**—each representing a distinct state type: local, computed, or asynchronously fetched. Stores track dependencies at runtime, evaluate lazily, and clean up automatically when unused.
|
|
6
6
|
|
|
@@ -10,10 +10,32 @@ All stores expose a consistent interface and can be used both inside and outside
|
|
|
10
10
|
- **Derived stores** compute values from other stores and re-run only when inputs change.
|
|
11
11
|
- **Query stores** fetch and cache async data, refetching when reactive parameters change.
|
|
12
12
|
|
|
13
|
-
All store types
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
and scale as application
|
|
13
|
+
All store types expose a stable store object with `.getState()` and
|
|
14
|
+
`.subscribe()`, plus optional support for persistence. In the React build,
|
|
15
|
+
stores are also callable hooks. In the vanilla build, stores remain plain store
|
|
16
|
+
objects. They compose naturally, interoperate cleanly, and scale as application
|
|
17
|
+
complexity grows.
|
|
18
|
+
|
|
19
|
+
## Runtime Modes
|
|
20
|
+
|
|
21
|
+
The root import is mode-aware:
|
|
22
|
+
|
|
23
|
+
- React web apps use `@storesjs/stores` by default.
|
|
24
|
+
- React Native apps use `@storesjs/stores`; the `react-native` package condition selects the native build.
|
|
25
|
+
- Vanilla apps use `@storesjs/stores` with the `vanilla` package condition enabled.
|
|
26
|
+
|
|
27
|
+
For TypeScript vanilla projects, use a condition-aware resolver and add the
|
|
28
|
+
same condition to `tsconfig.json`:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"compilerOptions": {
|
|
33
|
+
"module": "ESNext",
|
|
34
|
+
"moduleResolution": "bundler",
|
|
35
|
+
"customConditions": ["vanilla"]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
17
39
|
|
|
18
40
|
## Base Store
|
|
19
41
|
|
|
@@ -21,7 +43,7 @@ A base store defines local state along with an interface for reading and
|
|
|
21
43
|
updating that state.
|
|
22
44
|
|
|
23
45
|
```ts
|
|
24
|
-
export const
|
|
46
|
+
export const settingsStore = createBaseStore<Settings>(set => ({
|
|
25
47
|
currency: 'USD',
|
|
26
48
|
setCurrency: currency => set({ currency }),
|
|
27
49
|
}));
|
|
@@ -30,14 +52,14 @@ export const useSettingsStore = createBaseStore<Settings>(set => ({
|
|
|
30
52
|
In React, subscribe to values with selectors:
|
|
31
53
|
|
|
32
54
|
```ts
|
|
33
|
-
const currency =
|
|
55
|
+
const currency = settingsStore(s => s.currency);
|
|
34
56
|
```
|
|
35
57
|
|
|
36
58
|
Outside React:
|
|
37
59
|
|
|
38
60
|
```ts
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
settingsStore.getState().currency;
|
|
62
|
+
settingsStore.subscribe(selector, listener, options);
|
|
41
63
|
```
|
|
42
64
|
|
|
43
65
|
Enable persistence per store:
|
|
@@ -52,7 +74,7 @@ createBaseStore<Settings>(set => ({ ... }), {
|
|
|
52
74
|
You can also export actions as a stable object:
|
|
53
75
|
|
|
54
76
|
```ts
|
|
55
|
-
export const settingsActions = createStoreActions(
|
|
77
|
+
export const settingsActions = createStoreActions(settingsStore);
|
|
56
78
|
```
|
|
57
79
|
|
|
58
80
|
## Derived Store
|
|
@@ -61,9 +83,9 @@ Derived stores compute values from other stores. The `$` accessor tracks
|
|
|
61
83
|
dependencies at runtime:
|
|
62
84
|
|
|
63
85
|
```ts
|
|
64
|
-
export const
|
|
65
|
-
const { currency } = $(
|
|
66
|
-
const { subtotal, tax } = $(
|
|
86
|
+
export const totalStore = createDerivedStore($ => {
|
|
87
|
+
const { currency } = $(settingsStore);
|
|
88
|
+
const { subtotal, tax } = $(cartStore);
|
|
67
89
|
return formatTotal(currency, subtotal, tax);
|
|
68
90
|
});
|
|
69
91
|
```
|
|
@@ -78,10 +100,10 @@ Query stores manage remote data. They fetch, cache, and revalidate based
|
|
|
78
100
|
on reactive parameters:
|
|
79
101
|
|
|
80
102
|
```ts
|
|
81
|
-
export const
|
|
103
|
+
export const accountStore = createQueryStore<Account, Params>({
|
|
82
104
|
fetcher: fetchAccount,
|
|
83
105
|
params: {
|
|
84
|
-
userId: $ => $(
|
|
106
|
+
userId: $ => $(authStore).userId,
|
|
85
107
|
},
|
|
86
108
|
staleTime: time.minutes(10),
|
|
87
109
|
});
|
|
@@ -93,13 +115,13 @@ idle.
|
|
|
93
115
|
Use it in React:
|
|
94
116
|
|
|
95
117
|
```ts
|
|
96
|
-
const account =
|
|
118
|
+
const account = accountStore(s => s.getData());
|
|
97
119
|
```
|
|
98
120
|
|
|
99
121
|
Or imperatively:
|
|
100
122
|
|
|
101
123
|
```ts
|
|
102
|
-
|
|
124
|
+
accountStore.getState().fetch();
|
|
103
125
|
```
|
|
104
126
|
|
|
105
127
|
Query stores support full customization: extended local state, manual cache control, configurable staleness and retry behavior, and optional persistence.
|
|
@@ -108,22 +130,26 @@ They deduplicate fetches across consumers and compute stable query keys automati
|
|
|
108
130
|
|
|
109
131
|
## Store Interface
|
|
110
132
|
|
|
111
|
-
All stores implement the same API:
|
|
133
|
+
All stores implement the same store-object API:
|
|
112
134
|
|
|
113
135
|
```ts
|
|
114
|
-
|
|
115
|
-
|
|
136
|
+
store.getState()
|
|
137
|
+
store.setState() // Except for derived stores
|
|
138
|
+
store.subscribe(selector, listener, options?)
|
|
139
|
+
```
|
|
116
140
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
In the React build, stores are also callable hooks:
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
store()
|
|
145
|
+
store(selector, equalityFn?)
|
|
120
146
|
```
|
|
121
147
|
|
|
122
148
|
## Composed Example
|
|
123
149
|
|
|
124
150
|
```ts
|
|
125
|
-
export const
|
|
126
|
-
const { currency, locale } = $(
|
|
151
|
+
export const currencyFormatterStore = createDerivedStore($ => {
|
|
152
|
+
const { currency, locale } = $(settingsStore);
|
|
127
153
|
return new Intl.NumberFormat(locale, {
|
|
128
154
|
currency,
|
|
129
155
|
style: 'currency',
|
|
@@ -132,16 +158,16 @@ export const useCurrencyFormatter = createDerivedStore($ => {
|
|
|
132
158
|
```
|
|
133
159
|
|
|
134
160
|
```ts
|
|
135
|
-
export const
|
|
136
|
-
const balance = $(
|
|
137
|
-
const formatter = $(
|
|
161
|
+
export const accountBalanceStore = createDerivedStore($ => {
|
|
162
|
+
const balance = $(accountStore).getData()?.balance ?? 0;
|
|
163
|
+
const formatter = $(currencyFormatterStore);
|
|
138
164
|
return formatter.format(balance);
|
|
139
165
|
});
|
|
140
166
|
```
|
|
141
167
|
|
|
142
168
|
```ts
|
|
143
169
|
function AccountSummary() {
|
|
144
|
-
const balance =
|
|
170
|
+
const balance = accountBalanceStore();
|
|
145
171
|
return <Text>Balance: {balance}</Text>;
|
|
146
172
|
}
|
|
147
173
|
```
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
|
|
1
|
+
import type { BaseStoreOptions, OptionallyPersistedStore, Store, StateCreator } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a base store without persistence.
|
|
4
4
|
* @param createState - The state creator function for the base store.
|
|
5
|
-
* @returns A
|
|
5
|
+
* @returns A store with the specified state.
|
|
6
6
|
*/
|
|
7
7
|
export declare function createBaseStore<S>(createState: StateCreator<S>): Store<S>;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a base store with persistence.
|
|
10
10
|
* @param createState - The state creator function for the base store.
|
|
11
11
|
* @param options - The configuration options for persistence and sync.
|
|
12
|
-
* @returns A
|
|
12
|
+
* @returns A store with the specified state and persistence.
|
|
13
13
|
*/
|
|
14
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
15
|
/**
|
|
16
16
|
* Creates a base store with async persistence.
|
|
17
17
|
* @param createState - The state creator function for the base store.
|
|
18
18
|
* @param options - The configuration options for persistence and sync.
|
|
19
|
-
* @returns A
|
|
19
|
+
* @returns A store with the specified state and persistence.
|
|
20
20
|
*/
|
|
21
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
22
|
/**
|
|
23
23
|
* Creates a base store with optional persistence.
|
|
24
24
|
* @param createState - The state creator function for the base store.
|
|
25
25
|
* @param options - The configuration options for persistence and sync.
|
|
26
|
-
* @returns A
|
|
26
|
+
* @returns A store with the specified state and optional persistence.
|
|
27
27
|
*/
|
|
28
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
29
|
/**
|
|
30
30
|
* Creates a base store with optional async persistence.
|
|
31
31
|
* @param createState - The state creator function for the base store.
|
|
32
32
|
* @param options - The configuration options for persistence and sync.
|
|
33
|
-
* @returns A
|
|
33
|
+
* @returns A store with the specified state and optional persistence.
|
|
34
34
|
*/
|
|
35
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>;
|
|
36
36
|
//# sourceMappingURL=createBaseStore.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DeriveOptions, DerivedStore
|
|
1
|
+
import type { DeriveGetter, DeriveOptions, DerivedStore } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* ### `createDerivedStore`
|
|
4
4
|
*
|
|
5
|
-
* Creates a **read-only** store derived from one or more
|
|
5
|
+
* Creates a **read-only** store derived from one or more source stores.
|
|
6
6
|
*
|
|
7
7
|
* ---
|
|
8
8
|
* The `deriveFunction` is called whenever its dependencies change, producing a new derived state.
|
|
@@ -28,10 +28,10 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
|
|
|
28
28
|
*
|
|
29
29
|
* ---
|
|
30
30
|
* Derived stores automatically unsubscribe from all dependencies when no consumers remain, and
|
|
31
|
-
* resubscribe when new consumers appear. The returned
|
|
31
|
+
* resubscribe when new consumers appear. The returned store exposes:
|
|
32
32
|
*
|
|
33
|
-
* - A **React hook** (`const state = useDerivedStore(selector, equalityFn?)`)
|
|
34
33
|
* - A **store object** with `getState()`, `subscribe()`, and `destroy()`
|
|
34
|
+
* - In the React build, a **React hook** (`const state = derivedStore(selector, equalityFn?)`)
|
|
35
35
|
*
|
|
36
36
|
* ---
|
|
37
37
|
* You can optionally pass a second parameter (either an equality function or a config object)
|
|
@@ -44,28 +44,20 @@ import { DeriveOptions, DerivedStore, EqualityFn, Store, Selector, InferStoreSta
|
|
|
44
44
|
* @example
|
|
45
45
|
* ```ts
|
|
46
46
|
* // Create a derived store
|
|
47
|
-
* const
|
|
48
|
-
* const query = $(
|
|
49
|
-
* const items = $(
|
|
47
|
+
* const searchResultsStore = createDerivedStore($ => {
|
|
48
|
+
* const query = $(searchStore).query.trim().toLowerCase();
|
|
49
|
+
* const items = $(itemsStore).items;
|
|
50
50
|
* return findResults(query, items);
|
|
51
51
|
* }, shallowEqual);
|
|
52
52
|
*
|
|
53
|
-
*
|
|
54
|
-
* // Consume the derived state
|
|
55
|
-
* const results = useSearchResults(); // Or (selector, equalityFn?)
|
|
56
|
-
* return <ResultsList items={results} />;
|
|
57
|
-
* }
|
|
53
|
+
* const results = searchResultsStore.getState();
|
|
58
54
|
* ```
|
|
59
55
|
*
|
|
60
56
|
* ---
|
|
61
57
|
* @param deriveFunction - Function that reads from other stores via `$` to produce derived state.
|
|
62
58
|
* @param optionsOrEqualityFn - Either an equality function or a config object (see `DeriveOptions`).
|
|
63
59
|
*
|
|
64
|
-
* @returns A read-only derived store
|
|
60
|
+
* @returns A read-only derived store. In the React build, it is also callable as a hook.
|
|
65
61
|
*/
|
|
66
62
|
export declare function createDerivedStore<Derived>(deriveFunction: ($: DeriveGetter) => Derived, optionsOrEqualityFn?: DeriveOptions<Derived>): DerivedStore<Derived>;
|
|
67
|
-
export type DeriveGetter = {
|
|
68
|
-
<S extends Store<unknown>>(store: S): InferStoreState<S>;
|
|
69
|
-
<S extends Store<unknown>, Selected>(store: S, selector: Selector<InferStoreState<S>, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
70
|
-
};
|
|
71
63
|
//# sourceMappingURL=createDerivedStore.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { QueryStoreConfig, QueryStoreState } from './queryStore/types';
|
|
3
|
-
import { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
|
|
1
|
+
import { defaultRetryDelay } from './internal/runtime';
|
|
2
|
+
import type { QueryStoreConfig, QueryStoreState } from './queryStore/types';
|
|
3
|
+
import type { BaseStoreOptions, OptionallyPersistedStore, PersistedStore, StateCreator, Store } from './types';
|
|
4
|
+
export { defaultRetryDelay };
|
|
4
5
|
/**
|
|
5
6
|
* Creates a persisted, query-enabled store with data fetching capabilities (sync storage).
|
|
6
7
|
*
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DeriveGetter } from './
|
|
2
|
-
import { BaseStore, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
|
|
1
|
+
import type { BaseStore, DeriveGetter, InferPersistedState, InferSetStateReturn, InferStoreState, OptionallyPersistedStore } from './types';
|
|
3
2
|
type MethodOverrides<Store extends BaseStore<unknown>> = Partial<Pick<Store, 'getState' | 'setState'>>;
|
|
4
3
|
type VirtualStore<Store extends BaseStore<unknown>> = OptionallyPersistedStore<InferStoreState<Store>, InferPersistedState<Store>, InferSetStateReturn<Store>>;
|
|
5
4
|
type VirtualStoreOptions = {
|
package/dist/env.native.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { unstable_batchedUpdates } from 'react-native';
|
|
2
1
|
export declare const IS_REACT_NATIVE = true;
|
|
3
2
|
export declare const IS_BROWSER = false;
|
|
4
3
|
export declare const IS_IOS: boolean;
|
|
5
4
|
export declare const IS_ANDROID: boolean;
|
|
6
5
|
export declare const IS_DEV: boolean;
|
|
7
6
|
export declare const IS_TEST: boolean;
|
|
8
|
-
export { unstable_batchedUpdates };
|
|
9
7
|
//# sourceMappingURL=env.native.d.ts.map
|
package/dist/env.web.d.ts
CHANGED
|
@@ -4,5 +4,4 @@ export declare const IS_IOS = false;
|
|
|
4
4
|
export declare const IS_ANDROID = false;
|
|
5
5
|
export declare const IS_DEV: boolean;
|
|
6
6
|
export declare const IS_TEST: boolean;
|
|
7
|
-
export declare const unstable_batchedUpdates: <T>(callback: () => T) => T;
|
|
8
7
|
//# sourceMappingURL=env.web.d.ts.map
|
|
@@ -61,7 +61,7 @@ export type UseListenOptions<Selected> = {
|
|
|
61
61
|
/**
|
|
62
62
|
* ### `useListen`
|
|
63
63
|
*
|
|
64
|
-
* Subscribes to a slice of a
|
|
64
|
+
* Subscribes to a slice of a store and runs a callback whenever that slice changes,
|
|
65
65
|
* **without triggering re-renders**.
|
|
66
66
|
*
|
|
67
67
|
* Useful for forwarding updates to non-React state (e.g. Reanimated shared values), scoped side
|
|
@@ -75,7 +75,7 @@ export type UseListenOptions<Selected> = {
|
|
|
75
75
|
* They take effect only if a resubscription occurs.
|
|
76
76
|
*
|
|
77
77
|
* ---
|
|
78
|
-
* @param store -
|
|
78
|
+
* @param store - Store to listen to. Should be a stable reference.
|
|
79
79
|
* @param selector - Selects the slice of the store state to listen to.
|
|
80
80
|
* @param react - Triggered when the selected slice changes. Receives `(current, previous, unsubscribe)`.
|
|
81
81
|
* @param optionsOrEqualityFn - Optional `equalityFn`, `fireImmediately` settings, forwarded to `store.subscribe`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createBaseStore } from './createBaseStore';
|
|
3
|
-
export * from './createDerivedStore';
|
|
4
|
-
export * from './createQueryStore';
|
|
5
|
-
export * from './createVirtualStore';
|
|
6
|
-
export { StoresError } from './errors';
|
|
7
|
-
export { replacer, reviver } from './utils/serialization';
|
|
8
|
-
export { applyStateUpdate, destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './utils/storeUtils';
|
|
1
|
+
export * from './index.shared';
|
|
9
2
|
export * from './hooks/useListen';
|
|
10
3
|
export * from './hooks/useStableValue';
|
|
11
|
-
export * from './sync/types';
|
|
12
|
-
export * from './queryStore/types';
|
|
13
|
-
export * from './storage/storageTypes';
|
|
14
|
-
export * from './types';
|
|
15
|
-
export { identity, nullObject } from './utils/core';
|
|
16
|
-
export * from './utils/createStoreActions';
|
|
17
|
-
export { deepEqual, shallowEqual } from './utils/equality';
|
|
18
|
-
export { time } from './utils/time';
|
|
19
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './createBaseStore';
|
|
2
|
+
export * from './createDerivedStore';
|
|
3
|
+
export * from './createQueryStore';
|
|
4
|
+
export * from './createVirtualStore';
|
|
5
|
+
export { configureStores, StoresError } from './internal/runtime';
|
|
6
|
+
export { applyStateUpdate, replacer, reviver } from './internal/runtime';
|
|
7
|
+
export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './internal/runtime';
|
|
8
|
+
export type * from './sync/types';
|
|
9
|
+
export { QueryStatuses } from './internal/runtime';
|
|
10
|
+
export type * from './queryStore/types';
|
|
11
|
+
export type * from './storage/storageTypes';
|
|
12
|
+
export type * from './types';
|
|
13
|
+
export { createStoreActions, deepEqual, identity, nullObject, shallowEqual, time } from './internal/runtime';
|
|
14
|
+
//# sourceMappingURL=index.shared.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { QueryStoreConfig } from '../queryStore/types';
|
|
2
|
+
import { SyncEngine } from '../sync/types';
|
|
3
|
+
import { AsyncStorageInterface, SyncStorageInterface } from '../types';
|
|
4
|
+
import { NonFunction } from '../types/functions';
|
|
5
|
+
import { Prettify } from '../types/objects';
|
|
1
6
|
import { Logger } from './logger';
|
|
2
|
-
import { QueryStoreConfig } from './queryStore/types';
|
|
3
|
-
import { SyncEngine } from './sync/types';
|
|
4
|
-
import { AsyncStorageInterface, SyncStorageInterface } from './types';
|
|
5
|
-
import { NonFunction } from './types/functions';
|
|
6
|
-
import { Prettify } from './types/objects';
|
|
7
7
|
/**
|
|
8
8
|
* Global configuration for all stores.
|
|
9
9
|
*/
|
|
@@ -44,9 +44,6 @@ export type QueryStoreDefaults = Prettify<ConfigDefaults<QueryStoreConfig<unknow
|
|
|
44
44
|
type ConfigDefaults<C, Excluded extends keyof C = never, AllowedFunctions extends keyof C = never> = Omit<{
|
|
45
45
|
[K in keyof C as K extends AllowedFunctions ? K : NonFunction<C[K]> extends undefined ? never : K]?: K extends AllowedFunctions ? C[K] : NonFunction<C[K]>;
|
|
46
46
|
}, Excluded>;
|
|
47
|
-
type Options = Pick<StoresConfig, 'queryStoreDefaults'>;
|
|
48
|
-
type StorageConfig = Pick<StoresConfig, 'storage' | 'syncEngine'>;
|
|
49
|
-
export declare const DEFAULT_STORAGE_KEY_PREFIX = "stores:";
|
|
50
47
|
/**
|
|
51
48
|
* Configures global defaults for all stores.
|
|
52
49
|
*
|
|
@@ -63,8 +60,5 @@ export declare const DEFAULT_STORAGE_KEY_PREFIX = "stores:";
|
|
|
63
60
|
* ```
|
|
64
61
|
*/
|
|
65
62
|
export declare function configureStores(config: Partial<StoresConfig>): void;
|
|
66
|
-
export declare function getOptions(): Options | undefined;
|
|
67
|
-
export declare function getStorageConfig(): StorageConfig;
|
|
68
|
-
export declare function markStoreCreated(): void;
|
|
69
63
|
export {};
|
|
70
64
|
//# sourceMappingURL=config.d.ts.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { StoreApi } from '
|
|
2
|
-
import { InferStoreState } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export type StoreActions<Store extends StoreApi<unknown>> = Pick<InferStoreState<Store>, FunctionKeys<InferStoreState<Store>>>;
|
|
1
|
+
import type { StoreApi } from '../store/types';
|
|
2
|
+
import type { InferStoreState, StoreActions } from '../types';
|
|
3
|
+
import type { FunctionRecord } from '../types/functions';
|
|
4
|
+
import type { NoOverlap } from '../types/objects';
|
|
6
5
|
/**
|
|
7
6
|
* Given a store instance, produces a new object containing only its actions.
|
|
8
7
|
*
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { BaseStore } from '
|
|
1
|
+
import { BaseStore } from '../../types';
|
|
2
2
|
import { TrackPathFn } from './pathFinder';
|
|
3
3
|
/**
|
|
4
4
|
* Gets or creates a lightweight tracking proxy that records path access and store
|
|
5
5
|
* method invocations via proxy traps. Used to auto-generate selectors that point
|
|
6
6
|
* to either the accessed path or the value returned by an invoked store method.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getOrCreateProxy<S>(store: BaseStore<S>, rootProxyCache: WeakMap<
|
|
8
|
+
export declare function getOrCreateProxy<S>(store: BaseStore<S>, rootProxyCache: WeakMap<object, unknown>, trackPath: TrackPathFn): S;
|
|
9
9
|
/**
|
|
10
10
|
* Strips tracking proxies from published values to ensure
|
|
11
11
|
* proxies remain confined to internal tracking contexts.
|
|
@@ -7,8 +7,4 @@ export declare class StoresError extends Error {
|
|
|
7
7
|
cause?: unknown;
|
|
8
8
|
constructor(message: string, cause?: unknown);
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Normalizes unknown thrown values for store state and promise rejection paths.
|
|
12
|
-
*/
|
|
13
|
-
export declare function ensureError(error: unknown): Error;
|
|
14
10
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -7,6 +7,4 @@ export interface Logger {
|
|
|
7
7
|
info: (message: string, context?: Record<string, unknown>) => void;
|
|
8
8
|
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
9
9
|
}
|
|
10
|
-
export declare let logger: Logger;
|
|
11
|
-
export declare function setLogger(customLogger: Logger): void;
|
|
12
10
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StateCreator } from '../../types';
|
|
2
|
+
import { SyncContext } from '../sync/syncEnhancer';
|
|
3
|
+
type WrappedOnRehydrateStorage<S> = (userCallback: ((state: S) => ((finalState?: S, error?: unknown) => void) | void) | undefined, syncContext: SyncContext | undefined) => (state: S) => (finalState?: S, error?: unknown) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Creates hydration-gating middleware that queues state updates until rehydration completes.
|
|
6
|
+
*
|
|
7
|
+
* **Before hydration**: Queues all `set()` calls and flushes them sequentially after rehydration.
|
|
8
|
+
*
|
|
9
|
+
* **After hydration**: Passes `set()` calls through synchronously without batching.
|
|
10
|
+
*
|
|
11
|
+
* This ensures persistence sees a fully rehydrated base state before applying queued updates,
|
|
12
|
+
* while keeping in-memory state changes synchronous post-hydration.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createHydrationGate<S>(stateCreator: StateCreator<S>): {
|
|
15
|
+
hydrationPromise: () => Promise<void>;
|
|
16
|
+
stateCreator: StateCreator<S>;
|
|
17
|
+
wrapOnRehydrateStorage: WrappedOnRehydrateStorage<S>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=createHydrationGate.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Prettify } from '../../types/objects';
|
|
2
|
+
import { QueryStoreDefaults } from '../config';
|
|
3
|
+
export declare function getQueryStoreDefaults(): Prettify<Required<QueryStoreDefaults>>;
|
|
4
|
+
/**
|
|
5
|
+
* Exponential backoff: starts at `baseDelay` (5s), doubles each retry, capped at `maxDelay` (5m).
|
|
6
|
+
*/
|
|
7
|
+
export declare function defaultRetryDelay(retryCount: number): number;
|
|
8
|
+
//# sourceMappingURL=queryStoreDefaults.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { configureStores } from './config';
|
|
2
|
+
export { StoresError } from './errors';
|
|
3
|
+
export { QueryStatuses } from '../queryStore/types';
|
|
4
|
+
export { defaultRetryDelay } from './queryStore/queryStoreDefaults';
|
|
5
|
+
export { getQueryKey, parseQueryKey } from '../queryStore/queryKey';
|
|
6
|
+
export { applyStateUpdate } from '../store/stateUpdate';
|
|
7
|
+
export { replacer, reviver } from '../utils/serialization';
|
|
8
|
+
export { destroyStore, destroyStores, getStoreName, hasGetSnapshot, isDerivedStore, isPersistedStore, isQueryStore, isVirtualStore, } from './storeUtils';
|
|
9
|
+
export { identity, nullObject } from '../utils/core';
|
|
10
|
+
export { createStoreActions } from './createStoreActions';
|
|
11
|
+
export { deepEqual, shallowEqual } from '../utils/equality';
|
|
12
|
+
export { time } from '../utils/time';
|
|
13
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AttachValue } from '../queryStore/signalTypes';
|
|
2
|
+
import type { StoreApi } from '../store/types';
|
|
3
|
+
import type { EqualityFn, Selector, UnsubscribeFn } from '../types/subscribe';
|
|
4
|
+
export declare const attachValueSubscriptionMap: WeakMap<AttachValue<unknown>, Subscribe>;
|
|
5
|
+
export type Subscribe = (callback: () => void) => UnsubscribeFn;
|
|
6
|
+
export type GetValue = () => unknown;
|
|
7
|
+
export type SetValue = (path: unknown[], value: unknown) => void;
|
|
8
|
+
export declare function $<T>(store: StoreApi<T>): AttachValue<T>;
|
|
9
|
+
export declare function $<T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn?: EqualityFn<S>): AttachValue<S>;
|
|
10
|
+
export declare const createSignal: <T, S>(store: StoreApi<T>, selector: Selector<T, S>, equalityFn: EqualityFn<S>) => [Subscribe, GetValue, SetValue];
|
|
11
|
+
export declare function getAttachValueSubscribeFn<AttachVal extends AttachValue<unknown>>(attachVal: AttachVal): Subscribe | undefined;
|
|
12
|
+
//# sourceMappingURL=signal.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AsyncPersistStorage, PersistStorageConfig } from '../../store/types';
|
|
2
|
+
import type { AsyncStorageInterface, BaseStoreOptions, EnforceStorageKey, SyncStorageInterface } from '../../types';
|
|
3
|
+
import type { SyncContext } from '../sync/syncEnhancer';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a persist storage object for the base store.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, storage: AsyncStorageInterface | SyncStorageInterface | undefined, syncContext: SyncContext | undefined): PersistStorageConfig<S, PersistedState>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an asynchronous persist storage adapter.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAsyncPersistStorage<S, PersistedState extends Partial<S>, PersistReturn>(storage: AsyncStorageInterface, options: EnforceStorageKey<BaseStoreOptions<S, PersistedState, PersistReturn>>, persistThrottleMs: number | undefined, syncContext?: SyncContext): AsyncPersistStorage<S, PersistedState>;
|
|
12
|
+
//# sourceMappingURL=storageCreators.d.ts.map
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BaseStore, InferStoreState, PersistedStore
|
|
4
|
-
export declare const StoreTags: Readonly<{
|
|
5
|
-
QueryStore: symbol;
|
|
6
|
-
VirtualStore: symbol;
|
|
7
|
-
}>;
|
|
8
|
-
type StoreTag = (typeof StoreTags)[keyof typeof StoreTags];
|
|
9
|
-
export declare function assignStoreTag<S>(store: BaseStore<S>, tag: StoreTag): BaseStore<S>;
|
|
10
|
-
/**
|
|
11
|
-
* Helper that applies a `setState` update to the provided state.
|
|
12
|
-
* Handles the `setState` discriminated union types internally.
|
|
13
|
-
*/
|
|
14
|
-
export declare function applyStateUpdate<S>(state: S, ...setArgs: SetStateArgs<S>): S;
|
|
1
|
+
import type { QueryStore, QueryStoreState } from '../queryStore/types';
|
|
2
|
+
import type { StoreApi } from '../store/types';
|
|
3
|
+
import type { BaseStore, InferStoreState, PersistedStore } from '../types';
|
|
15
4
|
/**
|
|
16
5
|
* Calls the appropriate reset or destroy method on the store, if available.
|
|
17
6
|
* Handles both `DerivedStore` and `QueryStore`.
|
|
@@ -27,12 +16,6 @@ export declare function destroyStores(stores: Partial<Record<string, BaseStore<u
|
|
|
27
16
|
* Returns the name of the store, either from the `persist` options or the store itself.
|
|
28
17
|
*/
|
|
29
18
|
export declare function getStoreName(store: BaseStore<unknown>): string;
|
|
30
|
-
/**
|
|
31
|
-
* Checks if a store has a `destroy` method.
|
|
32
|
-
*/
|
|
33
|
-
export declare function hasDestroy<T extends StoreApi<unknown>>(store: T): store is T & {
|
|
34
|
-
destroy: () => void;
|
|
35
|
-
};
|
|
36
19
|
/**
|
|
37
20
|
* Checks if a store is a `DerivedStore` and reveals its internal `getSnapshot` method.
|
|
38
21
|
*/
|
|
@@ -60,5 +43,4 @@ export declare function isPersistedStore<T extends BaseStore<unknown> | Persiste
|
|
|
60
43
|
* Checks if a store is a virtual store.
|
|
61
44
|
*/
|
|
62
45
|
export declare function isVirtualStore<T extends BaseStore<unknown> | StoreApi<unknown>>(store: T): store is T & BaseStore<InferStoreState<T>>;
|
|
63
|
-
export {};
|
|
64
46
|
//# sourceMappingURL=storeUtils.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NormalizedSyncConfig } from '../../sync/types';
|
|
2
|
+
import { StateCreator } from '../../types';
|
|
3
|
+
export type SyncContext = {
|
|
4
|
+
isAsync: boolean;
|
|
5
|
+
clearFieldTimestamps: (snapshot: Record<string, number> | undefined) => void;
|
|
6
|
+
getFieldTimestampSnapshot: () => Record<string, number> | undefined;
|
|
7
|
+
getIsApplyingRemote: () => boolean;
|
|
8
|
+
getSessionId: () => string | undefined;
|
|
9
|
+
getTimestamp: () => number | undefined;
|
|
10
|
+
mergeFieldTimestamps: (fields: Record<string, number>) => void;
|
|
11
|
+
onHydrationComplete: (() => void) | undefined;
|
|
12
|
+
onHydrationFlushEnd: (() => void) | undefined;
|
|
13
|
+
setIsApplyingRemote: (value: boolean) => void;
|
|
14
|
+
setSessionId: (sessionId: string) => void;
|
|
15
|
+
setTimestamp: (timestamp: number) => void;
|
|
16
|
+
setWithoutPersist: (<_T extends (..._: unknown[]) => void | Promise<void>, Args extends unknown[]>(..._: Args) => void | Promise<void>) | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare function createSyncedStateCreator<T extends Record<string, unknown>>(stateCreator: StateCreator<T>, config: NormalizedSyncConfig<T>, isAsync: boolean): {
|
|
19
|
+
stateCreator: StateCreator<T>;
|
|
20
|
+
syncContext: SyncContext;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Readable indices for `FieldMetadata` tuples.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TIMESTAMP: 0, SESSION_ID: 1;
|
|
26
|
+
//# sourceMappingURL=syncEnhancer.d.ts.map
|