beestate 0.1.4 → 0.1.5

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.
Files changed (69) hide show
  1. package/README.md +1 -0
  2. package/dist/@types/InternalStore.d.ts +21 -30
  3. package/dist/@types/StoreProvider.d.ts +2 -2
  4. package/dist/@types/createStore.d.ts +5 -6
  5. package/dist/@types/createStoreRegistry.d.ts +8 -5
  6. package/dist/@types/createUseDispatcher.d.ts +6 -6
  7. package/dist/@types/createUseLatest.d.ts +11 -0
  8. package/dist/@types/createUseProp.d.ts +3 -6
  9. package/dist/@types/createUsePropAll.d.ts +3 -6
  10. package/dist/@types/createUseStore.d.ts +11 -11
  11. package/dist/@types/index.d.ts +11 -3
  12. package/dist/@types/pipe/Error.d.ts +6 -0
  13. package/dist/@types/pipe/check.d.ts +37 -0
  14. package/dist/@types/pipe/createPipeKit.d.ts +24 -0
  15. package/dist/@types/pipe/debug/createDebugger.d.ts +2 -0
  16. package/dist/@types/pipe/debug/debugInstruction.d.ts +1 -0
  17. package/dist/@types/pipe/debug/extendedDebugInstruction.d.ts +5 -0
  18. package/dist/@types/pipe/debug/index.d.ts +4 -0
  19. package/dist/@types/pipe/debug/log.d.ts +2 -0
  20. package/dist/@types/pipe/deepCopy.env-detect.dev.d.ts +1 -0
  21. package/dist/@types/pipe/deepCopy.env-detect.main.d.ts +4 -0
  22. package/dist/@types/pipe/entities/Adjunct.d.ts +3 -0
  23. package/dist/@types/pipe/entities/Connect.d.ts +9 -0
  24. package/dist/@types/pipe/entities/DataBarrel.d.ts +24 -0
  25. package/dist/@types/pipe/entities/Fill.d.ts +25 -0
  26. package/dist/@types/pipe/entities/Instruction.d.ts +81 -0
  27. package/dist/@types/pipe/entities/ParentPipe.d.ts +9 -0
  28. package/dist/@types/pipe/entities/Pipe.d.ts +57 -0
  29. package/dist/@types/pipe/entities/Stream.d.ts +13 -0
  30. package/dist/@types/pipe/entities/StreamGroup.d.ts +25 -0
  31. package/dist/@types/pipe/entities/index.d.ts +9 -0
  32. package/dist/@types/pipe/index.core.d.ts +26 -0
  33. package/dist/@types/pipe/index.d.ts +4 -0
  34. package/dist/@types/pipe/index.debug.d.ts +14 -0
  35. package/dist/@types/pipe/instruction.d.ts +9 -0
  36. package/dist/@types/requestState.d.ts +19 -0
  37. package/dist/@types/requestStateDefault.d.ts +7 -0
  38. package/dist/@types/requestStatus.d.ts +12 -0
  39. package/dist/@types/types/Dispatcher.d.ts +5 -7
  40. package/dist/@types/types/InitInstance.d.ts +2 -2
  41. package/dist/@types/types/InitPayload.d.ts +3 -4
  42. package/dist/@types/types/InternalStoreProps.d.ts +6 -6
  43. package/dist/@types/types/Reducer.d.ts +2 -2
  44. package/dist/@types/types/ReducerLink.d.ts +8 -6
  45. package/dist/@types/types/ReducerMap.d.ts +2 -2
  46. package/dist/@types/types/ReducerPayload.d.ts +3 -4
  47. package/dist/@types/types/RegisterDefaultInstance.d.ts +2 -2
  48. package/dist/@types/types/RegisterInstance.d.ts +3 -3
  49. package/dist/@types/types/RequestState/RequestAbortedState.d.ts +12 -0
  50. package/dist/@types/types/RequestState/RequestFulfilledState.d.ts +12 -0
  51. package/dist/@types/types/RequestState/RequestIdleState.d.ts +12 -0
  52. package/dist/@types/types/RequestState/RequestPendingState.d.ts +12 -0
  53. package/dist/@types/types/RequestState/RequestRejectedState.d.ts +12 -0
  54. package/dist/@types/types/RequestState.d.ts +7 -0
  55. package/dist/@types/types/RequestStateMeta.d.ts +1 -0
  56. package/dist/@types/types/RequestStateStoreKey.d.ts +5 -0
  57. package/dist/@types/types/ResetInstance.d.ts +1 -1
  58. package/dist/@types/types/ResetPayload.d.ts +3 -4
  59. package/dist/@types/types/StateLink.d.ts +5 -5
  60. package/dist/@types/types/Store.d.ts +8 -8
  61. package/dist/@types/types/StoreController.d.ts +5 -5
  62. package/dist/@types/types/StoreControllerInstance.d.ts +3 -3
  63. package/dist/@types/types/StoreRegistry.d.ts +1 -1
  64. package/dist/@types/types/UseProp.d.ts +7 -0
  65. package/dist/@types/types/UsePropAll.d.ts +7 -0
  66. package/dist/@types/types/index.d.ts +10 -0
  67. package/dist/cjs/index.cjs.js +139 -45
  68. package/dist/esm/index.esm.js +139 -47
  69. package/package.json +2 -1
