@pitboxdev/dynamic-store-zustand 0.0.2 → 0.0.3

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 CHANGED
@@ -26,33 +26,42 @@
26
26
 
27
27
  ---
28
28
 
29
- ## Features
29
+ ## Features
30
30
 
31
- - **Zero Boilerplate:** No more complex setups or switch-statements.
31
+ - 🛠️ **DX First (Zero Boilerplate):** Extremely simple API without boilerplate, keeping the standard React `useState` ergonomics.
32
32
  - 🧹 **Auto-Cleanup:** Built-in hooks for automatic store resets on unmount.
33
+ - ⚡ **High Performance:** Subscription-free hooks available (`useDynamicStoreMethods`) to read and update state without component re-renders.
33
34
  - 🔄 **Functional Updaters:** Handles race conditions naturally with `setData(prev => ...)`.
34
- - 🛡️ **Fully Typed:** Inferred TypeScript definitions out of the box with strict mode support.
35
+ - 🛡️ **100% Type-safe:** Written in TypeScript with pristine type inference and autocomplete out of the box.
35
36
  - 🪶 **Tiny Footprint:** Minimal addition to your bundle size.
36
37
 
37
38
  ---
38
39
 
40
+ ## ❓ Motivation
41
+
42
+ Modern frontend applications often suffer from state management boilerplate and bloated global stores. Setting up stores usually requires defining schemas upfront, creating actions, and wiring things together.
43
+
44
+ The main motivation behind this package is to **drastically reduce boilerplate and simplify store management for maximum efficiency**.
45
+
46
+ Whether you need to generate stores dynamically on the fly or just want the simplicity of `useState` with the power of a scalable global store, this API delivers a seamless, hassle-free experience.
47
+
48
+ ---
49
+
39
50
  ## Table of Contents
40
51
 
