septor-store-react 0.0.2

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 ADDED
@@ -0,0 +1,327 @@
1
+
2
+
3
+ ### Add Quick Summary Table
4
+
5
+ | Feature | Description |
6
+ |-------------------------------------------|----------------------------------------------|
7
+ | API Deduplication | Prevents duplicate in-flight API calls |
8
+ | State Sync | Dynamically generates Pinia state per API |
9
+ | Caching | SessionStorage support |
10
+ | Pagination Helpers | Stubbed pagination extractors |
11
+ | Post + Submit Support | Easily manage POST data and track responses |
12
+ | Flexible Callbacks | Use custom callbacks on state update |
13
+ | Loading & Error States | Built-in support for loading/errors |
14
+
15
+ Key Features (Detailed)
16
+
17
+ Automatic API Call Queue Management
18
+ Prevents multiple simultaneous calls to the same endpoint by tracking ongoing requests.
19
+
20
+ Session Storage Caching
21
+ Optionally caches API responses for faster retrieval and offline resilience.
22
+
23
+ Dynamic State Generation
24
+ Automatically creates and manages state slices based on API response keys.
25
+
26
+ Paginated Data Handling
27
+ Includes helper methods to extract page numbers and manage paginated API responses.
28
+
29
+ State Reload and Refresh Controls
30
+ Supports forced reloads with configurable delays to prevent rapid repeat requests.
31
+
32
+ Flexible Callback Integration
33
+ Allows injecting custom callbacks for state updates.
34
+
35
+ Error Handling and Logging
36
+ Centralizes error capture and logs API issues for easier debugging.
37
+
38
+ Loading State Management
39
+ Tracks and exposes loading status for UI feedback during asynchronous operations.
40
+
41
+ Generic Data Validation
42
+ Utility methods for validating object/array length and type.
43
+
44
+ Built-in Sleep/Delay Utility
45
+ Useful for throttling or debouncing API requests.
46
+
47
+ Fast, cache-friendly state access
48
+
49
+ Lightweight reactivity
50
+
51
+ Data-ready views
52
+
53
+ Seamless session recovery
54
+ ---
55
+
56
+
57
+ | Option | Description |
58
+ | ------------- | ------------------------------------ |
59
+ | `stateKey` | Where data is stored in global state |
60
+ | `req` | Axios request configuration |
61
+ | `reload` | Force API reload |
62
+ | `time` | Delay before reload (seconds) |
63
+ | `mStore.mUse` | Enable sessionStorage caching |
64
+
65
+
66
+ stateGeneratorApi({
67
+ stateKey: "orders",
68
+ req: { url: "/orders" },
69
+ mStore: { mUse: true },
70
+ });
71
+
72
+ Data persists after refresh
73
+ Faster loading
74
+ Optional per request
75
+
76
+
77
+
78
+ Access Store in Other Files
79
+ ```
80
+ import usePomZStore from "septor-store-react";
81
+
82
+ const store = usePomZStore();
83
+
84
+ // Read
85
+ console.log(store.orders);
86
+
87
+ // Write
88
+ store.YourGlobalState = "I have new data";
89
+ ```
90
+
91
+ ### can be ignored
92
+
93
+ ```bash
94
+ setBearerToken({token:hellothere}); set Bearer token object
95
+ getBearerToken(); get Bearer token object
96
+ *❌ These will now throw errors: *
97
+ setBearerToken(null);
98
+ setBearerToken("string");
99
+ setBearerToken(123);
100
+ setBearerToken(["array"]);
101
+
102
+ *βœ… These will now :*
103
+ setBearerToken({ token: "abc123" });
104
+ // Or with additional props
105
+ setBearerToken({ token: "abc123", expiresIn: 3600 });
106
+ ```
107
+
108
+ Installation
109
+ npm install zustand axios
110
+
111
+ πŸ“ Usage
112
+ Import the store
113
+ import usePomZStore from "septor-store-react";
114
+
115
+ 🧠 Basic Example
116
+ import { useEffect } from "react";
117
+ import usePomZStore from "septor-store-react";
118
+ // stateKey: remember this should be an id
119
+
120
+ export default function Users() {
121
+
122
+ const { stateGeneratorApi, loading } = usePomZStore();
123
+
124
+ useEffect(() => {
125
+ stateGeneratorApi({
126
+ stateKey: "users",
127
+ req: {
128
+ url: "/users",
129
+ method: "GET",
130
+ ...
131
+ },
132
+ });
133
+ }, []);
134
+
135
+ if (loading) return <p>Loading...</p>;
136
+
137
+ return <p>Users loaded</p>;
138
+ }
139
+
140
+ 🧩 Store State
141
+ Name Description
142
+ loading Global loading flag
143
+ stateValue Object holding all stored data
144
+ checkQueriesInQue Tracks active API requests
145
+ isThereAnyDataChangeInAform Tracks form/data changes
146
+ πŸ›  Available Functions
147
+ setStateValue(key, value)
148
+
149
+ Store any value globally.
150
+
151
+ setStateValue("profile", userData);
152
+
153
+ getStateItem(key)
154
+
155
+ Read stored data.
156
+
157
+ const users = getStateItem("users");
158
+
159
+ sleep(ms)
160
+
161
+ Delay execution.
162
+
163
+ await sleep(1000); // wait 1 second
164
+
165
+ validateLength(obj)
166
+
167
+ Check if data exists.
168
+
169
+ validateLength([]); // 0
170
+ validateLength({ a: 1 }); // 1
171
+ import usePomZStore from "septor-store-react";
172
+ const { stateGeneratorApi } = usePomZStore();
173
+
174
+ 🌐 API Handling
175
+ stateGeneratorApi(config, onData)
176
+
177
+ This is the main function you’ll use to fetch API data.
178
+
179
+ stateGeneratorApi(
180
+ {
181
+ stateKey: "products",
182
+ req: {
183
+ url: "/products",
184
+ method: "GET",
185
+ },
186
+ reload: false,
187
+ time: 0,
188
+ mStore: { mUse: true },
189
+ },
190
+ (data) => {
191
+ console.log("Received data:", data);
192
+ }
193
+ );
194
+
195
+ Configuration Options
196
+ Option Description
197
+ stateKey Where data is stored
198
+ req Axios request config
199
+ reload Force API reload
200
+ time Delay before reload (seconds)
201
+ mStore.mUse Enable sessionStorage
202
+ πŸ’Ύ Session Storage Cache
203
+
204
+ Enable caching like this:
205
+
206
+ stateGeneratorApi({
207
+ stateKey: "orders",
208
+ req: { url: "/orders" },
209
+ mStore: { mUse: true },
210
+ });
211
+
212
+
213
+ let use the state in other file
214
+ import usePomZStore from "septor-store-react";
215
+ const store = usePomZStore();
216
+ store.orders
217
+
218
+
219
+ set the new state in the store
220
+ store.YourGlobalState="I have new data "
221
+
222
+
223
+ let use the state in other file
224
+ import usePomZStore from "septor-store-react";
225
+ const store = usePomZStore();
226
+ console.log(store.YourGlobalState)
227
+
228
+
229
+
230
+ βœ” Data persists after refresh
231
+ βœ” Faster loading
232
+ βœ” Optional per request
233
+
234
+ 🚫 Duplicate API Protection
235
+
236
+ If the same API request is already running, it won’t run again.
237
+
238
+ callApiData("users", "GET_USERS", { url: "/users" });
239
+
240
+ ### Team Rules
241
+ - Do not call axios directly in components
242
+ - Use `stateGeneratorApi` for all API calls
243
+ - Use `STORE_KEYS` constants
244
+ - Never mutate state directly
245
+
246
+
247
+ This prevents:
248
+
249
+ Double API calls
250
+
251
+ Race conditions
252
+
253
+ Wasted network requests
254
+
255
+ πŸ”” Track Data Changes
256
+ isThereAnyDataChangeInAform
257
+
258
+
259
+ Useful for:
260
+
261
+ Form dirty checks
262
+
263
+ Save warnings
264
+
265
+ Conditional reloads
266
+
267
+ ⚠️ Important Notes
268
+
269
+ Axios instance is imported internally
270
+
271
+ Designed for browser apps (uses sessionStorage)
272
+
273
+ loading is global (not per request)
274
+
275
+ TypeScript typings are recommended for large apps
276
+
277
+ βœ… Best Use Cases
278
+
279
+ Admin dashboards
280
+
281
+ Data-heavy React apps
282
+
283
+ Forms with shared state
284
+
285
+ Apps replacing Redux with simpler logic
286
+
287
+ 🏁 Summary
288
+
289
+ PomZStore gives you:
290
+
291
+ Global state
292
+
293
+ Safe API calls
294
+
295
+ Smart caching
296
+
297
+ Minimal setup
298
+
299
+ Simple store. Real-world features. Zero Redux boilerplate.
300
+
301
+ Final Verdict
302
+ This structure gives you:
303
+ βœ” Clean ownership
304
+ βœ” Easy reviews
305
+ βœ” Safe refactors
306
+ βœ” Scalable collaboration
307
+
308
+ Simple enough for juniors. Powerful enough for seniors.# septor-store-react
309
+
310
+ Team Rules
311
+
312
+ Do not call Axios directly in components
313
+
314
+ Use stateGeneratorApi for all API calls
315
+
316
+ Use constants for stateKey
317
+
318
+ Never mutate state directly
319
+ ### Note
320
+
321
+ - This package is designed with both junior and senior developers in mind, making state management and API handling effortless and reliable. By intelligently preventing unnecessary and duplicate API calls, it optimizes your app’s performance and reduces network overhead β€” a huge win for user experience and resource management.
322
+ It empowers your application with dynamic, flexible state generation and smart caching, so your data is always fresh yet efficiently retrieved. The built-in loading states and error handling simplify complex async workflows, letting you focus more on building features rather than wrestling with data consistency.
323
+ Whether you're building a small project or scaling a large application, septor-store offers a clean, extensible, and maintainable approach to state management that saves you time, prevents bugs, and keeps your codebase organized.
324
+
325
+
326
+ you Can use septor-store documentation
327
+ ``https://www.npmjs.com/package/septor-store?activeTab=readme``