@@ -43,30 +43,47 @@ function createUseDispatcher(storeRegistry) {
43
43
  };
44
44
  }
45
45
 
46
+ function createUseLatest(storeRegistry) {
47
+ return function useLatest(saga, reducerLinks, instanceKey) {
48
+ return;
49
+ };
50
+ }
51
+
46
52
  function createUseProp(storeRegistry) {
47
53
  return function useProp(stateLink, instanceKey) {
48
54
  const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
49
55
  const contextInstanceKey = React.useContext(internalStoreProps.context);
50
56
  const actualInstanceKey = instanceKey ?? contextInstanceKey ?? DEFAULT_INSTANCE_KEY;
51
- // TODO Вынести в отдельную функцию, т.к. уже встречается в проекте пару раз
52
- if (!(internalStoreProps.uniqKey in storeRegistry)) {
53
- throw new Error(`Store "${internalStoreProps.name}" is not registered.`);
54
- }
55
- // TODO Вынести в отдельную функцию, т.к. уже встречается в проекте пару раз
56
- if (!(storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey])) {
57
- throw new Error(`Store "${internalStoreProps.name}" is not initialized for instance "${String(actualInstanceKey)}".`);
58
- }
59
- const internalStore = storeRegistry[internalStoreProps.uniqKey].internalStore;
60
- const subscribe = React.useCallback((listener) => {
61
- return internalStore.subscribe(actualInstanceKey, listener);
62
- }, [actualInstanceKey, internalStore]);
63
- const getSnapshot = React.useCallback(() => {
64
- return internalStore.getSnapshot(actualInstanceKey);
65
- }, [actualInstanceKey, internalStore]);
57
+ const [, setUninitializedHack] = React.useState(0);
58
+ const initialized = internalStoreProps.uniqKey in storeRegistry && storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey];
59
+ const { getSnapshot, subscribe } = React.useMemo(() => {
60
+ let subscribe;
61
+ let getSnapshot;
62
+ if (initialized) {
63
+ const internalStore = storeRegistry[internalStoreProps.uniqKey].internalStore;
64
+ subscribe = (listener) => {
65
+ return internalStore.subscribe(actualInstanceKey, listener);
66
+ };
67
+ getSnapshot = () => {
68
+ return internalStore.getState(actualInstanceKey);
69
+ };
70
+ }
71
+ else {
72
+ subscribe = () => () => undefined;
73
+ getSnapshot = () => internalStoreProps.initialState;
74
+ }
75
+ return { getSnapshot, subscribe };
76
+ }, [actualInstanceKey, initialized, internalStoreProps, storeRegistry]);
66
77
  const selector = React.useCallback((state) => {
67
78
  return state[stateLink.stateName];
68
79
  }, [stateLink]);