41
- - [Features](#features)
52
+ - [Features](#-features)
53
+ - [❓ Motivation](#-motivation)
42
54
  - [Overview](#overview)
43
55
  - [Installation](#installation)
44
- - [API 1 — `createDynamicStore`](#api-1--createdynamicstore)
56
+ - [`useDynamicStore`](#usedynamicstore)
45
57
  - [Quick Start](#quick-start)
46
- - [Outside React](#outside-react)
47
- - [TypeScript](#typescript)
48
- - [API 2 — `useDynamicStore`](#api-2--usedynamicstore)
49
- - [Quick Start](#quick-start-1)
50
58
  - [Functional updater (`setData`)](#functional-updater-setdata)
51
- - [Auto-cleanup with `useDynamicStoreWithCleanup`](#auto-cleanup-with-usedynamicstorewithcleanup)
52
- - [Imperative helpers (outside React)](#imperative-helpers-outside-react)
53
- - [Config options](#config-options)
54
- - [TypeScript](#typescript-1)
55
- - [When to use which API](#when-to-use-which-api)
59
+ - [Examples](#examples)
60
+ - [`useDynamicStoreWithCleanup`](#usedynamicstorewithcleanup)
61
+ - [`useDynamicStoreMethods` (No Subscription)](#usedynamicstoremethods-no-subscription)
62
+ - [Imperative helpers (outside React)](#imperative-helpers-outside-react)
63
+ - [Config options](#config-options)
64
+ - [TypeScript](#typescript)
56
65
  - [Full API Reference](#full-api-reference)
57
66
  - [Contributing](#contributing)
58
67
  - [License](#license)
@@ -61,17 +70,15 @@
61
70
 
62
71
  ## Overview
63
72
 
64
- The package ships **two independent APIs** that can be used separately or together:
73
+ `@pitboxdev/dynamic-store-zustand` provides dynamic store management for React applications. It is built on top of [Zustand](https://github.com/pmndrs/zustand) and exposes a hook API that feels exactly like React's `useState`, with the addition that stores are stored globally in a single shared registry keyed by a string `storeId`.
65
74
 
66
- | | `createDynamicStore` | `useDynamicStore` |
67
- |---|---|---|
68
- | Style | Factory function | React hook |
69
- | Stores | One Zustand store per call | All stores live in a single registry |
70
- | Actions | Explicit, typed | Implicit via `setData` |
71
- | Functional updater | Via `set((s) => …)` in actions | Built-in `setData((prev) => …)` |
72
- | Auto-cleanup | | `useDynamicStoreWithCleanup` |
73
- | Navigation persistence | — | `persistOnNavigation` config flag |
74
- | Best for | Permanent, feature-level stores | Page/form/modal scoped state |
75
+ | Feature | Description |
76
+ |---|---|
77
+ | **Dynamic initialization** | Stores are initialized just-in-time when the hook mounts |
78
+ | **useState-like API** | `setData(obj)` or `setData((prev) => update)` |
79
+ | **Auto-cleanup** | `useDynamicStoreWithCleanup` resets state on unmount |
80
+ | **Navigation reset** | Non-persistent stores reset via imperative API on route changes |
81
+ | **Imperative helpers** | Modify and reset stores outside React components |
75
82
 
76
83
  ---
77
84
 
@@ -89,99 +96,7 @@ pnpm add @pitboxdev/dynamic-store-zustand zustand
89
96
 
90
97
  ---
91
98
 
92
- ## API 1 — `createDynamicStore`
93
-
94
- A factory function that creates a standalone, fully typed Zustand store from a configuration object with explicit actions.
95
-
96
- ### Quick Start
97
-
98
- ```tsx
99
- import { createDynamicStore } from "@pitboxdev/dynamic-store-zustand";
100
-
101
- const { useStore } = createDynamicStore({
102
- initialState: { count: 0 },
103
- actions: (set) => ({
104
- increment: () => set((s) => ({ count: s.count + 1 })),
105
- decrement: () => set((s) => ({ count: s.count - 1 })),
106
- reset: () => set({ count: 0 }),
107
- }),
108
- });
109
-
110
- function Counter() {
111
- const count = useStore((s) => s.count);
112
- const { increment, decrement, reset } = useStore();
113
-
114
- return (
115
- <div>
116
- <button onClick={decrement}>-</button>
117
- <span>{count}</span>
118
- <button onClick={increment}>+</button>
119
- <button onClick={reset}>Reset</button>
120
- </div>
121
- );
122
- }
123
- ```
124
-
125
- ### Outside React
126
-
127
- ```ts
128
- const { store } = createDynamicStore({ initialState: { count: 0 }, actions: (set) => ({
129
- increment: () => set((s) => ({ count: s.count + 1 })),
130
- }) });
131
-
132
- // Read
133
- const count = store.getState().count;
134
-
135
- // Write
136
- store.setState({ count: 42 });
137
-
138
- // Subscribe
139
- const unsub = store.subscribe((state) => console.log(state.count));
140
- unsub();
141
- ```
142
-
143
- ### TypeScript
144
-
145
- All types are inferred automatically. You can also define them explicitly:
146
-
147
- ```ts
148
- import {
149
- createDynamicStore,
150
- type DynamicStoreConfig,
151
- } from "@pitboxdev/dynamic-store-zustand";
152
-
153
- interface CounterState { count: number }
154
- interface CounterActions {
155
- increment: () => void;
156
- decrement: () => void;
157
- reset: () => void;
158
- }
159
-
160
- const config: DynamicStoreConfig<CounterState, CounterActions> = {
161
- initialState: { count: 0 },
162
- actions: (set) => ({
163
- increment: () => set((s) => ({ count: s.count + 1 })),
164
- decrement: () => set((s) => ({ count: s.count - 1 })),
165
- reset: () => set({ count: 0 }),
166
- }),
167
- };
168
-
169
- const { useStore, store } = createDynamicStore(config);
170
- ```
171
-
172
- Using multiple selectors with shallow equality:
173
-
174
- ```ts
175
- import { useShallow } from "zustand/react/shallow";
176
-
177
- const { count, increment } = useStore(
178
- useShallow((s) => ({ count: s.count, increment: s.increment }))
179
- );
180
- ```
181
-
182
- ---
183
-
184
- ## API 2 — `useDynamicStore`
99
+ ## `useDynamicStore`
185
100
 
186
101
  A hook that stores state in a single shared registry keyed by a string `storeId`. `setData` works exactly like React's `useState` setter — it accepts either a partial object or a function that receives the previous state.
187
102
 
@@ -250,6 +165,8 @@ setData((prev) => ({ value: prev.value + 1 }));
250
165
 
251
166
  Always prefer the functional form when the new state depends on the old state.
252
167
 
168
+ ### Examples
169
+
253
170
  #### Todo list example
254
171
 
255
172
  ```tsx
@@ -320,7 +237,9 @@ function Cart() {
320
237
  }
321
238
  ```
322
239
 
323
- ### Auto-cleanup with `useDynamicStoreWithCleanup`
240
+ ---
241
+
242
+ ## `useDynamicStoreWithCleanup`
324
243
 
325
244
  `useDynamicStoreWithCleanup` works identically to `useDynamicStore` but resets the store when the component unmounts — useful for modal dialogs, wizard steps, or edit forms.
326
245
 
@@ -337,7 +256,41 @@ function EditModal() {
337
256
  }
338
257
  ```
339
258
 
340
- ### Imperative helpers (outside React)
259
+ ---
260
+
261
+ ## `useDynamicStoreMethods` (No Subscription)
262
+
263
+ If you need to update or read the store **without subscribing to its changes** (to avoid component re-renders), you can use `useDynamicStoreMethods`:
264
+
265
+ ```tsx
266
+ import { useDynamicStoreMethods } from "@pitboxdev/dynamic-store-zustand";
267
+
268
+ function Controls() {
269
+ // This component will NOT re-render when 'counter' state changes!
270
+ const { setData, reset, get } = useDynamicStoreMethods<CounterState>("counter");
271
+
272
+ const increment = () => {
273
+ // Both forms work just like in the regular hook:
274
+ setData((prev) => ({ value: prev.value + 1 }));
275
+ };
276
+
277
+ const logCurrent = () => {
278
+ console.log("Current state:", get()); // Get current state without subscribing
279
+ };
280
+
281
+ return (
282
+ <div>
283
+ <button onClick={increment}>Increment</button>
284
+ <button onClick={logCurrent}>Log State</button>
285
+ <button onClick={reset}>Reset</button>
286
+ </div>
287
+ );
288
+ }
289
+ ```
290
+
291
+ ---
292
+
293
+ ## Imperative helpers (outside React)
341
294
 
342
295
  All helpers call into the shared manager directly — no hook required.
343
296
 
@@ -362,7 +315,9 @@ resetAllDynamicStores();
362
315
  resetNonPersistentDynamicStores();
363
316
  ```
364
317
 
365
- ### Config options
318
+ ---
319
+
320
+ ## Config options
366
321
 
367
322
  | Option | Type | Default | Description |
368
323
  |---|---|---|---|
@@ -370,7 +325,9 @@ resetNonPersistentDynamicStores();
370
325
  | `persistOnNavigation` | `boolean` | `false` | Skip reset when `resetNonPersistentDynamicStores()` is called |
371
326
  | `resetOnUnmount` | `boolean` | `false` | Auto-reset when the component unmounts (`useDynamicStoreWithCleanup` only) |
372
327
 
373
- ### TypeScript
328
+ ---
329
+
330
+ ## TypeScript
374
331
 
375
332
  ```ts
376
333
  import {
@@ -413,56 +370,8 @@ function RegistrationForm() {
413
370
 
414
371
  ---
415
372
 
416
- ## When to use which API
417
-
418
- ### Use `createDynamicStore` when you need:
419
-
420
- - A **permanent, feature-level store** (auth, theme, user profile, global UI)
421
- - **Explicit, named actions** that encapsulate business logic
422
- - **Fine-grained selectors** and subscriptions outside React
423
- - The full Zustand API (middleware, persist, devtools, subscribe)
424
-
425
- ```ts
426
- // auth.store.ts
427
- export const { useStore: useAuthStore, store: authStore } = createDynamicStore({
428
- initialState: { user: null as User | null, token: "" },
429
- actions: (set) => ({
430
- login: (user: User, token: string) => set({ user, token }),
431
- logout: () => set({ user: null, token: "" }),
432
- }),
433
- });
434
- ```
435
-
436
- ### Use `useDynamicStore` when you need:
437
-
438
- - **Page / route / modal scoped state** with optional auto-cleanup
439
- - **useState-like ergonomics** without boilerplate action definitions
440
- - **Multiple stores** managed centrally with shared reset helpers
441
- - Quick iteration when action interfaces aren't stable yet
442
-
443
- ```tsx
444
- // Inside a wizard step component
445
- const { data, setData } = useDynamicStoreWithCleanup<StepState>(
446
- "wizard-step-2",
447
- { initialState: { selection: null }, resetOnUnmount: true }
448
- );
449
- ```
450
-
451
- ---
452
-
453
373
  ## Full API Reference
454
374
 
455
- ### `createDynamicStore(config)`
456
-
457
- | Parameter | Type | Description |
458
- |---|---|---|
459
- | `config.initialState` | `TState` | Plain object representing the initial state |
460
- | `config.actions` | `(set, get) => TActions` | Factory that returns named action implementations |
461
-
462
- Returns `{ useStore, store }`.
463
-
464
- ---
465
-
466
375
  ### `useDynamicStore<T>(storeId, config?)`
467
376
 
468
377
  | Parameter | Type | Description |
@@ -480,11 +389,18 @@ Same signature as `useDynamicStore`. Calls `reset()` on component unmount when `
480
389
 
481
390
  ---
482
391
 
392
+ ### `useDynamicStoreMethods<T>(storeId, config?)`
393
+
394
+ Returns `{ setData, reset, get }` bound to the store, without subscribing the component to state changes.
395
+
396
+ ---
397
+
483
398
  ### Imperative helpers
484
399
 
485
400
  | Function | Signature | Description |
486
401
  |---|---|---|
487
402
  | `updateDynamicStore` | `(storeId, data) => void` | Merge data into a store from outside React |
403
+ | `getDynamicStoreData` | `(storeId) => T \| undefined` | Retrieve a store's current state from outside React |
488
404
  | `resetDynamicStore` | `(storeId) => void` | Reset one store to its `initialState` |
489
405
  | `resetAllDynamicStores` | `() => void` | Reset every registered store |
490
406
  | `resetNonPersistentDynamicStores` | `() => void` | Reset stores where `persistOnNavigation` is not `true` |
@@ -496,14 +412,11 @@ Same signature as `useDynamicStore`. Calls `reset()` on component unmount when `
496
412
  | Type | Description |
497
413
  |---|---|
498
414
  | `StoreState` | `Record<string, unknown>` — base constraint for state objects |
499
- | `StoreActions` | `Record<string, (...args) => unknown>` — base constraint for action maps |
500
- | `DynamicStoreConfig<TState, TActions>` | Config type for `createDynamicStore` |
501
- | `DynamicStore<TState, TActions>` | Return type of `createDynamicStore` |
502
- | `StoreSlice<TState, TActions>` | Merged state + actions type |
503
415
  | `StoreConfig<T>` | Config type for `useDynamicStore` |
504
416
  | `SetStateAction<T>` | `Partial<T> \| ((prev: T) => Partial<T>)` — setter argument type |
505
417
  | `DynamicStoreRegistry` | Internal registry entry (advanced use) |
506
418
  | `UseDynamicStoreReturn<T>` | Return type of `useDynamicStore` |
419
+ | `UseDynamicStoreMethodsReturn<T>` | Return type of `useDynamicStoreMethods` |
507
420
 
508
421
  ---
509
422
 
package/dist/index.d.mts CHANGED
@@ -1,5 +1,3 @@
1
- import { UseBoundStore, StoreApi } from 'zustand';
2
-
3
1
  /**
4
2
  * Updater argument for setData — either a partial object or a function
5
3
  * that receives the previous state and returns a partial object.
@@ -30,55 +28,23 @@ interface DynamicStoreRegistry {
30
28
  * Keys are strings, values can be anything.
31
29
  */
32
30
  type StoreState = Record<string, unknown>;
33
- /**
34
- * Actions are functions attached to the store.
35
- */
36
- type StoreActions = Record<string, (...args: unknown[]) => unknown>;
37
- /**
38
- * Full store slice = state + actions.
39
- */
40
- type StoreSlice<TState extends StoreState = StoreState, TActions extends StoreActions = StoreActions> = TState & TActions;
41
- /**
42
- * Configuration object passed to createDynamicStore.
43
- */
44
- interface DynamicStoreConfig<TState extends StoreState, TActions extends StoreActions> {
45
- /** Initial state values */
46
- initialState: TState;
47
- /** Factory that receives `set` and `get` and returns action implementations */
48
- actions: (set: StoreApi<StoreSlice<TState, TActions>>["setState"], get: StoreApi<StoreSlice<TState, TActions>>["getState"]) => TActions;
49
- }
50
- /**
51
- * The return type of createDynamicStore.
52
- */
53
- interface DynamicStore<TState extends StoreState, TActions extends StoreActions> {
54
- /** Zustand React hook */
55
- useStore: UseBoundStore<StoreApi<StoreSlice<TState, TActions>>>;
56
- /** Direct access to the underlying Zustand store API */
57
- store: StoreApi<StoreSlice<TState, TActions>>;
58
- }
59
-
60
- /**
61
- * Creates a dynamic Zustand store from a configuration object.
62
- *
63
- * @example
64
- * ```ts
65
- * const { useStore } = createDynamicStore({
66
- * initialState: { count: 0 },
67
- * actions: (set) => ({
68
- * increment: () => set((s) => ({ count: s.count + 1 })),
69
- * decrement: () => set((s) => ({ count: s.count - 1 })),
70
- * reset: () => set({ count: 0 }),
71
- * }),
72
- * });
73
- * ```
74
- */
75
- declare function createDynamicStore<TState extends StoreState, TActions extends StoreActions>(config: DynamicStoreConfig<TState, TActions>): DynamicStore<TState, TActions>;
76
31
 
32
+ interface UseDynamicStoreMethodsReturn<T extends StoreState> {
33
+ setData: (updater: SetStateAction<T>) => void;
34
+ reset: () => void;
35
+ get: () => T;
36
+ }
77
37
  interface UseDynamicStoreReturn<T extends StoreState> {
78
38
  data: T;
79
39
  setData: (updater: SetStateAction<T>) => void;
80
40
  reset: () => void;
81
41
  }
42
+ /**
43
+ * Hook that returns store methods (setData, reset, get) WITHOUT subscribing
44
+ * to state changes. Useful when you only need to update or read the store
45
+ * imperatively without causing component re-renders.
46
+ */
47
+ declare function useDynamicStoreMethods<T extends StoreState>(storeId: string, config?: StoreConfig<T>): UseDynamicStoreMethodsReturn<T>;
82
48
  /**
83
49
  * Hook-based dynamic store keyed by `storeId`.
84
50
  *
@@ -117,6 +83,11 @@ declare function useDynamicStoreWithCleanup<T extends StoreState>(storeId: strin
117
83
  * Update a dynamic store from outside a React component.
118
84
  */
119
85
  declare const updateDynamicStore: (storeId: string, data: StoreState) => void;
86
+ /**
87
+ * Retrieve the current state of a dynamic store from outside a React component.
88
+ * Fallbacks to empty object if store does not exist.
89
+ */
90
+ declare const getDynamicStoreData: <T extends StoreState = StoreState>(storeId: string) => T | undefined;
120
91
  /**
121
92
  * Reset a single dynamic store to its initial state from outside React.
122
93
  */
@@ -130,4 +101,4 @@ declare const resetAllDynamicStores: () => void;
130
101
  */
131
102
  declare const resetNonPersistentDynamicStores: () => void;
132
103
 
133
- export { type DynamicStore, type DynamicStoreConfig, type DynamicStoreRegistry, type SetStateAction, type StoreActions, type StoreConfig, type StoreSlice, type StoreState, type UseDynamicStoreReturn, createDynamicStore, resetAllDynamicStores, resetDynamicStore, resetNonPersistentDynamicStores, updateDynamicStore, useDynamicStore, useDynamicStoreWithCleanup };
104
+ export { type DynamicStoreRegistry, type SetStateAction, type StoreConfig, type UseDynamicStoreMethodsReturn, type UseDynamicStoreReturn, getDynamicStoreData, resetAllDynamicStores, resetDynamicStore, resetNonPersistentDynamicStores, updateDynamicStore, useDynamicStore, useDynamicStoreMethods, useDynamicStoreWithCleanup };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { UseBoundStore, StoreApi } from 'zustand';
2
-
3
1
  /**
4
2
  * Updater argument for setData — either a partial object or a function
5
3
  * that receives the previous state and returns a partial object.
@@ -30,55 +28,23 @@ interface DynamicStoreRegistry {
30
28
  * Keys are strings, values can be anything.
31
29
  */
32
30
  type StoreState = Record<string, unknown>;
33
- /**
34
- * Actions are functions attached to the store.
35
- */
36
- type StoreActions = Record<string, (...args: unknown[]) => unknown>;
37
- /**
38
- * Full store slice = state + actions.
39
- */
40
- type StoreSlice<TState extends StoreState = StoreState, TActions extends StoreActions = StoreActions> = TState & TActions;
41
- /**
42
- * Configuration object passed to createDynamicStore.
43
- */
44
- interface DynamicStoreConfig<TState extends StoreState, TActions extends StoreActions> {
45
- /** Initial state values */
46
- initialState: TState;
47
- /** Factory that receives `set` and `get` and returns action implementations */
48
- actions: (set: StoreApi<StoreSlice<TState, TActions>>["setState"], get: StoreApi<StoreSlice<TState, TActions>>["getState"]) => TActions;
49
- }
50
- /**
51
- * The return type of createDynamicStore.
52
- */
53
- interface DynamicStore<TState extends StoreState, TActions extends StoreActions> {
54
- /** Zustand React hook */
55
- useStore: UseBoundStore<StoreApi<StoreSlice<TState, TActions>>>;
56
- /** Direct access to the underlying Zustand store API */
57
- store: StoreApi<StoreSlice<TState, TActions>>;
58
- }
59
-
60
- /**
61
- * Creates a dynamic Zustand store from a configuration object.
62
- *
63
- * @example
64
- * ```ts
65
- * const { useStore } = createDynamicStore({
66
- * initialState: { count: 0 },
67
- * actions: (set) => ({
68
- * increment: () => set((s) => ({ count: s.count + 1 })),
69
- * decrement: () => set((s) => ({ count: s.count - 1 })),
70
- * reset: () => set({ count: 0 }),
71
- * }),
72
- * });
73
- * ```
74
- */
75
- declare function createDynamicStore<TState extends StoreState, TActions extends StoreActions>(config: DynamicStoreConfig<TState, TActions>): DynamicStore<TState, TActions>;
76
31
 
32
+ interface UseDynamicStoreMethodsReturn<T extends StoreState> {
33
+ setData: (updater: SetStateAction<T>) => void;
34
+ reset: () => void;
35
+ get: () => T;
36
+ }
77
37
  interface UseDynamicStoreReturn<T extends StoreState> {
78
38
  data: T;
79
39
  setData: (updater: SetStateAction<T>) => void;
80
40
  reset: () => void;
81
41
  }
42
+ /**
43
+ * Hook that returns store methods (setData, reset, get) WITHOUT subscribing
44
+ * to state changes. Useful when you only need to update or read the store
45
+ * imperatively without causing component re-renders.
46
+ */
47
+ declare function useDynamicStoreMethods<T extends StoreState>(storeId: string, config?: StoreConfig<T>): UseDynamicStoreMethodsReturn<T>;
82
48
  /**
83
49
  * Hook-based dynamic store keyed by `storeId`.
84
50
  *
@@ -117,6 +83,11 @@ declare function useDynamicStoreWithCleanup<T extends StoreState>(storeId: strin
117
83
  * Update a dynamic store from outside a React component.
118
84
  */
119
85
  declare const updateDynamicStore: (storeId: string, data: StoreState) => void;
86
+ /**
87
+ * Retrieve the current state of a dynamic store from outside a React component.
88
+ * Fallbacks to empty object if store does not exist.
89
+ */
90
+ declare const getDynamicStoreData: <T extends StoreState = StoreState>(storeId: string) => T | undefined;
120
91
  /**
121
92
  * Reset a single dynamic store to its initial state from outside React.
122
93
  */
@@ -130,4 +101,4 @@ declare const resetAllDynamicStores: () => void;
130
101
  */
131
102
  declare const resetNonPersistentDynamicStores: () => void;
132
103
 
133
- export { type DynamicStore, type DynamicStoreConfig, type DynamicStoreRegistry, type SetStateAction, type StoreActions, type StoreConfig, type StoreSlice, type StoreState, type UseDynamicStoreReturn, createDynamicStore, resetAllDynamicStores, resetDynamicStore, resetNonPersistentDynamicStores, updateDynamicStore, useDynamicStore, useDynamicStoreWithCleanup };
104
+ export { type DynamicStoreRegistry, type SetStateAction, type StoreConfig, type UseDynamicStoreMethodsReturn, type UseDynamicStoreReturn, getDynamicStoreData, resetAllDynamicStores, resetDynamicStore, resetNonPersistentDynamicStores, updateDynamicStore, useDynamicStore, useDynamicStoreMethods, useDynamicStoreWithCleanup };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var zustand=require('zustand'),middleware=require('zustand/middleware'),react=require('react');function d(r){let{initialState:t,actions:e}=r,o=zustand.create()((n,s)=>({...t,...e(n,s)}));return {useStore:o,store:o}}var i=zustand.create()(middleware.devtools(r=>({stores:{},setStoreData:(t,e,o)=>{r(n=>{let s=n.stores[t],a={data:{...s?.data??o?.initialState??{},...e},config:o??s?.config??{},initialState:o?.initialState??s?.initialState??{}};return {stores:{...n.stores,[t]:a}}});},resetStore:t=>{r(e=>{let o=e.stores[t];return o?{stores:{...e.stores,[t]:{...o,data:{...o.initialState}}}}:e});},resetAllStores:()=>{r(t=>{let e={};for(let[o,n]of Object.entries(t.stores))e[o]={...n,data:{...n.initialState}};return {stores:e}});},resetNonPersistentStores:()=>{r(t=>{let e={};for(let[o,n]of Object.entries(t.stores))e[o]=n.config.persistOnNavigation===true?n:{...n,data:{...n.initialState}};return {stores:e}});}}),{name:"DynamicStoresManager"}));function c(r,t){let e=i(),o=e.stores[r];return react.useEffect(()=>{!o&&t?.initialState!==void 0&&e.setStoreData(r,{},t);},[r]),{data:o?.data??t?.initialState??{},setData:a=>{if(typeof a=="function"){let y=e.stores[r]?.data??t?.initialState??{},D=a(y);e.setStoreData(r,D,t);}else e.setStoreData(r,a,t);},reset:()=>{e.resetStore(r);}}}function g(r,t){let{data:e,setData:o,reset:n}=c(r,t);return react.useEffect(()=>()=>{t?.resetOnUnmount===true&&n();},[r,t?.resetOnUnmount]),{data:e,setData:o,reset:n}}var l=(r,t)=>{i.getState().setStoreData(r,t);},x=r=>{i.getState().resetStore(r);},T=()=>{i.getState().resetAllStores();},A=()=>{i.getState().resetNonPersistentStores();};exports.createDynamicStore=d;exports.resetAllDynamicStores=T;exports.resetDynamicStore=x;exports.resetNonPersistentDynamicStores=A;exports.updateDynamicStore=l;exports.useDynamicStore=c;exports.useDynamicStoreWithCleanup=g;//# sourceMappingURL=index.js.map
1
+ 'use strict';var zustand=require('zustand'),middleware=require('zustand/middleware'),react=require('react');var a=zustand.create()(middleware.devtools(e=>({stores:{},setStoreData:(t,r,o)=>{e(s=>{let i=s.stores[t],n={data:{...i?.data??o?.initialState??{},...r},config:o??i?.config??{},initialState:o?.initialState??i?.initialState??{}};return {stores:{...s.stores,[t]:n}}});},resetStore:t=>{e(r=>{let o=r.stores[t];return o?{stores:{...r.stores,[t]:{...o,data:{...o.initialState}}}}:r});},resetAllStores:()=>{e(t=>{let r={};for(let[o,s]of Object.entries(t.stores))r[o]={...s,data:{...s.initialState}};return {stores:r}});},resetNonPersistentStores:()=>{e(t=>{let r={};for(let[o,s]of Object.entries(t.stores))r[o]=s.config.persistOnNavigation===true?s:{...s,data:{...s.initialState}};return {stores:r}});}}),{name:"DynamicStoresManager"}));function c(e,t){let r=a(n=>n.setStoreData),o=a(n=>n.resetStore),s=()=>a.getState().stores[e]?.data??t?.initialState??{};return {setData:n=>{if(typeof n=="function"){let D=n(s());r(e,D,t);}else r(e,n,t);},reset:()=>{o(e);},get:s}}function d(e,t){let r=a(i=>i.stores[e]),o=c(e,t);return react.useEffect(()=>{!r&&t?.initialState!==void 0&&a.getState().setStoreData(e,{},t);},[e]),{data:r?.data??t?.initialState??{},setData:o.setData,reset:o.reset}}function g(e,t){let{data:r,setData:o,reset:s}=d(e,t);return react.useEffect(()=>()=>{t?.resetOnUnmount===true&&s();},[e,t?.resetOnUnmount]),{data:r,setData:o,reset:s}}var f=(e,t)=>{a.getState().setStoreData(e,t);},p=e=>a.getState().stores[e]?.data,l=e=>{a.getState().resetStore(e);},T=()=>{a.getState().resetAllStores();},x=()=>{a.getState().resetNonPersistentStores();};exports.getDynamicStoreData=p;exports.resetAllDynamicStores=T;exports.resetDynamicStore=l;exports.resetNonPersistentDynamicStores=x;exports.updateDynamicStore=f;exports.useDynamicStore=d;exports.useDynamicStoreMethods=c;exports.useDynamicStoreWithCleanup=g;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createDynamicStore.ts","../src/dynamicStore.ts"],"names":["createDynamicStore","config","initialState","actions","store","create","set","get","useDynamicStoresManager","devtools","storeId","data","state","existingStore","entry","next","id","useDynamicStore","storesManager","storeRegistry","useEffect","updater","currentData","updates","useDynamicStoreWithCleanup","setData","reset","updateDynamicStore","resetDynamicStore","resetAllDynamicStores","resetNonPersistentDynamicStores"],"mappings":"4GAwBO,SAASA,EAIdC,CAAAA,CACgC,CAChC,GAAM,CAAE,YAAA,CAAAC,CAAAA,CAAc,QAAAC,CAAQ,CAAA,CAAIF,EAE5BG,CAAAA,CAAQC,cAAAA,GAAuC,CAACC,CAAAA,CAAKC,CAAAA,IAAS,CAClE,GAAGL,CAAAA,CACH,GAAGC,CAAAA,CAAQG,CAAAA,CAAKC,CAAG,CACrB,CAAA,CAAE,EAEF,OAAO,CACL,QAAA,CAAUH,CAAAA,CACV,KAAA,CAAAA,CACF,CACF,CCjBA,IAAMI,CAAAA,CAA0BH,cAAAA,GAC9BI,mBAAAA,CACGH,CAAAA,GAAS,CACR,MAAA,CAAQ,EAAC,CAET,YAAA,CAAc,CAACI,CAAAA,CAASC,EAAMV,CAAAA,GAAW,CACvCK,CAAAA,CAAKM,CAAAA,EAAU,CACb,IAAMC,EAAgBD,CAAAA,CAAM,MAAA,CAAOF,CAAO,CAAA,CAIpCI,CAAAA,CAA8B,CAClC,KAAM,CAAE,GAHRD,GAAe,IAAA,EAAQZ,CAAAA,EAAQ,cAAgB,EAAC,CAGxB,GAAGU,CAAK,CAAA,CAChC,MAAA,CAAQV,GA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CAAAA,CAAmBP,CAAAA,CAAST,CAAM,CAAA,CAEnE,OAAAmB,eAAAA,CAAU,IACD,IAAM,CACPnB,CAAAA,EAAQ,cAAA,GAAmB,MAC7ByB,CAAAA,GAEJ,CAAA,CAEC,CAAChB,CAAAA,CAAST,CAAAA,EAAQ,cAAc,CAAC,CAAA,CAE7B,CAAE,IAAA,CAAAU,CAAAA,CAAM,QAAAc,CAAAA,CAAS,KAAA,CAAAC,CAAM,CAChC,CAOO,IAAMC,EAAqB,CAChCjB,CAAAA,CACAC,CAAAA,GACS,CACTH,CAAAA,CAAwB,QAAA,GAAW,YAAA,CAAaE,CAAAA,CAASC,CAAI,EAC/D,CAAA,CAKaiB,CAAAA,CAAqBlB,GAA0B,CAC1DF,CAAAA,CAAwB,UAAS,CAAE,UAAA,CAAWE,CAAO,EACvD,CAAA,CAKamB,CAAAA,CAAwB,IAAY,CAC/CrB,CAAAA,CAAwB,UAAS,CAAE,cAAA,GACrC,CAAA,CAKasB,CAAAA,CAAkC,IAAY,CACzDtB,CAAAA,CAAwB,QAAA,EAAS,CAAE,wBAAA,GACrC","file":"index.js","sourcesContent":["import { create } from \"zustand\";\nimport type {\n DynamicStore,\n DynamicStoreConfig,\n StoreActions,\n StoreState,\n StoreSlice,\n} from \"./types\";\n\n/**\n * Creates a dynamic Zustand store from a configuration object.\n *\n * @example\n * ```ts\n * const { useStore } = createDynamicStore({\n * initialState: { count: 0 },\n * actions: (set) => ({\n * increment: () => set((s) => ({ count: s.count + 1 })),\n * decrement: () => set((s) => ({ count: s.count - 1 })),\n * reset: () => set({ count: 0 }),\n * }),\n * });\n * ```\n */\nexport function createDynamicStore<\n TState extends StoreState,\n TActions extends StoreActions,\n>(\n config: DynamicStoreConfig<TState, TActions>,\n): DynamicStore<TState, TActions> {\n const { initialState, actions } = config;\n\n const store = create<StoreSlice<TState, TActions>>()((set, get) => ({\n ...initialState,\n ...actions(set, get),\n }));\n\n return {\n useStore: store,\n store,\n };\n}\n","import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport { useEffect } from \"react\";\nimport type {\n SetStateAction,\n StoreConfig,\n DynamicStoreRegistry,\n StoreState,\n} from \"./types\";\n\n// ─── Internal manager state ───────────────────────────────────────────────────\n\ninterface DynamicStoresState {\n stores: Record<string, DynamicStoreRegistry>;\n setStoreData: (\n storeId: string,\n data: StoreState,\n config?: StoreConfig,\n ) => void;\n resetStore: (storeId: string) => void;\n resetAllStores: () => void;\n resetNonPersistentStores: () => void;\n}\n\nconst useDynamicStoresManager = create<DynamicStoresState>()(\n devtools(\n (set) => ({\n stores: {},\n\n setStoreData: (storeId, data, config) => {\n set((state) => {\n const existingStore = state.stores[storeId];\n const currentData: StoreState =\n existingStore?.data ?? config?.initialState ?? {};\n\n const entry: DynamicStoreRegistry = {\n data: { ...currentData, ...data },\n config: config ?? existingStore?.config ?? {},\n initialState:\n config?.initialState ?? existingStore?.initialState ?? {},\n };\n\n return {\n stores: { ...state.stores, [storeId]: entry },\n };\n });\n },\n\n resetStore: (storeId) => {\n set((state) => {\n const store = state.stores[storeId];\n if (!store) return state;\n\n return {\n stores: {\n ...state.stores,\n [storeId]: { ...store, data: { ...store.initialState } },\n },\n };\n });\n },\n\n resetAllStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] = { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n\n resetNonPersistentStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] =\n store.config.persistOnNavigation === true\n ? store\n : { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n }),\n { name: \"DynamicStoresManager\" },\n ),\n);\n\n// ─── Return types ─────────────────────────────────────────────────────────────\n\nexport interface UseDynamicStoreReturn<T extends StoreState> {\n data: T;\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n}\n\n// ─── useDynamicStore ──────────────────────────────────────────────────────────\n\n/**\n * Hook-based dynamic store keyed by `storeId`.\n *\n * `setData` accepts either a partial object **or** a function that receives\n * the previous state and returns a partial object — exactly like React's\n * `useState` setter.\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStore<CounterState>('counter', {\n * initialState: { value: 0, step: 1 },\n * });\n *\n * // object update\n * setData({ value: 42 });\n *\n * // functional update — safe for rapid successive calls\n * setData((prev) => ({ value: prev.value + prev.step }));\n * ```\n */\nexport function useDynamicStore<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const storesManager = useDynamicStoresManager();\n const storeRegistry = storesManager.stores[storeId];\n\n // Initialize the store entry on first use\n useEffect(() => {\n if (!storeRegistry && config?.initialState !== undefined) {\n storesManager.setStoreData(storeId, {}, config as StoreConfig);\n }\n // Only run on mount / storeId change — intentional dep list\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId]);\n\n const data = (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n\n const setData = (updater: SetStateAction<T>): void => {\n if (typeof updater === \"function\") {\n const currentData = (\n storesManager.stores[storeId]?.data ?? config?.initialState ?? {}\n ) as T;\n const updates = updater(currentData);\n storesManager.setStoreData(\n storeId,\n updates as StoreState,\n config as StoreConfig | undefined,\n );\n } else {\n storesManager.setStoreData(\n storeId,\n updater as StoreState,\n config as StoreConfig | undefined,\n );\n }\n };\n\n const reset = (): void => {\n storesManager.resetStore(storeId);\n };\n\n return { data, setData, reset };\n}\n\n// ─── useDynamicStoreWithCleanup ───────────────────────────────────────────────\n\n/**\n * Same as `useDynamicStore` but automatically resets state when the\n * component unmounts (when `config.resetOnUnmount` is `true`).\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStoreWithCleanup<FormState>(\n * 'editForm',\n * { initialState, resetOnUnmount: true },\n * );\n * ```\n */\nexport function useDynamicStoreWithCleanup<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const { data, setData, reset } = useDynamicStore<T>(storeId, config);\n\n useEffect(() => {\n return () => {\n if (config?.resetOnUnmount === true) {\n reset();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId, config?.resetOnUnmount]);\n\n return { data, setData, reset };\n}\n\n// ─── Imperative helpers (outside React) ──────────────────────────────────────\n\n/**\n * Update a dynamic store from outside a React component.\n */\nexport const updateDynamicStore = (\n storeId: string,\n data: StoreState,\n): void => {\n useDynamicStoresManager.getState().setStoreData(storeId, data);\n};\n\n/**\n * Reset a single dynamic store to its initial state from outside React.\n */\nexport const resetDynamicStore = (storeId: string): void => {\n useDynamicStoresManager.getState().resetStore(storeId);\n};\n\n/**\n * Reset all dynamic stores to their initial states from outside React.\n */\nexport const resetAllDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetAllStores();\n};\n\n/**\n * Reset only stores that do not have `persistOnNavigation: true`.\n */\nexport const resetNonPersistentDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetNonPersistentStores();\n};\n"]}
1
+ {"version":3,"sources":["../src/dynamicStore.ts"],"names":["useDynamicStoresManager","create","devtools","set","storeId","data","config","state","existingStore","entry","store","next","id","useDynamicStoreMethods","setStoreData","resetStore","get","updater","updates","useDynamicStore","storeRegistry","methods","useEffect","useDynamicStoreWithCleanup","setData","reset","updateDynamicStore","getDynamicStoreData","resetDynamicStore","resetAllDynamicStores","resetNonPersistentDynamicStores"],"mappings":"4GAwBA,IAAMA,CAAAA,CAA0BC,cAAAA,EAA2B,CACzDC,mBAAAA,CACGC,CAAAA,GAAS,CACR,OAAQ,EAAC,CAET,YAAA,CAAc,CAACC,CAAAA,CAASC,CAAAA,CAAMC,IAAW,CACvCH,CAAAA,CAAKI,GAAU,CACb,IAAMC,EAAgBD,CAAAA,CAAM,MAAA,CAAOH,CAAO,CAAA,CAIpCK,CAAAA,CAA8B,CAClC,KAAM,CAAE,GAHRD,CAAAA,EAAe,IAAA,EAAQF,CA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AAY,CACzD9B,CAAAA,CAAwB,QAAA,EAAS,CAAE,wBAAA,GACrC","file":"index.js","sourcesContent":["import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport { useEffect } from \"react\";\nimport type {\n SetStateAction,\n StoreConfig,\n DynamicStoreRegistry,\n StoreState,\n} from \"./types\";\n\n// ─── Internal manager state ───────────────────────────────────────────────────\n\ninterface DynamicStoresState {\n stores: Record<string, DynamicStoreRegistry>;\n setStoreData: (\n storeId: string,\n data: StoreState,\n config?: StoreConfig,\n ) => void;\n resetStore: (storeId: string) => void;\n resetAllStores: () => void;\n resetNonPersistentStores: () => void;\n}\n\nconst useDynamicStoresManager = create<DynamicStoresState>()(\n devtools(\n (set) => ({\n stores: {},\n\n setStoreData: (storeId, data, config) => {\n set((state) => {\n const existingStore = state.stores[storeId];\n const currentData: StoreState =\n existingStore?.data ?? config?.initialState ?? {};\n\n const entry: DynamicStoreRegistry = {\n data: { ...currentData, ...data },\n config: config ?? existingStore?.config ?? {},\n initialState:\n config?.initialState ?? existingStore?.initialState ?? {},\n };\n\n return {\n stores: { ...state.stores, [storeId]: entry },\n };\n });\n },\n\n resetStore: (storeId) => {\n set((state) => {\n const store = state.stores[storeId];\n if (!store) return state;\n\n return {\n stores: {\n ...state.stores,\n [storeId]: { ...store, data: { ...store.initialState } },\n },\n };\n });\n },\n\n resetAllStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] = { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n\n resetNonPersistentStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] =\n store.config.persistOnNavigation === true\n ? store\n : { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n }),\n { name: \"DynamicStoresManager\" },\n ),\n);\n\n// ─── Return types ─────────────────────────────────────────────────────────────\n\nexport interface UseDynamicStoreMethodsReturn<T extends StoreState> {\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n get: () => T;\n}\n\nexport interface UseDynamicStoreReturn<T extends StoreState> {\n data: T;\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n}\n\n// ─── useDynamicStoreMethods ───────────────────────────────────────────────────\n\n/**\n * Hook that returns store methods (setData, reset, get) WITHOUT subscribing\n * to state changes. Useful when you only need to update or read the store\n * imperatively without causing component re-renders.\n */\nexport function useDynamicStoreMethods<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreMethodsReturn<T> {\n const setStoreData = useDynamicStoresManager((state) => state.setStoreData);\n const resetStore = useDynamicStoresManager((state) => state.resetStore);\n\n const get = (): T => {\n const storeRegistry = useDynamicStoresManager.getState().stores[storeId];\n return (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n };\n\n const setData = (updater: SetStateAction<T>): void => {\n if (typeof updater === \"function\") {\n const updates = updater(get());\n setStoreData(\n storeId,\n updates as StoreState,\n config as StoreConfig | undefined,\n );\n } else {\n setStoreData(\n storeId,\n updater as StoreState,\n config as StoreConfig | undefined,\n );\n }\n };\n\n const reset = (): void => {\n resetStore(storeId);\n };\n\n return { setData, reset, get };\n}\n\n// ─── useDynamicStore ──────────────────────────────────────────────────────────\n\n/**\n * Hook-based dynamic store keyed by `storeId`.\n *\n * `setData` accepts either a partial object **or** a function that receives\n * the previous state and returns a partial object — exactly like React's\n * `useState` setter.\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStore<CounterState>('counter', {\n * initialState: { value: 0, step: 1 },\n * });\n *\n * // object update\n * setData({ value: 42 });\n *\n * // functional update — safe for rapid successive calls\n * setData((prev) => ({ value: prev.value + prev.step }));\n * ```\n */\nexport function useDynamicStore<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const storeRegistry = useDynamicStoresManager((state) => state.stores[storeId]);\n const methods = useDynamicStoreMethods<T>(storeId, config);\n\n // Initialize the store entry on first use\n useEffect(() => {\n if (!storeRegistry && config?.initialState !== undefined) {\n useDynamicStoresManager.getState().setStoreData(\n storeId,\n {},\n config as StoreConfig,\n );\n }\n // Only run on mount / storeId change — intentional dep list\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId]);\n\n const data = (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n\n return { data, setData: methods.setData, reset: methods.reset };\n}\n\n// ─── useDynamicStoreWithCleanup ───────────────────────────────────────────────\n\n/**\n * Same as `useDynamicStore` but automatically resets state when the\n * component unmounts (when `config.resetOnUnmount` is `true`).\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStoreWithCleanup<FormState>(\n * 'editForm',\n * { initialState, resetOnUnmount: true },\n * );\n * ```\n */\nexport function useDynamicStoreWithCleanup<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const { data, setData, reset } = useDynamicStore<T>(storeId, config);\n\n useEffect(() => {\n return () => {\n if (config?.resetOnUnmount === true) {\n reset();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId, config?.resetOnUnmount]);\n\n return { data, setData, reset };\n}\n\n// ─── Imperative helpers (outside React) ──────────────────────────────────────\n\n/**\n * Update a dynamic store from outside a React component.\n */\nexport const updateDynamicStore = (\n storeId: string,\n data: StoreState,\n): void => {\n useDynamicStoresManager.getState().setStoreData(storeId, data);\n};\n\n/**\n * Retrieve the current state of a dynamic store from outside a React component.\n * Fallbacks to empty object if store does not exist.\n */\nexport const getDynamicStoreData = <T extends StoreState = StoreState>(\n storeId: string,\n): T | undefined => {\n return useDynamicStoresManager.getState().stores[storeId]?.data as T | undefined;\n};\n\n/**\n * Reset a single dynamic store to its initial state from outside React.\n */\nexport const resetDynamicStore = (storeId: string): void => {\n useDynamicStoresManager.getState().resetStore(storeId);\n};\n\n/**\n * Reset all dynamic stores to their initial states from outside React.\n */\nexport const resetAllDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetAllStores();\n};\n\n/**\n * Reset only stores that do not have `persistOnNavigation: true`.\n */\nexport const resetNonPersistentDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetNonPersistentStores();\n};\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {create}from'zustand';import {devtools}from'zustand/middleware';import {useEffect}from'react';function d(r){let{initialState:t,actions:e}=r,o=create()((n,s)=>({...t,...e(n,s)}));return {useStore:o,store:o}}var i=create()(devtools(r=>({stores:{},setStoreData:(t,e,o)=>{r(n=>{let s=n.stores[t],a={data:{...s?.data??o?.initialState??{},...e},config:o??s?.config??{},initialState:o?.initialState??s?.initialState??{}};return {stores:{...n.stores,[t]:a}}});},resetStore:t=>{r(e=>{let o=e.stores[t];return o?{stores:{...e.stores,[t]:{...o,data:{...o.initialState}}}}:e});},resetAllStores:()=>{r(t=>{let e={};for(let[o,n]of Object.entries(t.stores))e[o]={...n,data:{...n.initialState}};return {stores:e}});},resetNonPersistentStores:()=>{r(t=>{let e={};for(let[o,n]of Object.entries(t.stores))e[o]=n.config.persistOnNavigation===true?n:{...n,data:{...n.initialState}};return {stores:e}});}}),{name:"DynamicStoresManager"}));function c(r,t){let e=i(),o=e.stores[r];return useEffect(()=>{!o&&t?.initialState!==void 0&&e.setStoreData(r,{},t);},[r]),{data:o?.data??t?.initialState??{},setData:a=>{if(typeof a=="function"){let y=e.stores[r]?.data??t?.initialState??{},D=a(y);e.setStoreData(r,D,t);}else e.setStoreData(r,a,t);},reset:()=>{e.resetStore(r);}}}function g(r,t){let{data:e,setData:o,reset:n}=c(r,t);return useEffect(()=>()=>{t?.resetOnUnmount===true&&n();},[r,t?.resetOnUnmount]),{data:e,setData:o,reset:n}}var l=(r,t)=>{i.getState().setStoreData(r,t);},x=r=>{i.getState().resetStore(r);},T=()=>{i.getState().resetAllStores();},A=()=>{i.getState().resetNonPersistentStores();};export{d as createDynamicStore,T as resetAllDynamicStores,x as resetDynamicStore,A as resetNonPersistentDynamicStores,l as updateDynamicStore,c as useDynamicStore,g as useDynamicStoreWithCleanup};//# sourceMappingURL=index.mjs.map
1
+ import {create}from'zustand';import {devtools}from'zustand/middleware';import {useEffect}from'react';var a=create()(devtools(e=>({stores:{},setStoreData:(t,r,o)=>{e(s=>{let i=s.stores[t],n={data:{...i?.data??o?.initialState??{},...r},config:o??i?.config??{},initialState:o?.initialState??i?.initialState??{}};return {stores:{...s.stores,[t]:n}}});},resetStore:t=>{e(r=>{let o=r.stores[t];return o?{stores:{...r.stores,[t]:{...o,data:{...o.initialState}}}}:r});},resetAllStores:()=>{e(t=>{let r={};for(let[o,s]of Object.entries(t.stores))r[o]={...s,data:{...s.initialState}};return {stores:r}});},resetNonPersistentStores:()=>{e(t=>{let r={};for(let[o,s]of Object.entries(t.stores))r[o]=s.config.persistOnNavigation===true?s:{...s,data:{...s.initialState}};return {stores:r}});}}),{name:"DynamicStoresManager"}));function c(e,t){let r=a(n=>n.setStoreData),o=a(n=>n.resetStore),s=()=>a.getState().stores[e]?.data??t?.initialState??{};return {setData:n=>{if(typeof n=="function"){let D=n(s());r(e,D,t);}else r(e,n,t);},reset:()=>{o(e);},get:s}}function d(e,t){let r=a(i=>i.stores[e]),o=c(e,t);return useEffect(()=>{!r&&t?.initialState!==void 0&&a.getState().setStoreData(e,{},t);},[e]),{data:r?.data??t?.initialState??{},setData:o.setData,reset:o.reset}}function g(e,t){let{data:r,setData:o,reset:s}=d(e,t);return useEffect(()=>()=>{t?.resetOnUnmount===true&&s();},[e,t?.resetOnUnmount]),{data:r,setData:o,reset:s}}var f=(e,t)=>{a.getState().setStoreData(e,t);},p=e=>a.getState().stores[e]?.data,l=e=>{a.getState().resetStore(e);},T=()=>{a.getState().resetAllStores();},x=()=>{a.getState().resetNonPersistentStores();};export{p as getDynamicStoreData,T as resetAllDynamicStores,l as resetDynamicStore,x as resetNonPersistentDynamicStores,f as updateDynamicStore,d as useDynamicStore,c as useDynamicStoreMethods,g as useDynamicStoreWithCleanup};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createDynamicStore.ts","../src/dynamicStore.ts"],"names":["createDynamicStore","config","initialState","actions","store","create","set","get","useDynamicStoresManager","devtools","storeId","data","state","existingStore","entry","next","id","useDynamicStore","storesManager","storeRegistry","useEffect","updater","currentData","updates","useDynamicStoreWithCleanup","setData","reset","updateDynamicStore","resetDynamicStore","resetAllDynamicStores","resetNonPersistentDynamicStores"],"mappings":"qGAwBO,SAASA,EAIdC,CAAAA,CACgC,CAChC,GAAM,CAAE,YAAA,CAAAC,CAAAA,CAAc,QAAAC,CAAQ,CAAA,CAAIF,EAE5BG,CAAAA,CAAQC,MAAAA,GAAuC,CAACC,CAAAA,CAAKC,CAAAA,IAAS,CAClE,GAAGL,CAAAA,CACH,GAAGC,CAAAA,CAAQG,CAAAA,CAAKC,CAAG,CACrB,CAAA,CAAE,EAEF,OAAO,CACL,QAAA,CAAUH,CAAAA,CACV,KAAA,CAAAA,CACF,CACF,CCjBA,IAAMI,CAAAA,CAA0BH,MAAAA,GAC9BI,QAAAA,CACGH,CAAAA,GAAS,CACR,MAAA,CAAQ,EAAC,CAET,YAAA,CAAc,CAACI,CAAAA,CAASC,EAAMV,CAAAA,GAAW,CACvCK,CAAAA,CAAKM,CAAAA,EAAU,CACb,IAAMC,EAAgBD,CAAAA,CAAM,MAAA,CAAOF,CAAO,CAAA,CAIpCI,CAAAA,CAA8B,CAClC,KAAM,CAAE,GAHRD,GAAe,IAAA,EAAQZ,CAAAA,EAAQ,cAAgB,EAAC,CAGxB,GAAGU,CAAK,CAAA,CAChC,MAAA,CAAQV,GAAUY,CAAAA,EAAe,MAAA,EAAU,EAAC,CAC5C,YAAA,CACEZ,CAAAA,EAAQ,cAAgBY,CAAAA,EAAe,YAAA,EAAgB,EAC3D,CAAA,CAEA,OAAO,CACL,MAAA,CAAQ,CAAE,GAAGD,CAAAA,C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,CAAAA,EAAQ,cAAc,CAAC,CAAA,CAE7B,CAAE,IAAA,CAAAU,CAAAA,CAAM,QAAAc,CAAAA,CAAS,KAAA,CAAAC,CAAM,CAChC,CAOO,IAAMC,EAAqB,CAChCjB,CAAAA,CACAC,CAAAA,GACS,CACTH,CAAAA,CAAwB,QAAA,GAAW,YAAA,CAAaE,CAAAA,CAASC,CAAI,EAC/D,CAAA,CAKaiB,CAAAA,CAAqBlB,GAA0B,CAC1DF,CAAAA,CAAwB,UAAS,CAAE,UAAA,CAAWE,CAAO,EACvD,CAAA,CAKamB,CAAAA,CAAwB,IAAY,CAC/CrB,CAAAA,CAAwB,UAAS,CAAE,cAAA,GACrC,CAAA,CAKasB,CAAAA,CAAkC,IAAY,CACzDtB,CAAAA,CAAwB,QAAA,EAAS,CAAE,wBAAA,GACrC","file":"index.mjs","sourcesContent":["import { create } from \"zustand\";\nimport type {\n DynamicStore,\n DynamicStoreConfig,\n StoreActions,\n StoreState,\n StoreSlice,\n} from \"./types\";\n\n/**\n * Creates a dynamic Zustand store from a configuration object.\n *\n * @example\n * ```ts\n * const { useStore } = createDynamicStore({\n * initialState: { count: 0 },\n * actions: (set) => ({\n * increment: () => set((s) => ({ count: s.count + 1 })),\n * decrement: () => set((s) => ({ count: s.count - 1 })),\n * reset: () => set({ count: 0 }),\n * }),\n * });\n * ```\n */\nexport function createDynamicStore<\n TState extends StoreState,\n TActions extends StoreActions,\n>(\n config: DynamicStoreConfig<TState, TActions>,\n): DynamicStore<TState, TActions> {\n const { initialState, actions } = config;\n\n const store = create<StoreSlice<TState, TActions>>()((set, get) => ({\n ...initialState,\n ...actions(set, get),\n }));\n\n return {\n useStore: store,\n store,\n };\n}\n","import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport { useEffect } from \"react\";\nimport type {\n SetStateAction,\n StoreConfig,\n DynamicStoreRegistry,\n StoreState,\n} from \"./types\";\n\n// ─── Internal manager state ───────────────────────────────────────────────────\n\ninterface DynamicStoresState {\n stores: Record<string, DynamicStoreRegistry>;\n setStoreData: (\n storeId: string,\n data: StoreState,\n config?: StoreConfig,\n ) => void;\n resetStore: (storeId: string) => void;\n resetAllStores: () => void;\n resetNonPersistentStores: () => void;\n}\n\nconst useDynamicStoresManager = create<DynamicStoresState>()(\n devtools(\n (set) => ({\n stores: {},\n\n setStoreData: (storeId, data, config) => {\n set((state) => {\n const existingStore = state.stores[storeId];\n const currentData: StoreState =\n existingStore?.data ?? config?.initialState ?? {};\n\n const entry: DynamicStoreRegistry = {\n data: { ...currentData, ...data },\n config: config ?? existingStore?.config ?? {},\n initialState:\n config?.initialState ?? existingStore?.initialState ?? {},\n };\n\n return {\n stores: { ...state.stores, [storeId]: entry },\n };\n });\n },\n\n resetStore: (storeId) => {\n set((state) => {\n const store = state.stores[storeId];\n if (!store) return state;\n\n return {\n stores: {\n ...state.stores,\n [storeId]: { ...store, data: { ...store.initialState } },\n },\n };\n });\n },\n\n resetAllStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] = { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n\n resetNonPersistentStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] =\n store.config.persistOnNavigation === true\n ? store\n : { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n }),\n { name: \"DynamicStoresManager\" },\n ),\n);\n\n// ─── Return types ─────────────────────────────────────────────────────────────\n\nexport interface UseDynamicStoreReturn<T extends StoreState> {\n data: T;\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n}\n\n// ─── useDynamicStore ──────────────────────────────────────────────────────────\n\n/**\n * Hook-based dynamic store keyed by `storeId`.\n *\n * `setData` accepts either a partial object **or** a function that receives\n * the previous state and returns a partial object — exactly like React's\n * `useState` setter.\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStore<CounterState>('counter', {\n * initialState: { value: 0, step: 1 },\n * });\n *\n * // object update\n * setData({ value: 42 });\n *\n * // functional update — safe for rapid successive calls\n * setData((prev) => ({ value: prev.value + prev.step }));\n * ```\n */\nexport function useDynamicStore<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const storesManager = useDynamicStoresManager();\n const storeRegistry = storesManager.stores[storeId];\n\n // Initialize the store entry on first use\n useEffect(() => {\n if (!storeRegistry && config?.initialState !== undefined) {\n storesManager.setStoreData(storeId, {}, config as StoreConfig);\n }\n // Only run on mount / storeId change — intentional dep list\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId]);\n\n const data = (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n\n const setData = (updater: SetStateAction<T>): void => {\n if (typeof updater === \"function\") {\n const currentData = (\n storesManager.stores[storeId]?.data ?? config?.initialState ?? {}\n ) as T;\n const updates = updater(currentData);\n storesManager.setStoreData(\n storeId,\n updates as StoreState,\n config as StoreConfig | undefined,\n );\n } else {\n storesManager.setStoreData(\n storeId,\n updater as StoreState,\n config as StoreConfig | undefined,\n );\n }\n };\n\n const reset = (): void => {\n storesManager.resetStore(storeId);\n };\n\n return { data, setData, reset };\n}\n\n// ─── useDynamicStoreWithCleanup ───────────────────────────────────────────────\n\n/**\n * Same as `useDynamicStore` but automatically resets state when the\n * component unmounts (when `config.resetOnUnmount` is `true`).\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStoreWithCleanup<FormState>(\n * 'editForm',\n * { initialState, resetOnUnmount: true },\n * );\n * ```\n */\nexport function useDynamicStoreWithCleanup<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const { data, setData, reset } = useDynamicStore<T>(storeId, config);\n\n useEffect(() => {\n return () => {\n if (config?.resetOnUnmount === true) {\n reset();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId, config?.resetOnUnmount]);\n\n return { data, setData, reset };\n}\n\n// ─── Imperative helpers (outside React) ──────────────────────────────────────\n\n/**\n * Update a dynamic store from outside a React component.\n */\nexport const updateDynamicStore = (\n storeId: string,\n data: StoreState,\n): void => {\n useDynamicStoresManager.getState().setStoreData(storeId, data);\n};\n\n/**\n * Reset a single dynamic store to its initial state from outside React.\n */\nexport const resetDynamicStore = (storeId: string): void => {\n useDynamicStoresManager.getState().resetStore(storeId);\n};\n\n/**\n * Reset all dynamic stores to their initial states from outside React.\n */\nexport const resetAllDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetAllStores();\n};\n\n/**\n * Reset only stores that do not have `persistOnNavigation: true`.\n */\nexport const resetNonPersistentDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetNonPersistentStores();\n};\n"]}
1
+ {"version":3,"sources":["../src/dynamicStore.ts"],"names":["useDynamicStoresManager","create","devtools","set","storeId","data","config","state","existingStore","entry","store","next","id","useDynamicStoreMethods","setStoreData","resetStore","get","updater","updates","useDynamicStore","storeRegistry","methods","useEffect","useDynamicStoreWithCleanup","setData","reset","updateDynamicStore","getDynamicStoreData","resetDynamicStore","resetAllDynamicStores","resetNonPersistentDynamicStores"],"mappings":"qGAwBA,IAAMA,CAAAA,CAA0BC,MAAAA,EAA2B,CACzDC,QAAAA,CACGC,CAAAA,GAAS,CACR,OAAQ,EAAC,CAET,YAAA,CAAc,CAACC,CAAAA,CAASC,CAAAA,CAAMC,IAAW,CACvCH,CAAAA,CAAKI,GAAU,CACb,IAAMC,EAAgBD,CAAAA,CAAM,MAAA,CAAOH,CAAO,CAAA,CAIpCK,CAAAA,CAA8B,CAClC,KAAM,CAAE,GAHRD,CAAAA,EAAe,IAAA,EAAQF,CAAAA,EAAQ,YAAA,EAAgB,EAAC,CAGxB,GAAGD,CAAK,CAAA,CAChC,MAAA,CAAQC,CAAAA,EAAUE,GAAe,MAAA,EAAU,GAC3C,YAAA,CACEF,CAAAA,EAAQ,cAAgBE,CAAAA,EAAe,YAAA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CAAC,CAAA,CAIL,CAAE,KAFKgB,CAAAA,EAAe,IAAA,EAAQd,GAAQ,YAAA,EAAgB,GAE9C,OAAA,CAASe,CAAAA,CAAQ,OAAA,CAAS,KAAA,CAAOA,CAAAA,CAAQ,KAAM,CAChE,CAgBO,SAASE,CAAAA,CACdnB,CAAAA,CACAE,CAAAA,CAC0B,CAC1B,GAAM,CAAE,IAAA,CAAAD,CAAAA,CAAM,OAAA,CAAAmB,CAAAA,CAAS,KAAA,CAAAC,CAAM,CAAA,CAAIN,CAAAA,CAAmBf,CAAAA,CAASE,CAAM,CAAA,CAEnE,OAAAgB,UAAU,IACD,IAAM,CACPhB,CAAAA,EAAQ,cAAA,GAAmB,IAAA,EAC7BmB,IAEJ,CAAA,CAEC,CAACrB,CAAAA,CAASE,CAAAA,EAAQ,cAAc,CAAC,CAAA,CAE7B,CAAE,IAAA,CAAAD,CAAAA,CAAM,OAAA,CAAAmB,CAAAA,CAAS,MAAAC,CAAM,CAChC,CAOO,IAAMC,CAAAA,CAAqB,CAChCtB,CAAAA,CACAC,CAAAA,GACS,CACTL,CAAAA,CAAwB,QAAA,EAAS,CAAE,aAAaI,CAAAA,CAASC,CAAI,EAC/D,CAAA,CAMasB,CAAAA,CACXvB,CAAAA,EAEOJ,EAAwB,QAAA,EAAS,CAAE,MAAA,CAAOI,CAAO,CAAA,EAAG,IAAA,CAMhDwB,EAAqBxB,CAAAA,EAA0B,CAC1DJ,CAAAA,CAAwB,QAAA,EAAS,CAAE,UAAA,CAAWI,CAAO,EACvD,CAAA,CAKayB,CAAAA,CAAwB,IAAY,CAC/C7B,CAAAA,CAAwB,UAAS,CAAE,cAAA,GACrC,CAAA,CAKa8B,CAAAA,CAAkC,IAAY,CACzD9B,CAAAA,CAAwB,QAAA,EAAS,CAAE,wBAAA,GACrC","file":"index.mjs","sourcesContent":["import { create } from \"zustand\";\nimport { devtools } from \"zustand/middleware\";\nimport { useEffect } from \"react\";\nimport type {\n SetStateAction,\n StoreConfig,\n DynamicStoreRegistry,\n StoreState,\n} from \"./types\";\n\n// ─── Internal manager state ───────────────────────────────────────────────────\n\ninterface DynamicStoresState {\n stores: Record<string, DynamicStoreRegistry>;\n setStoreData: (\n storeId: string,\n data: StoreState,\n config?: StoreConfig,\n ) => void;\n resetStore: (storeId: string) => void;\n resetAllStores: () => void;\n resetNonPersistentStores: () => void;\n}\n\nconst useDynamicStoresManager = create<DynamicStoresState>()(\n devtools(\n (set) => ({\n stores: {},\n\n setStoreData: (storeId, data, config) => {\n set((state) => {\n const existingStore = state.stores[storeId];\n const currentData: StoreState =\n existingStore?.data ?? config?.initialState ?? {};\n\n const entry: DynamicStoreRegistry = {\n data: { ...currentData, ...data },\n config: config ?? existingStore?.config ?? {},\n initialState:\n config?.initialState ?? existingStore?.initialState ?? {},\n };\n\n return {\n stores: { ...state.stores, [storeId]: entry },\n };\n });\n },\n\n resetStore: (storeId) => {\n set((state) => {\n const store = state.stores[storeId];\n if (!store) return state;\n\n return {\n stores: {\n ...state.stores,\n [storeId]: { ...store, data: { ...store.initialState } },\n },\n };\n });\n },\n\n resetAllStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] = { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n\n resetNonPersistentStores: () => {\n set((state) => {\n const next: Record<string, DynamicStoreRegistry> = {};\n\n for (const [id, store] of Object.entries(state.stores)) {\n next[id] =\n store.config.persistOnNavigation === true\n ? store\n : { ...store, data: { ...store.initialState } };\n }\n\n return { stores: next };\n });\n },\n }),\n { name: \"DynamicStoresManager\" },\n ),\n);\n\n// ─── Return types ─────────────────────────────────────────────────────────────\n\nexport interface UseDynamicStoreMethodsReturn<T extends StoreState> {\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n get: () => T;\n}\n\nexport interface UseDynamicStoreReturn<T extends StoreState> {\n data: T;\n setData: (updater: SetStateAction<T>) => void;\n reset: () => void;\n}\n\n// ─── useDynamicStoreMethods ───────────────────────────────────────────────────\n\n/**\n * Hook that returns store methods (setData, reset, get) WITHOUT subscribing\n * to state changes. Useful when you only need to update or read the store\n * imperatively without causing component re-renders.\n */\nexport function useDynamicStoreMethods<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreMethodsReturn<T> {\n const setStoreData = useDynamicStoresManager((state) => state.setStoreData);\n const resetStore = useDynamicStoresManager((state) => state.resetStore);\n\n const get = (): T => {\n const storeRegistry = useDynamicStoresManager.getState().stores[storeId];\n return (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n };\n\n const setData = (updater: SetStateAction<T>): void => {\n if (typeof updater === \"function\") {\n const updates = updater(get());\n setStoreData(\n storeId,\n updates as StoreState,\n config as StoreConfig | undefined,\n );\n } else {\n setStoreData(\n storeId,\n updater as StoreState,\n config as StoreConfig | undefined,\n );\n }\n };\n\n const reset = (): void => {\n resetStore(storeId);\n };\n\n return { setData, reset, get };\n}\n\n// ─── useDynamicStore ──────────────────────────────────────────────────────────\n\n/**\n * Hook-based dynamic store keyed by `storeId`.\n *\n * `setData` accepts either a partial object **or** a function that receives\n * the previous state and returns a partial object — exactly like React's\n * `useState` setter.\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStore<CounterState>('counter', {\n * initialState: { value: 0, step: 1 },\n * });\n *\n * // object update\n * setData({ value: 42 });\n *\n * // functional update — safe for rapid successive calls\n * setData((prev) => ({ value: prev.value + prev.step }));\n * ```\n */\nexport function useDynamicStore<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const storeRegistry = useDynamicStoresManager((state) => state.stores[storeId]);\n const methods = useDynamicStoreMethods<T>(storeId, config);\n\n // Initialize the store entry on first use\n useEffect(() => {\n if (!storeRegistry && config?.initialState !== undefined) {\n useDynamicStoresManager.getState().setStoreData(\n storeId,\n {},\n config as StoreConfig,\n );\n }\n // Only run on mount / storeId change — intentional dep list\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId]);\n\n const data = (storeRegistry?.data ?? config?.initialState ?? {}) as T;\n\n return { data, setData: methods.setData, reset: methods.reset };\n}\n\n// ─── useDynamicStoreWithCleanup ───────────────────────────────────────────────\n\n/**\n * Same as `useDynamicStore` but automatically resets state when the\n * component unmounts (when `config.resetOnUnmount` is `true`).\n *\n * @example\n * ```tsx\n * const { data, setData, reset } = useDynamicStoreWithCleanup<FormState>(\n * 'editForm',\n * { initialState, resetOnUnmount: true },\n * );\n * ```\n */\nexport function useDynamicStoreWithCleanup<T extends StoreState>(\n storeId: string,\n config?: StoreConfig<T>,\n): UseDynamicStoreReturn<T> {\n const { data, setData, reset } = useDynamicStore<T>(storeId, config);\n\n useEffect(() => {\n return () => {\n if (config?.resetOnUnmount === true) {\n reset();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [storeId, config?.resetOnUnmount]);\n\n return { data, setData, reset };\n}\n\n// ─── Imperative helpers (outside React) ──────────────────────────────────────\n\n/**\n * Update a dynamic store from outside a React component.\n */\nexport const updateDynamicStore = (\n storeId: string,\n data: StoreState,\n): void => {\n useDynamicStoresManager.getState().setStoreData(storeId, data);\n};\n\n/**\n * Retrieve the current state of a dynamic store from outside a React component.\n * Fallbacks to empty object if store does not exist.\n */\nexport const getDynamicStoreData = <T extends StoreState = StoreState>(\n storeId: string,\n): T | undefined => {\n return useDynamicStoresManager.getState().stores[storeId]?.data as T | undefined;\n};\n\n/**\n * Reset a single dynamic store to its initial state from outside React.\n */\nexport const resetDynamicStore = (storeId: string): void => {\n useDynamicStoresManager.getState().resetStore(storeId);\n};\n\n/**\n * Reset all dynamic stores to their initial states from outside React.\n */\nexport const resetAllDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetAllStores();\n};\n\n/**\n * Reset only stores that do not have `persistOnNavigation: true`.\n */\nexport const resetNonPersistentDynamicStores = (): void => {\n useDynamicStoresManager.getState().resetNonPersistentStores();\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitboxdev/dynamic-store-zustand",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Dynamic store factory built on top of Zustand for scalable state management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",