beestate 0.1.4 → 0.1.6
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 +1 -0
- package/dist/@types/InternalStore.d.ts +15 -54
- package/dist/@types/StoreProvider.d.ts +2 -2
- package/dist/@types/createStore.d.ts +5 -6
- package/dist/@types/createStoreController.d.ts +6 -0
- package/dist/@types/createStoreRegistry.d.ts +8 -5
- package/dist/@types/createUseDispatcher.d.ts +7 -7
- package/dist/@types/createUseLatest.d.ts +11 -0
- package/dist/@types/createUseProp.d.ts +3 -6
- package/dist/@types/createUsePropAll.d.ts +3 -6
- package/dist/@types/createUseStore.d.ts +11 -11
- package/dist/@types/index.d.ts +12 -4
- package/dist/@types/pipe/Error.d.ts +6 -0
- package/dist/@types/pipe/check.d.ts +37 -0
- package/dist/@types/pipe/createPipeKit.d.ts +24 -0
- package/dist/@types/pipe/debug/createDebugger.d.ts +2 -0
- package/dist/@types/pipe/debug/debugInstruction.d.ts +1 -0
- package/dist/@types/pipe/debug/extendedDebugInstruction.d.ts +5 -0
- package/dist/@types/pipe/debug/index.d.ts +4 -0
- package/dist/@types/pipe/debug/log.d.ts +2 -0
- package/dist/@types/pipe/deepCopy.env-detect.dev.d.ts +1 -0
- package/dist/@types/pipe/deepCopy.env-detect.main.d.ts +4 -0
- package/dist/@types/pipe/entities/Adjunct.d.ts +3 -0
- package/dist/@types/pipe/entities/Connect.d.ts +9 -0
- package/dist/@types/pipe/entities/DataBarrel.d.ts +24 -0
- package/dist/@types/pipe/entities/Fill.d.ts +25 -0
- package/dist/@types/pipe/entities/Instruction.d.ts +81 -0
- package/dist/@types/pipe/entities/ParentPipe.d.ts +9 -0
- package/dist/@types/pipe/entities/Pipe.d.ts +57 -0
- package/dist/@types/pipe/entities/Stream.d.ts +13 -0
- package/dist/@types/pipe/entities/StreamGroup.d.ts +25 -0
- package/dist/@types/pipe/entities/index.d.ts +9 -0
- package/dist/@types/pipe/index.core.d.ts +26 -0
- package/dist/@types/pipe/index.d.ts +4 -0
- package/dist/@types/pipe/index.debug.d.ts +14 -0
- package/dist/@types/pipe/instruction.d.ts +9 -0
- package/dist/@types/requestState.d.ts +19 -0
- package/dist/@types/requestStateDefault.d.ts +7 -0
- package/dist/@types/requestStatus.d.ts +12 -0
- package/dist/@types/types/Dispatcher.d.ts +5 -7
- package/dist/@types/types/InitInstance.d.ts +2 -2
- package/dist/@types/types/InitPayload.d.ts +3 -4
- package/dist/@types/types/InstanceKey.d.ts +1 -1
- package/dist/@types/types/InternalStore/Dispatch.d.ts +7 -0
- package/dist/@types/types/InternalStore/GetState.d.ts +5 -0
- package/dist/@types/types/InternalStore/GetStateAll.d.ts +5 -0
- package/dist/@types/types/InternalStore/InitInstance.d.ts +8 -0
- package/dist/@types/types/InternalStore/Listener.d.ts +7 -0
- package/dist/@types/types/InternalStore/ListenerAll.d.ts +7 -0
- package/dist/@types/types/InternalStore/ResetInstance.d.ts +6 -0
- package/dist/@types/types/InternalStore/Subscribe.d.ts +7 -0
- package/dist/@types/types/InternalStore/SubscribeAll.d.ts +6 -0
- package/dist/@types/types/InternalStore/Unsubscribe.d.ts +3 -0
- package/dist/@types/types/InternalStore/UnsubscribeAll.d.ts +3 -0
- package/dist/@types/types/InternalStoreProps.d.ts +6 -6
- package/dist/@types/types/Reducer.d.ts +2 -2
- package/dist/@types/types/ReducerLink.d.ts +8 -6
- package/dist/@types/types/ReducerMap.d.ts +2 -2
- package/dist/@types/types/ReducerPayload.d.ts +3 -4
- package/dist/@types/types/RegisterDefaultInstance.d.ts +2 -2
- package/dist/@types/types/RegisterInstance.d.ts +3 -3
- package/dist/@types/types/RequestState/RequestAbortedState.d.ts +12 -0
- package/dist/@types/types/RequestState/RequestFulfilledState.d.ts +12 -0
- package/dist/@types/types/RequestState/RequestIdleState.d.ts +12 -0
- package/dist/@types/types/RequestState/RequestPendingState.d.ts +12 -0
- package/dist/@types/types/RequestState/RequestRejectedState.d.ts +12 -0
- package/dist/@types/types/RequestState.d.ts +7 -0
- package/dist/@types/types/RequestStateMeta.d.ts +1 -0
- package/dist/@types/types/RequestStateStoreKey.d.ts +5 -0
- package/dist/@types/types/ResetInstance.d.ts +1 -1
- package/dist/@types/types/ResetPayload.d.ts +3 -4
- package/dist/@types/types/StateLink.d.ts +5 -5
- package/dist/@types/types/Store.d.ts +8 -8
- package/dist/@types/types/StoreController.d.ts +7 -6
- package/dist/@types/types/StoreInstanceController.d.ts +7 -0
- package/dist/@types/types/StoreRegistry.d.ts +1 -1
- package/dist/@types/types/UseProp.d.ts +7 -0
- package/dist/@types/types/UsePropAll.d.ts +7 -0
- package/dist/cjs/index.cjs.js +229 -112
- package/dist/esm/index.esm.js +229 -114
- package/package.json +2 -1
- package/dist/@types/types/StoreControllerInstance.d.ts +0 -7
- package/dist/@types/types/index.d.ts +0 -20
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -43,30 +43,112 @@ 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
|
+
|
|
52
|
+
class InternalStore {
|
|
53
|
+
constructor(name) {
|
|
54
|
+
this.getState = (instanceKey) => {
|
|
55
|
+
return this.state[instanceKey];
|
|
56
|
+
};
|
|
57
|
+
this.getStateAll = () => {
|
|
58
|
+
return this.state;
|
|
59
|
+
};
|
|
60
|
+
this.initInstance = (instanceKey, initialState, initPayload, initReducer) => {
|
|
61
|
+
// TODO От множественной инициализации было решено отказаться. Надо кинуть предупреждение.
|
|
62
|
+
this.state = { ...this.state, [instanceKey]: this.state[instanceKey] ?? initialState };
|
|
63
|
+
// TODO От множественной инициализации было решено отказаться. Надо кинуть предупреждение.
|
|
64
|
+
this.listeners[instanceKey] = this.listeners[instanceKey] ?? new Set();
|
|
65
|
+
this.dispatch(instanceKey, initPayload, initReducer);
|
|
66
|
+
return (resetPayload, resetReducer) => {
|
|
67
|
+
this.dispatch(instanceKey, resetPayload, resetReducer);
|
|
68
|
+
// TODO Тут место для уничтожения состояния экземпляра хранилища через `delete this.state[instanceKey];`
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
this.subscribe = (instanceKey, listener) => {
|
|
72
|
+
this.listeners[instanceKey].add(listener);
|
|
73
|
+
return () => {
|
|
74
|
+
this.listeners[instanceKey].delete(listener);
|
|
75
|
+
if (this.listeners[instanceKey].size === 0) {
|
|
76
|
+
delete this.listeners[instanceKey];
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
this.subscribeAll = (listener) => {
|
|
81
|
+
this.listenersAll.add(listener);
|
|
82
|
+
return () => {
|
|
83
|
+
this.listenersAll.delete(listener);
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
this.dispatch = (instanceKey, payload, reducer) => {
|
|
87
|
+
const instanceState = this.state[instanceKey];
|
|
88
|
+
const instanceNextState = reducer(instanceState, payload);
|
|
89
|
+
this.state = { ...this.state, [instanceKey]: instanceNextState };
|
|
90
|
+
this.listeners[instanceKey].forEach((listener) => listener(instanceKey, payload, reducer));
|
|
91
|
+
this.listenersAll.forEach((listener) => listener(instanceKey, payload, reducer));
|
|
92
|
+
// TODO Убрать в логгер
|
|
93
|
+
console.log(`dispatch [store: ${this.name}, instanceKey: ${String(instanceKey)}, action: ${reducer.name}]:`);
|
|
94
|
+
// TODO Убрать в логгер
|
|
95
|
+
console.log({ payload, [`prev state`]: instanceState, [`next state`]: instanceNextState });
|
|
96
|
+
};
|
|
97
|
+
this.listeners = {};
|
|
98
|
+
this.listenersAll = new Set();
|
|
99
|
+
this.name = name;
|
|
100
|
+
this.state = {};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function createStoreController(storeRegistry, internalStoreProps) {
|
|
105
|
+
let storeController = storeRegistry[internalStoreProps.uniqKey];
|
|
106
|
+
if (!storeController) {
|
|
107
|
+
const internalStore = new InternalStore(internalStoreProps.name);
|
|
108
|
+
storeController = { earlySubscribers: {}, instances: {}, internalStore };
|
|
109
|
+
storeRegistry[internalStoreProps.uniqKey] = storeController;
|
|
110
|
+
}
|
|
111
|
+
return storeController;
|
|
112
|
+
}
|
|
113
|
+
|
|
46
114
|
function createUseProp(storeRegistry) {
|
|
47
115
|
return function useProp(stateLink, instanceKey) {
|
|
48
116
|
const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
49
117
|
const contextInstanceKey = React.useContext(internalStoreProps.context);
|
|
50
118
|
const actualInstanceKey = instanceKey ?? contextInstanceKey ?? DEFAULT_INSTANCE_KEY;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
119
|
+
const [, setUninitializedHack] = React.useState(0);
|
|
120
|
+
const earlySubscriberRef = React.useRef({ earlySubscriber: null });
|
|
121
|
+
const storeController = createStoreController(storeRegistry, internalStoreProps);
|
|
122
|
+
const initialized = actualInstanceKey in storeController.instances;
|
|
123
|
+
const { getSnapshot, subscribe } = React.useMemo(() => {
|
|
124
|
+
let subscribe;
|
|
125
|
+
let getSnapshot;
|
|
126
|
+
if (initialized) {
|
|
127
|
+
subscribe = (listener) => {
|
|
128
|
+
return storeController.internalStore.subscribe(actualInstanceKey, listener);
|
|
129
|
+
};
|
|
130
|
+
getSnapshot = () => {
|
|
131
|
+
return storeController.internalStore.getState(actualInstanceKey);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
subscribe = () => () => undefined;
|
|
136
|
+
getSnapshot = () => internalStoreProps.initialState;
|
|
137
|
+
if (!storeController.earlySubscribers[actualInstanceKey]) {
|
|
138
|
+
storeController.earlySubscribers[actualInstanceKey] = [];
|
|
139
|
+
}
|
|
140
|
+
else if (earlySubscriberRef.current.earlySubscriber) {
|
|
141
|
+
storeController.earlySubscribers[actualInstanceKey].splice(storeController.earlySubscribers[actualInstanceKey].indexOf(earlySubscriberRef.current.earlySubscriber), 1);
|
|
142
|
+
}
|
|
143
|
+
const earlySubscriber = earlySubscriberRef.current.earlySubscriber = () => setUninitializedHack(state => state + 1);
|
|
144
|
+
storeController.earlySubscribers[actualInstanceKey].push(earlySubscriber);
|
|
145
|
+
}
|
|
146
|
+
return { getSnapshot, subscribe };
|
|
147
|
+
}, [actualInstanceKey, initialized, internalStoreProps, storeController]);
|
|
66
148
|
const selector = React.useCallback((state) => {
|
|
67
149
|
return state[stateLink.stateName];
|
|
68
150
|
}, [stateLink]);
|
|
69
|
-
return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot,
|
|
151
|
+
return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
|
|
70
152
|
};
|
|
71
153
|
}
|
|
72
154
|
|
|
@@ -82,7 +164,7 @@ function createUsePropAll(storeRegistry) {
|
|
|
82
164
|
return internalStore.subscribeAll(listener);
|
|
83
165
|
}, [internalStore]);
|
|
84
166
|
const getSnapshot = React.useCallback(() => {
|
|
85
|
-
return internalStore.
|
|
167
|
+
return internalStore.getStateAll();
|
|
86
168
|
}, [internalStore]);
|
|
87
169
|
const selector = React.useCallback((state) => {
|
|
88
170
|
let stateAll;
|
|
@@ -114,7 +196,7 @@ function createUsePropAll(storeRegistry) {
|
|
|
114
196
|
return prevStateAllRef.current.prevStateAll;
|
|
115
197
|
}
|
|
116
198
|
}, [instanceKeys, stateLink]);
|
|
117
|
-
return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot,
|
|
199
|
+
return withSelector.useSyncExternalStoreWithSelector(subscribe, getSnapshot, null, selector);
|
|
118
200
|
};
|
|
119
201
|
}
|
|
120
202
|
function isEqual(prevStateAll, stateAll) {
|
|
@@ -131,119 +213,65 @@ function isEqual(prevStateAll, stateAll) {
|
|
|
131
213
|
}
|
|
132
214
|
}
|
|
133
215
|
|
|
134
|
-
class InternalStore {
|
|
135
|
-
constructor(name) {
|
|
136
|
-
this.getStateAll = () => {
|
|
137
|
-
return this.state;
|
|
138
|
-
};
|
|
139
|
-
this.getState = (instanceKey) => {
|
|
140
|
-
return this.state[instanceKey];
|
|
141
|
-
};
|
|
142
|
-
this.initInstance = (instanceKey, initialState, initPayload, initReducer) => {
|
|
143
|
-
const initState = initReducer(initialState, initPayload);
|
|
144
|
-
this.state = {
|
|
145
|
-
...this.state,
|
|
146
|
-
[instanceKey]: initState,
|
|
147
|
-
};
|
|
148
|
-
// TODO Убрать в логгер
|
|
149
|
-
console.log(`initInstance [store: ${this.name}, instance: ${String(instanceKey)}]:`);
|
|
150
|
-
console.dir(this.state);
|
|
151
|
-
return (resetPayload, resetReducer) => {
|
|
152
|
-
const resetState = resetReducer(initState, resetPayload);
|
|
153
|
-
// TODO Тут место для уничтожения состояния экземпляра хранилища через `delete this.state[instanceKey];`
|
|
154
|
-
this.state = { ...this.state, [instanceKey]: resetState };
|
|
155
|
-
// TODO Убрать в логгер
|
|
156
|
-
console.log(`resetInstance [store: ${this.name}, instance: ${String(instanceKey)}]:`);
|
|
157
|
-
console.dir(this.state);
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
this.subscribe = (instanceKey, listener) => {
|
|
161
|
-
if (!this.listeners[instanceKey]) {
|
|
162
|
-
this.listeners[instanceKey] = new Set();
|
|
163
|
-
}
|
|
164
|
-
this.listeners[instanceKey].add(listener);
|
|
165
|
-
return () => {
|
|
166
|
-
this.listeners[instanceKey].delete(listener);
|
|
167
|
-
if (this.listeners[instanceKey].size === 0) {
|
|
168
|
-
delete this.listeners[instanceKey];
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
this.subscribeAll = (listener) => {
|
|
173
|
-
this.listenersAll.add(listener);
|
|
174
|
-
return () => {
|
|
175
|
-
this.listenersAll.delete(listener);
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
this.getSnapshot = (instanceKey) => {
|
|
179
|
-
return this.state[instanceKey];
|
|
180
|
-
};
|
|
181
|
-
this.getSnapshotAll = () => {
|
|
182
|
-
return this.state;
|
|
183
|
-
};
|
|
184
|
-
this.dispatch = (instanceKey, payload, reducer) => {
|
|
185
|
-
const instanceState = this.state[instanceKey];
|
|
186
|
-
const changes = reducer(instanceState, payload);
|
|
187
|
-
this.update(instanceKey, changes);
|
|
188
|
-
// TODO Убрать в логгер
|
|
189
|
-
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());
|
|
196
|
-
};
|
|
197
|
-
this.listeners = {};
|
|
198
|
-
this.listenersAll = new Set();
|
|
199
|
-
this.name = name;
|
|
200
|
-
this.state = {};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
216
|
function createUseStore(storeRegistry) {
|
|
205
217
|
function useStore(store, ...args) {
|
|
206
218
|
let instanceKeys;
|
|
207
219
|
let registerInstance;
|
|
208
220
|
if (typeof args[0] === `function`) {
|
|
209
|
-
instanceKeys = [];
|
|
221
|
+
instanceKeys = [DEFAULT_INSTANCE_KEY];
|
|
210
222
|
registerInstance = args[0];
|
|
211
223
|
}
|
|
212
224
|
else {
|
|
213
225
|
instanceKeys = args[0];
|
|
214
226
|
registerInstance = args[1];
|
|
215
227
|
}
|
|
216
|
-
|
|
228
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
229
|
+
const actualInstanceKeys = React.useMemo(() => instanceKeys, instanceKeys);
|
|
217
230
|
const storeRef = React.useRef({ store });
|
|
218
231
|
const ownerKeyRef = React.useRef({ ownerKey: Symbol(`ownerKey`) });
|
|
219
232
|
const initInstancesRef = React.useRef({ initInstances: {} });
|
|
220
|
-
React.
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
const storeMismatchWarnedRef = React.useRef({ warned: false });
|
|
234
|
+
if (storeRef.current.store !== store) {
|
|
235
|
+
console.warn(`Store reference mismatch. You must pass the same store instance on every render.`);
|
|
236
|
+
storeMismatchWarnedRef.current.warned = true;
|
|
237
|
+
}
|
|
238
|
+
React.useEffect(() => {
|
|
239
|
+
const { store } = storeRef.current;
|
|
240
|
+
const { ownerKey } = ownerKeyRef.current;
|
|
241
|
+
const { initInstances } = initInstancesRef.current;
|
|
223
242
|
for (const instanceKey of actualInstanceKeys) {
|
|
224
243
|
if (!initInstances[instanceKey]) {
|
|
225
|
-
const ownerKey = ownerKeyRef.current.ownerKey;
|
|
226
244
|
const initInstance = (initPayload) => {
|
|
227
245
|
const internalStoreProps = store[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
228
|
-
|
|
229
|
-
if (!storeController) {
|
|
230
|
-
const internalStore = new InternalStore(internalStoreProps.name);
|
|
231
|
-
storeController = { internalStore, instances: {} };
|
|
232
|
-
storeRegistry[internalStoreProps.uniqKey] = storeController;
|
|
233
|
-
// TODO Убрать в логгер
|
|
234
|
-
console.log(`registerStore [store: ${storeController.internalStore.name}]:`);
|
|
235
|
-
console.dir(storeRegistry);
|
|
236
|
-
}
|
|
246
|
+
const storeController = createStoreController(storeRegistry, internalStoreProps);
|
|
237
247
|
if (!storeController.instances[instanceKey]) {
|
|
238
|
-
|
|
248
|
+
// TODO Убрать в логгер
|
|
249
|
+
console.log(`Store instance initialization [store: ${storeController.internalStore.name}, instanceKey: ${instanceKey.toString()}]`);
|
|
250
|
+
// TODO Убрать в логгер
|
|
251
|
+
console.log({ storeRegistry });
|
|
252
|
+
const resetState = storeController.internalStore.initInstance(instanceKey, internalStoreProps.initialState, initPayload, internalStoreProps.$$init);
|
|
239
253
|
storeController.instances[instanceKey] = { owners: [], resetState };
|
|
254
|
+
if (storeController.earlySubscribers[instanceKey]) {
|
|
255
|
+
for (const subscriber of storeController.earlySubscribers[instanceKey]) {
|
|
256
|
+
subscriber();
|
|
257
|
+
}
|
|
258
|
+
storeController.earlySubscribers[instanceKey].splice(0);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
// TODO Множественная инициализация хранилища
|
|
263
|
+
// Архитектура позволяет несколько раз инициализировать одно и то же хранилище с
|
|
264
|
+
// одним и тем же ключом, однако возможно от этого стоит отказаться. Возможно
|
|
265
|
+
// стоит просить разработчиков проверять инициализирована ли стора и
|
|
266
|
+
// инициализировать ее при необходимости.
|
|
267
|
+
console.warn(`Duplicate store initialization for key "${instanceKey.toString()}"`);
|
|
240
268
|
}
|
|
241
269
|
storeController.instances[instanceKey].owners.push(ownerKey);
|
|
242
270
|
return (resetPayload) => {
|
|
243
271
|
storeController.instances[instanceKey].owners.splice(storeController.instances[instanceKey].owners.indexOf(ownerKey), 1);
|
|
244
272
|
if (storeController.instances[instanceKey].owners.length === 0) {
|
|
245
273
|
// TODO Надо ли оповещать слушателей если один экземпляр хранилища удалился
|
|
246
|
-
storeController.instances[instanceKey].resetState(resetPayload, internalStoreProps
|
|
274
|
+
storeController.instances[instanceKey].resetState(resetPayload, internalStoreProps.$$reset);
|
|
247
275
|
delete storeController.instances[instanceKey];
|
|
248
276
|
}
|
|
249
277
|
delete initInstances[instanceKey];
|
|
@@ -264,7 +292,7 @@ function createUseStore(storeRegistry) {
|
|
|
264
292
|
}
|
|
265
293
|
},
|
|
266
294
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
267
|
-
actualInstanceKeys);
|
|
295
|
+
[actualInstanceKeys, /*registerInstance*/]);
|
|
268
296
|
React.useEffect(() => {
|
|
269
297
|
const initInstances = initInstancesRef.current.initInstances;
|
|
270
298
|
return () => {
|
|
@@ -279,23 +307,26 @@ function createUseStore(storeRegistry) {
|
|
|
279
307
|
|
|
280
308
|
function createStoreRegistry() {
|
|
281
309
|
const storeRegistry = {};
|
|
282
|
-
const
|
|
310
|
+
const useStore = createUseStore(storeRegistry);
|
|
283
311
|
const useProp = createUseProp(storeRegistry);
|
|
284
312
|
const usePropAll = createUsePropAll(storeRegistry);
|
|
285
|
-
const
|
|
313
|
+
const useDispatcher = createUseDispatcher(storeRegistry);
|
|
314
|
+
const useLatest = createUseLatest();
|
|
286
315
|
return {
|
|
287
|
-
|
|
316
|
+
storeRegistry,
|
|
317
|
+
useStore,
|
|
288
318
|
useProp,
|
|
289
319
|
usePropAll,
|
|
290
|
-
|
|
320
|
+
useDispatcher,
|
|
321
|
+
useLatest,
|
|
291
322
|
};
|
|
292
323
|
}
|
|
293
324
|
|
|
294
325
|
function createStore(name, initialState, reducers) {
|
|
295
326
|
const context = React.createContext(null);
|
|
296
327
|
const internalStoreProps = {
|
|
297
|
-
|
|
298
|
-
|
|
328
|
+
$$init: reducers.$$init,
|
|
329
|
+
$$reset: reducers.$$reset,
|
|
299
330
|
context,
|
|
300
331
|
initialState,
|
|
301
332
|
name,
|
|
@@ -324,6 +355,90 @@ function createStore(name, initialState, reducers) {
|
|
|
324
355
|
return store;
|
|
325
356
|
}
|
|
326
357
|
|
|
358
|
+
const requestStateDefault = {
|
|
359
|
+
isAborted: false,
|
|
360
|
+
isFulfilled: false,
|
|
361
|
+
isIdle: false,
|
|
362
|
+
isPending: false,
|
|
363
|
+
isRejected: false,
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const requestStatus = {
|
|
367
|
+
IDLE: 'IDLE',
|
|
368
|
+
PENDING: 'PENDING',
|
|
369
|
+
FULFILLED: 'FULFILLED',
|
|
370
|
+
REJECTED: 'REJECTED',
|
|
371
|
+
ABORTED: 'ABORTED',
|
|
372
|
+
FORCE_IDLE: 'IDLE',
|
|
373
|
+
FORCE_PENDING: 'PENDING',
|
|
374
|
+
FORCE_FULFILLED: 'FULFILLED',
|
|
375
|
+
FORCE_REJECTED: 'REJECTED',
|
|
376
|
+
FORCE_ABORTED: 'ABORTED',
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const requestState = {
|
|
380
|
+
idle: (meta) => {
|
|
381
|
+
return {
|
|
382
|
+
...requestStateDefault,
|
|
383
|
+
isIdle: true,
|
|
384
|
+
status: requestStatus.IDLE,
|
|
385
|
+
error: null,
|
|
386
|
+
meta: meta ?? null,
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
pending: (meta) => {
|
|
390
|
+
return {
|
|
391
|
+
...requestStateDefault,
|
|
392
|
+
isPending: true,
|
|
393
|
+
status: requestStatus.PENDING,
|
|
394
|
+
error: null,
|
|
395
|
+
meta: meta ?? null,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
fulfilled: (meta) => {
|
|
399
|
+
return {
|
|
400
|
+
...requestStateDefault,
|
|
401
|
+
isFulfilled: true,
|
|
402
|
+
status: requestStatus.FULFILLED,
|
|
403
|
+
meta: meta ?? null,
|
|
404
|
+
error: null,
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
rejected: (error, meta) => {
|
|
408
|
+
return {
|
|
409
|
+
...requestStateDefault,
|
|
410
|
+
isRejected: true,
|
|
411
|
+
status: requestStatus.REJECTED,
|
|
412
|
+
error: error ?? null,
|
|
413
|
+
meta: meta ?? null,
|
|
414
|
+
};
|
|
415
|
+
},
|
|
416
|
+
aborted: (meta) => {
|
|
417
|
+
return {
|
|
418
|
+
...requestStateDefault,
|
|
419
|
+
isAborted: true,
|
|
420
|
+
status: requestStatus.ABORTED,
|
|
421
|
+
meta: meta ?? null,
|
|
422
|
+
error: null,
|
|
423
|
+
};
|
|
424
|
+
},
|
|
425
|
+
forceIdle: (meta) => {
|
|
426
|
+
return requestState.idle(meta);
|
|
427
|
+
},
|
|
428
|
+
forcePending: (meta) => {
|
|
429
|
+
return requestState.pending(meta);
|
|
430
|
+
},
|
|
431
|
+
forceFulfilled: (meta) => {
|
|
432
|
+
return requestState.fulfilled(meta);
|
|
433
|
+
},
|
|
434
|
+
forceRejected: (error, meta) => {
|
|
435
|
+
return requestState.rejected(error, meta);
|
|
436
|
+
},
|
|
437
|
+
forceAborted: (meta) => {
|
|
438
|
+
return requestState.aborted(meta);
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
|
|
327
442
|
function StoreProvider(props) {
|
|
328
443
|
const Context = props.store[INTERNAL_STORE_PROPS_ACCESSOR].context;
|
|
329
444
|
return (jsxRuntime.jsx(Context.Provider, { value: props.instanceKey, children: props.children }));
|
|
@@ -336,6 +451,8 @@ exports.InternalStore = InternalStore;
|
|
|
336
451
|
exports.StoreProvider = StoreProvider;
|
|
337
452
|
exports.createStore = createStore;
|
|
338
453
|
exports.createStoreRegistry = createStoreRegistry;
|
|
454
|
+
exports.requestState = requestState;
|
|
455
|
+
exports.requestStatus = requestStatus;
|
|
339
456
|
exports.useDispatcher = useDispatcher;
|
|
340
457
|
exports.useProp = useProp;
|
|
341
458
|
exports.usePropAll = usePropAll;
|