69
- return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector);
80
+ React.useEffect(() => {
81
+ const initializedAfterEffect = internalStoreProps.uniqKey in storeRegistry && storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey];
82
+ if (!initialized && initializedAfterEffect) {
83
+ setUninitializedHack(state => state + 1);
84
+ }
85
+ }, [actualInstanceKey, initialized, internalStoreProps, storeRegistry]);
86
+ return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
70
87
  };
71
88
  }
72
89
 
@@ -82,7 +99,7 @@ function createUsePropAll(storeRegistry) {
82
99
  return internalStore.subscribeAll(listener);
83
100
  }, [internalStore]);
84
101
  const getSnapshot = React.useCallback(() => {
85
- return internalStore.getSnapshotAll();
102
+ return internalStore.getStateAll();
86
103
  }, [internalStore]);
87
104
  const selector = React.useCallback((state) => {
88
105
  let stateAll;
@@ -114,7 +131,7 @@ function createUsePropAll(storeRegistry) {
114
131
  return prevStateAllRef.current.prevStateAll;
115
132
  }
116
133
  }, [instanceKeys, stateLink]);
117
- return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector);
134
+ return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
118
135
  };
119
136
  }
120
137
  function isEqual(prevStateAll, stateAll) {
@@ -133,18 +150,15 @@ function isEqual(prevStateAll, stateAll) {
133
150
 
134
151
  class InternalStore {
135
152
  constructor(name) {
136
- this.getStateAll = () => {
137
- return this.state;
138
- };
139
153
  this.getState = (instanceKey) => {
140
154
  return this.state[instanceKey];
141
155
  };
156
+ this.getStateAll = () => {
157
+ return this.state;
158
+ };
142
159
  this.initInstance = (instanceKey, initialState, initPayload, initReducer) => {
143
160
  const initState = initReducer(initialState, initPayload);
144
- this.state = {
145
- ...this.state,
146
- [instanceKey]: initState,
147
- };
161
+ this.state = { ...this.state, [instanceKey]: initState };
148
162
  // TODO Убрать в логгер
149
163
  console.log(`initInstance [store: ${this.name}, instance: ${String(instanceKey)}]:`);
150
164
  console.dir(this.state);
@@ -175,24 +189,15 @@ class InternalStore {
175
189
  this.listenersAll.delete(listener);
176
190
  };
177
191
  };
178
- this.getSnapshot = (instanceKey) => {
179
- return this.state[instanceKey];
180
- };
181
- this.getSnapshotAll = () => {
182
- return this.state;
183
- };
184
192
  this.dispatch = (instanceKey, payload, reducer) => {
185
193
  const instanceState = this.state[instanceKey];
186
- const changes = reducer(instanceState, payload);
187
- this.update(instanceKey, changes);
194
+ const instanceNextState = reducer(instanceState, payload);
195
+ this.state = { ...this.state, [instanceKey]: instanceNextState };
196
+ this.listeners[instanceKey].forEach((listener) => listener(instanceKey, payload, reducer));
197
+ this.listenersAll.forEach((listener) => listener(instanceKey, payload, reducer));
188
198
  // TODO Убрать в логгер
189
199
  console.log(`dispatch [store: ${this.name}, instance: ${String(instanceKey)}, action: ${reducer.name}]:`);
190
- console.dir({ payload, [`prev state`]: instanceState, [`next state`]: changes });
191
- };
192
- this.update = (instanceKey, changes) => {
193
- this.state = { ...this.state, [instanceKey]: changes };
194
- this.listeners[instanceKey].forEach((listener) => listener());
195
- this.listenersAll.forEach((listener) => listener());
200
+ console.dir({ payload, [`prev state`]: instanceState, [`next state`]: instanceNextState });
196
201
  };
197
202
  this.listeners = {};
198
203
  this.listenersAll = new Set();
@@ -279,23 +284,26 @@ function createUseStore(storeRegistry) {
279
284
 
280
285
  function createStoreRegistry() {
281
286
  const storeRegistry = {};
282
- const useDispatcher = createUseDispatcher(storeRegistry);
287
+ const useStore = createUseStore(storeRegistry);
283
288
  const useProp = createUseProp(storeRegistry);
284
289
  const usePropAll = createUsePropAll(storeRegistry);
285
- const useStore = createUseStore(storeRegistry);
290
+ const useDispatcher = createUseDispatcher(storeRegistry);
291
+ const useLatest = createUseLatest();
286
292
  return {
287
- useDispatcher,
293
+ storeRegistry,
294
+ useStore,
288
295
  useProp,
289
296
  usePropAll,
290
- useStore,
297
+ useDispatcher,
298
+ useLatest,
291
299
  };
292
300
  }
293
301
 
294
302
  function createStore(name, initialState, reducers) {
295
303
  const context = React.createContext(null);
296
304
  const internalStoreProps = {
297
- [`$$init`]: reducers[`$$init`],
298
- [`$$reset`]: reducers[`$$reset`],
305
+ $$init: reducers.$$init,
306
+ $$reset: reducers.$$reset,
299
307
  context,
300
308
  initialState,
301
309
  name,
@@ -324,6 +332,90 @@ function createStore(name, initialState, reducers) {
324
332
  return store;
325
333
  }
326
334
 
335
+ const requestStateDefault = {
336
+ isAborted: false,
337
+ isFulfilled: false,
338
+ isIdle: false,
339
+ isPending: false,
340
+ isRejected: false,
341
+ };
342
+
343
+ const requestStatus = {
344
+ IDLE: 'IDLE',
345
+ PENDING: 'PENDING',
346
+ FULFILLED: 'FULFILLED',
347
+ REJECTED: 'REJECTED',
348
+ ABORTED: 'ABORTED',
349
+ FORCE_IDLE: 'IDLE',
350
+ FORCE_PENDING: 'PENDING',
351
+ FORCE_FULFILLED: 'FULFILLED',
352
+ FORCE_REJECTED: 'REJECTED',
353
+ FORCE_ABORTED: 'ABORTED',
354
+ };
355
+
356
+ const requestState = {
357
+ idle: (meta) => {
358
+ return {
359
+ ...requestStateDefault,
360
+ isIdle: true,
361
+ status: requestStatus.IDLE,
362
+ error: null,
363
+ meta: meta ?? null,
364
+ };
365
+ },
366
+ pending: (meta) => {
367
+ return {
368
+ ...requestStateDefault,
369
+ isPending: true,
370
+ status: requestStatus.PENDING,
371
+ error: null,
372
+ meta: meta ?? null,
373
+ };
374
+ },
375
+ fulfilled: (meta) => {
376
+ return {
377
+ ...requestStateDefault,
378
+ isFulfilled: true,
379
+ status: requestStatus.FULFILLED,
380
+ meta: meta ?? null,
381
+ error: null,
382
+ };
383
+ },
384
+ rejected: (error, meta) => {
385
+ return {
386
+ ...requestStateDefault,
387
+ isRejected: true,
388
+ status: requestStatus.REJECTED,
389
+ error: error ?? null,
390
+ meta: meta ?? null,
391
+ };
392
+ },
393
+ aborted: (meta) => {
394
+ return {
395
+ ...requestStateDefault,
396
+ isAborted: true,
397
+ status: requestStatus.ABORTED,
398
+ meta: meta ?? null,
399
+ error: null,
400
+ };
401
+ },
402
+ forceIdle: (meta) => {
403
+ return requestState.idle(meta);
404
+ },
405
+ forcePending: (meta) => {
406
+ return requestState.pending(meta);
407
+ },
408
+ forceFulfilled: (meta) => {
409
+ return requestState.fulfilled(meta);
410
+ },
411
+ forceRejected: (error, meta) => {
412
+ return requestState.rejected(error, meta);
413
+ },
414
+ forceAborted: (meta) => {
415
+ return requestState.aborted(meta);
416
+ },
417
+ };
418
+
327
419
  function StoreProvider(props) {
328
420
  const Context = props.store[INTERNAL_STORE_PROPS_ACCESSOR].context;
329
421
  return (jsxRuntime.jsx(Context.Provider, { value: props.instanceKey, children: props.children }));
@@ -336,6 +428,8 @@ exports.InternalStore = InternalStore;
336
428
  exports.StoreProvider = StoreProvider;
337
429
  exports.createStore = createStore;
338
430
  exports.createStoreRegistry = createStoreRegistry;
431
+ exports.requestState = requestState;
432
+ exports.requestStatus = requestStatus;
339
433
  exports.useDispatcher = useDispatcher;
340
434
  exports.useProp = useProp;
341
435
  exports.usePropAll = usePropAll;
@@ -1,4 +1,4 @@
1
- import React, { useContext, useMemo, useCallback, useRef, useEffect } from 'react';
1
+ import React, { useContext, useMemo, useState, useCallback, useEffect, useRef } from 'react';
2
2
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
@@ -41,30 +41,47 @@ function createUseDispatcher(storeRegistry) {
41
41
  };
42
42
  }
43
43
 
44
+ function createUseLatest(storeRegistry) {
45
+ return function useLatest(saga, reducerLinks, instanceKey) {
46
+ return;
47
+ };
48
+ }
49
+
44
50
  function createUseProp(storeRegistry) {
45
51
  return function useProp(stateLink, instanceKey) {
46
52
  const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
47
53
  const contextInstanceKey = useContext(internalStoreProps.context);
48
54
  const actualInstanceKey = instanceKey ?? contextInstanceKey ?? DEFAULT_INSTANCE_KEY;
49
- // TODO Вынести в отдельную функцию, т.к. уже встречается в проекте пару раз
50
- if (!(internalStoreProps.uniqKey in storeRegistry)) {
51
- throw new Error(`Store "${internalStoreProps.name}" is not registered.`);
52
- }
53
- // TODO Вынести в отдельную функцию, т.к. уже встречается в проекте пару раз
54
- if (!(storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey])) {
55
- throw new Error(`Store "${internalStoreProps.name}" is not initialized for instance "${String(actualInstanceKey)}".`);
56
- }
57
- const internalStore = storeRegistry[internalStoreProps.uniqKey].internalStore;
58
- const subscribe = useCallback((listener) => {
59
- return internalStore.subscribe(actualInstanceKey, listener);
60
- }, [actualInstanceKey, internalStore]);
61
- const getSnapshot = useCallback(() => {
62
- return internalStore.getSnapshot(actualInstanceKey);
63
- }, [actualInstanceKey, internalStore]);
55
+ const [, setUninitializedHack] = useState(0);
56
+ const initialized = internalStoreProps.uniqKey in storeRegistry && storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey];
57
+ const { getSnapshot, subscribe } = useMemo(() => {
58
+ let subscribe;
59
+ let getSnapshot;
60
+ if (initialized) {
61
+ const internalStore = storeRegistry[internalStoreProps.uniqKey].internalStore;
62
+ subscribe = (listener) => {
63
+ return internalStore.subscribe(actualInstanceKey, listener);
64
+ };
65
+ getSnapshot = () => {
66
+ return internalStore.getState(actualInstanceKey);
67
+ };
68
+ }
69
+ else {
70
+ subscribe = () => () => undefined;
71
+ getSnapshot = () => internalStoreProps.initialState;
72
+ }
73
+ return { getSnapshot, subscribe };
74
+ }, [actualInstanceKey, initialized, internalStoreProps, storeRegistry]);
64
75
  const selector = useCallback((state) => {
65
76
  return state[stateLink.stateName];
66
77
  }, [stateLink]);
67
- return useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector);
78
+ useEffect(() => {
79
+ const initializedAfterEffect = internalStoreProps.uniqKey in storeRegistry && storeRegistry[internalStoreProps.uniqKey].instances[actualInstanceKey];
80
+ if (!initialized && initializedAfterEffect) {
81
+ setUninitializedHack(state => state + 1);
82
+ }
83
+ }, [actualInstanceKey, initialized, internalStoreProps, storeRegistry]);
84
+ return useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
68
85
  };
69
86
  }
70
87
 
@@ -80,7 +97,7 @@ function createUsePropAll(storeRegistry) {
80
97
  return internalStore.subscribeAll(listener);
81
98
  }, [internalStore]);
82
99
  const getSnapshot = useCallback(() => {
83
- return internalStore.getSnapshotAll();
100
+ return internalStore.getStateAll();
84
101
  }, [internalStore]);
85
102
  const selector = useCallback((state) => {
86
103
  let stateAll;
@@ -112,7 +129,7 @@ function createUsePropAll(storeRegistry) {
112
129
  return prevStateAllRef.current.prevStateAll;
113
130
  }
114
131
  }, [instanceKeys, stateLink]);
115
- return useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector);
132
+ return useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
116
133
  };
117
134
  }
118
135
  function isEqual(prevStateAll, stateAll) {
@@ -131,18 +148,15 @@ function isEqual(prevStateAll, stateAll) {
131
148
 
132
149
  class InternalStore {
133
150
  constructor(name) {
134
- this.getStateAll = () => {
135
- return this.state;
136
- };
137
151
  this.getState = (instanceKey) => {
138
152
  return this.state[instanceKey];
139
153
  };
154
+ this.getStateAll = () => {
155
+ return this.state;
156
+ };
140
157
  this.initInstance = (instanceKey, initialState, initPayload, initReducer) => {
141
158
  const initState = initReducer(initialState, initPayload);
142
- this.state = {
143
- ...this.state,
144
- [instanceKey]: initState,
145
- };
159
+ this.state = { ...this.state, [instanceKey]: initState };
146
160
  // TODO Убрать в логгер
147
161
  console.log(`initInstance [store: ${this.name}, instance: ${String(instanceKey)}]:`);
148
162
  console.dir(this.state);
@@ -173,24 +187,15 @@ class InternalStore {
173
187
  this.listenersAll.delete(listener);
174
188
  };
175
189
  };
176
- this.getSnapshot = (instanceKey) => {
177
- return this.state[instanceKey];
178
- };
179
- this.getSnapshotAll = () => {
180
- return this.state;
181
- };
182
190
  this.dispatch = (instanceKey, payload, reducer) => {
183
191
  const instanceState = this.state[instanceKey];
184
- const changes = reducer(instanceState, payload);
185
- this.update(instanceKey, changes);
192
+ const instanceNextState = reducer(instanceState, payload);
193
+ this.state = { ...this.state, [instanceKey]: instanceNextState };
194
+ this.listeners[instanceKey].forEach((listener) => listener(instanceKey, payload, reducer));
195
+ this.listenersAll.forEach((listener) => listener(instanceKey, payload, reducer));
186
196
  // TODO Убрать в логгер
187
197
  console.log(`dispatch [store: ${this.name}, instance: ${String(instanceKey)}, action: ${reducer.name}]:`);
188
- console.dir({ payload, [`prev state`]: instanceState, [`next state`]: changes });
189
- };
190
- this.update = (instanceKey, changes) => {
191
- this.state = { ...this.state, [instanceKey]: changes };
192
- this.listeners[instanceKey].forEach((listener) => listener());
193
- this.listenersAll.forEach((listener) => listener());
198
+ console.dir({ payload, [`prev state`]: instanceState, [`next state`]: instanceNextState });
194
199
  };
195
200
  this.listeners = {};
196
201
  this.listenersAll = new Set();
@@ -277,23 +282,26 @@ function createUseStore(storeRegistry) {
277
282
 
278
283
  function createStoreRegistry() {
279
284
  const storeRegistry = {};
280
- const useDispatcher = createUseDispatcher(storeRegistry);
285
+ const useStore = createUseStore(storeRegistry);
281
286
  const useProp = createUseProp(storeRegistry);
282
287
  const usePropAll = createUsePropAll(storeRegistry);
283
- const useStore = createUseStore(storeRegistry);
288
+ const useDispatcher = createUseDispatcher(storeRegistry);
289
+ const useLatest = createUseLatest();
284
290
  return {
285
- useDispatcher,
291
+ storeRegistry,
292
+ useStore,
286
293
  useProp,
287
294
  usePropAll,
288
- useStore,
295
+ useDispatcher,
296
+ useLatest,
289
297
  };
290
298
  }
291
299
 
292
300
  function createStore(name, initialState, reducers) {
293
301
  const context = React.createContext(null);
294
302
  const internalStoreProps = {
295
- [`$$init`]: reducers[`$$init`],
296
- [`$$reset`]: reducers[`$$reset`],
303
+ $$init: reducers.$$init,
304
+ $$reset: reducers.$$reset,
297
305
  context,
298
306
  initialState,
299
307
  name,
@@ -322,6 +330,90 @@ function createStore(name, initialState, reducers) {
322
330
  return store;
323
331
  }
324
332
 
333
+ const requestStateDefault = {
334
+ isAborted: false,
335
+ isFulfilled: false,
336
+ isIdle: false,
337
+ isPending: false,
338
+ isRejected: false,
339
+ };
340
+
341
+ const requestStatus = {
342
+ IDLE: 'IDLE',
343
+ PENDING: 'PENDING',
344
+ FULFILLED: 'FULFILLED',
345
+ REJECTED: 'REJECTED',
346
+ ABORTED: 'ABORTED',
347
+ FORCE_IDLE: 'IDLE',
348
+ FORCE_PENDING: 'PENDING',
349
+ FORCE_FULFILLED: 'FULFILLED',
350
+ FORCE_REJECTED: 'REJECTED',
351
+ FORCE_ABORTED: 'ABORTED',
352
+ };
353
+
354
+ const requestState = {
355
+ idle: (meta) => {
356
+ return {
357
+ ...requestStateDefault,
358
+ isIdle: true,
359
+ status: requestStatus.IDLE,
360
+ error: null,
361
+ meta: meta ?? null,
362
+ };
363
+ },
364
+ pending: (meta) => {
365
+ return {
366
+ ...requestStateDefault,
367
+ isPending: true,
368
+ status: requestStatus.PENDING,
369
+ error: null,
370
+ meta: meta ?? null,
371
+ };
372
+ },
373
+ fulfilled: (meta) => {
374
+ return {
375
+ ...requestStateDefault,
376
+ isFulfilled: true,
377
+ status: requestStatus.FULFILLED,
378
+ meta: meta ?? null,
379
+ error: null,
380
+ };
381
+ },
382
+ rejected: (error, meta) => {
383
+ return {
384
+ ...requestStateDefault,
385
+ isRejected: true,
386
+ status: requestStatus.REJECTED,
387
+ error: error ?? null,
388
+ meta: meta ?? null,
389
+ };
390
+ },
391
+ aborted: (meta) => {
392
+ return {
393
+ ...requestStateDefault,
394
+ isAborted: true,
395
+ status: requestStatus.ABORTED,
396
+ meta: meta ?? null,
397
+ error: null,
398
+ };
399
+ },
400
+ forceIdle: (meta) => {
401
+ return requestState.idle(meta);
402
+ },
403
+ forcePending: (meta) => {
404
+ return requestState.pending(meta);
405
+ },
406
+ forceFulfilled: (meta) => {
407
+ return requestState.fulfilled(meta);
408
+ },
409
+ forceRejected: (error, meta) => {
410
+ return requestState.rejected(error, meta);
411
+ },
412
+ forceAborted: (meta) => {
413
+ return requestState.aborted(meta);
414
+ },
415
+ };
416
+
325
417
  function StoreProvider(props) {
326
418
  const Context = props.store[INTERNAL_STORE_PROPS_ACCESSOR].context;
327
419
  return (jsx(Context.Provider, { value: props.instanceKey, children: props.children }));
@@ -329,4 +421,4 @@ function StoreProvider(props) {
329
421
 
330
422
  const { useDispatcher, useProp, usePropAll, useStore, } = createStoreRegistry();
331
423
 
332
- export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, useDispatcher, useProp, usePropAll, useStore };
424
+ export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, requestState, requestStatus, useDispatcher, useProp, usePropAll, useStore };
package/package.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "author": "Yakov Dalinchuk <yakov.dalinchuk@gmail.com>",
2
3
  "dependencies": {
3
4
  "use-sync-external-store": "^1.5.0"
4
5
  },
@@ -19,5 +20,5 @@
19
20
  "prepublishOnly": "npm run build"
20
21
  },
21
22
  "types": "dist/@types",
22
- "version": "0.1.4"
23
+ "version": "0.1.5"
23
24
  }