state-decorator 7.0.0-beta.9-dev → 7.0.0-rc10
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 +71 -93
- package/development.d.ts +10 -0
- package/development.js +2 -0
- package/development.js.map +1 -0
- package/es/development.d.ts +10 -0
- package/es/development.js +2 -0
- package/es/development.js.map +1 -0
- package/es/graph.d.ts +8 -0
- package/es/helpers.d.ts +10 -9
- package/es/helpers.js +1 -162
- package/es/helpers.js.map +1 -1
- package/es/impl.d.ts +20 -32
- package/es/impl.js +1 -963
- package/es/impl.js.map +1 -1
- package/es/index.d.ts +19 -24
- package/es/index.js +1 -1013
- package/es/index.js.map +1 -1
- package/es/middlewares.d.ts +0 -23
- package/es/middlewares.js +1 -519
- package/es/middlewares.js.map +1 -1
- package/es/shallow.d.ts +0 -14
- package/es/test.d.ts +7 -21
- package/es/test.js +1 -349
- package/es/test.js.map +1 -1
- package/es/types.d.ts +73 -72
- package/es/v5.d.ts +5 -18
- package/es/v5.js +1 -301
- package/es/v5.js.map +1 -1
- package/es/v5_test.d.ts +4 -17
- package/es/v5_test.js +1 -392
- package/es/v5_test.js.map +1 -1
- package/es/v5_types.d.ts +15 -29
- package/es/v6.d.ts +7 -3
- package/es/v6.js +1 -96
- package/es/v6.js.map +1 -1
- package/graph.d.ts +8 -0
- package/helpers.d.ts +10 -9
- package/helpers.js +1 -174
- package/helpers.js.map +1 -1
- package/impl.d.ts +20 -32
- package/impl.js +1 -996
- package/impl.js.map +1 -1
- package/index.d.ts +19 -24
- package/index.js +1 -1044
- package/index.js.map +1 -1
- package/middlewares.d.ts +0 -23
- package/middlewares.js +1 -526
- package/middlewares.js.map +1 -1
- package/package.json +1 -1
- package/shallow.d.ts +0 -14
- package/test.d.ts +7 -21
- package/test.js +1 -358
- package/test.js.map +1 -1
- package/types.d.ts +73 -72
- package/v5.d.ts +5 -18
- package/v5.js +1 -322
- package/v5.js.map +1 -1
- package/v5_test.d.ts +4 -17
- package/v5_test.js +1 -416
- package/v5_test.js.map +1 -1
- package/v5_types.d.ts +15 -29
- package/v6.d.ts +7 -3
- package/v6.js +1 -120
- package/v6.js.map +1 -1
package/es/index.js
CHANGED
|
@@ -1,1014 +1,2 @@
|
|
|
1
|
-
import e, { useMemo, useContext, useReducer, useRef, useLayoutEffect, useEffect } from 'react';
|
|
2
|
-
import { createRef, isSimpleSyncAction, decorateSimpleSyncAction, isAsyncAction, decorateAsyncAction, computeAsyncActionInput, isSyncAction, decorateSyncAction, globalConfig, onPropChange, DEFAULT_PROMISE_ID, computeDerivedValues, buildOnMountInvocationContext, buildOnUnMountInvocationContext, isLoadingImpl, runMiddlewares, buildLoadingMap, buildErrorMap } from './impl';
|
|
3
|
-
export { EffectError, ParallelActionError, setGlobalConfig } from './impl';
|
|
4
|
-
|
|
5
|
-
/*! *****************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
|
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
|
|
20
|
-
var __assign = function() {
|
|
21
|
-
__assign = Object.assign || function __assign(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function __rest(s, e) {
|
|
32
|
-
var t = {};
|
|
33
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
34
|
-
t[p] = s[p];
|
|
35
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
36
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
37
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
38
|
-
t[p[i]] = s[p[i]];
|
|
39
|
-
}
|
|
40
|
-
return t;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function __spreadArray(to, from, pack) {
|
|
44
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
-
if (ar || !(i in from)) {
|
|
46
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
-
ar[i] = from[i];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function createCommonjsModule(fn) {
|
|
54
|
-
var module = { exports: {} };
|
|
55
|
-
return fn(module, module.exports), module.exports;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @license React
|
|
60
|
-
* use-sync-external-store-shim.production.min.js
|
|
61
|
-
*
|
|
62
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
63
|
-
*
|
|
64
|
-
* This source code is licensed under the MIT license found in the
|
|
65
|
-
* LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/
|
|
67
|
-
function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p$1=e.useDebugValue;function q$1(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r$1(c)&&g({inst:c});},[a,d,b]);m(function(){r$1(c)&&g({inst:c});return a(function(){r$1(c)&&g({inst:c});})},[a]);p$1(d);return d}
|
|
68
|
-
function r$1(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t$1(a,b){return b()}var u$1="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t$1:q$1;var useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u$1;
|
|
69
|
-
|
|
70
|
-
var useSyncExternalStoreShim_production_min = {
|
|
71
|
-
useSyncExternalStore: useSyncExternalStore
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @license React
|
|
76
|
-
* use-sync-external-store-shim.development.js
|
|
77
|
-
*
|
|
78
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
79
|
-
*
|
|
80
|
-
* This source code is licensed under the MIT license found in the
|
|
81
|
-
* LICENSE file in the root directory of this source tree.
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
var useSyncExternalStoreShim_development = createCommonjsModule(function (module, exports) {
|
|
85
|
-
|
|
86
|
-
if (process.env.NODE_ENV !== "production") {
|
|
87
|
-
(function() {
|
|
88
|
-
|
|
89
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
90
|
-
if (
|
|
91
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
92
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
93
|
-
'function'
|
|
94
|
-
) {
|
|
95
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
96
|
-
}
|
|
97
|
-
var React = e;
|
|
98
|
-
|
|
99
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
100
|
-
|
|
101
|
-
function error(format) {
|
|
102
|
-
{
|
|
103
|
-
{
|
|
104
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
105
|
-
args[_key2 - 1] = arguments[_key2];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
printWarning('error', format, args);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function printWarning(level, format, args) {
|
|
114
|
-
// When changing this logic, you might want to also
|
|
115
|
-
// update consoleWithStackDev.www.js as well.
|
|
116
|
-
{
|
|
117
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
118
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
119
|
-
|
|
120
|
-
if (stack !== '') {
|
|
121
|
-
format += '%s';
|
|
122
|
-
args = args.concat([stack]);
|
|
123
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var argsWithFormat = args.map(function (item) {
|
|
127
|
-
return String(item);
|
|
128
|
-
}); // Careful: RN currently depends on this prefix
|
|
129
|
-
|
|
130
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
131
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
132
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
|
133
|
-
|
|
134
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
140
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
141
|
-
*/
|
|
142
|
-
function is(x, y) {
|
|
143
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
144
|
-
;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
148
|
-
|
|
149
|
-
// dispatch for CommonJS interop named imports.
|
|
150
|
-
|
|
151
|
-
var useState = React.useState,
|
|
152
|
-
useEffect = React.useEffect,
|
|
153
|
-
useLayoutEffect = React.useLayoutEffect,
|
|
154
|
-
useDebugValue = React.useDebugValue;
|
|
155
|
-
var didWarnOld18Alpha = false;
|
|
156
|
-
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
157
|
-
// because of a very particular set of implementation details and assumptions
|
|
158
|
-
// -- change any one of them and it will break. The most important assumption
|
|
159
|
-
// is that updates are always synchronous, because concurrent rendering is
|
|
160
|
-
// only available in versions of React that also have a built-in
|
|
161
|
-
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
162
|
-
// does not exist.
|
|
163
|
-
//
|
|
164
|
-
// Do not assume that the clever hacks used by this hook also work in general.
|
|
165
|
-
// The point of this shim is to replace the need for hacks by other libraries.
|
|
166
|
-
|
|
167
|
-
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
168
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
169
|
-
// will need to track that themselves and return the correct value
|
|
170
|
-
// from `getSnapshot`.
|
|
171
|
-
getServerSnapshot) {
|
|
172
|
-
{
|
|
173
|
-
if (!didWarnOld18Alpha) {
|
|
174
|
-
if (React.startTransition !== undefined) {
|
|
175
|
-
didWarnOld18Alpha = true;
|
|
176
|
-
|
|
177
|
-
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
} // Read the current snapshot from the store on every render. Again, this
|
|
181
|
-
// breaks the rules of React, and only works here because of specific
|
|
182
|
-
// implementation details, most importantly that updates are
|
|
183
|
-
// always synchronous.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var value = getSnapshot();
|
|
187
|
-
|
|
188
|
-
{
|
|
189
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
190
|
-
var cachedValue = getSnapshot();
|
|
191
|
-
|
|
192
|
-
if (!objectIs(value, cachedValue)) {
|
|
193
|
-
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
194
|
-
|
|
195
|
-
didWarnUncachedGetSnapshot = true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} // Because updates are synchronous, we don't queue them. Instead we force a
|
|
199
|
-
// re-render whenever the subscribed state changes by updating an some
|
|
200
|
-
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
201
|
-
// the current value.
|
|
202
|
-
//
|
|
203
|
-
// Because we don't actually use the state returned by the useState hook, we
|
|
204
|
-
// can save a bit of memory by storing other stuff in that slot.
|
|
205
|
-
//
|
|
206
|
-
// To implement the early bailout, we need to track some things on a mutable
|
|
207
|
-
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
208
|
-
// our useState hook instead.
|
|
209
|
-
//
|
|
210
|
-
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
211
|
-
// new object always fails an equality check.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
var _useState = useState({
|
|
215
|
-
inst: {
|
|
216
|
-
value: value,
|
|
217
|
-
getSnapshot: getSnapshot
|
|
218
|
-
}
|
|
219
|
-
}),
|
|
220
|
-
inst = _useState[0].inst,
|
|
221
|
-
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
222
|
-
// in the layout phase so we can access it during the tearing check that
|
|
223
|
-
// happens on subscribe.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
useLayoutEffect(function () {
|
|
227
|
-
inst.value = value;
|
|
228
|
-
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
229
|
-
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
230
|
-
// this can happen all the time, but even in synchronous mode, an earlier
|
|
231
|
-
// effect may have mutated the store.
|
|
232
|
-
|
|
233
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
234
|
-
// Force a re-render.
|
|
235
|
-
forceUpdate({
|
|
236
|
-
inst: inst
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}, [subscribe, value, getSnapshot]);
|
|
240
|
-
useEffect(function () {
|
|
241
|
-
// Check for changes right before subscribing. Subsequent changes will be
|
|
242
|
-
// detected in the subscription handler.
|
|
243
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
244
|
-
// Force a re-render.
|
|
245
|
-
forceUpdate({
|
|
246
|
-
inst: inst
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
var handleStoreChange = function () {
|
|
251
|
-
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
252
|
-
// up to the consumer of this library to wrap their subscription event
|
|
253
|
-
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
254
|
-
// the case and print a warning in development?
|
|
255
|
-
// The store changed. Check if the snapshot changed since the last time we
|
|
256
|
-
// read from the store.
|
|
257
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
258
|
-
// Force a re-render.
|
|
259
|
-
forceUpdate({
|
|
260
|
-
inst: inst
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}; // Subscribe to the store and return a clean-up function.
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return subscribe(handleStoreChange);
|
|
267
|
-
}, [subscribe]);
|
|
268
|
-
useDebugValue(value);
|
|
269
|
-
return value;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function checkIfSnapshotChanged(inst) {
|
|
273
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
274
|
-
var prevValue = inst.value;
|
|
275
|
-
|
|
276
|
-
try {
|
|
277
|
-
var nextValue = latestGetSnapshot();
|
|
278
|
-
return !objectIs(prevValue, nextValue);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
285
|
-
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
286
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
287
|
-
// will need to track that themselves and return the correct value
|
|
288
|
-
// from `getSnapshot`.
|
|
289
|
-
return getSnapshot();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
293
|
-
|
|
294
|
-
var isServerEnvironment = !canUseDOM;
|
|
295
|
-
|
|
296
|
-
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
297
|
-
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
298
|
-
|
|
299
|
-
exports.useSyncExternalStore = useSyncExternalStore$2;
|
|
300
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
301
|
-
if (
|
|
302
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
303
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
304
|
-
'function'
|
|
305
|
-
) {
|
|
306
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
})();
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
var shim = createCommonjsModule(function (module) {
|
|
314
|
-
|
|
315
|
-
if (process.env.NODE_ENV === 'production') {
|
|
316
|
-
module.exports = useSyncExternalStoreShim_production_min;
|
|
317
|
-
} else {
|
|
318
|
-
module.exports = useSyncExternalStoreShim_development;
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* @license React
|
|
324
|
-
* use-sync-external-store-shim/with-selector.production.min.js
|
|
325
|
-
*
|
|
326
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
327
|
-
*
|
|
328
|
-
* This source code is licensed under the MIT license found in the
|
|
329
|
-
* LICENSE file in the root directory of this source tree.
|
|
330
|
-
*/
|
|
331
|
-
function p(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var q="function"===typeof Object.is?Object.is:p,r=shim.useSyncExternalStore,t=e.useRef,u=e.useEffect,v=e.useMemo,w=e.useDebugValue;
|
|
332
|
-
var useSyncExternalStoreWithSelector$1=function(a,b,e,l,g){var c=t(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f;}else f=c.current;c=v(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==g&&f.hasValue){var b=f.value;if(g(b,a))return k=b}return k=a}b=k;if(q(d,a))return b;var e=l(a);if(void 0!==g&&g(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return [function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,g]);var d=r(a,c[0],c[1]);
|
|
333
|
-
u(function(){f.hasValue=!0;f.value=d;},[d]);w(d);return d};
|
|
334
|
-
|
|
335
|
-
var withSelector_production_min = {
|
|
336
|
-
useSyncExternalStoreWithSelector: useSyncExternalStoreWithSelector$1
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* @license React
|
|
341
|
-
* use-sync-external-store-shim/with-selector.development.js
|
|
342
|
-
*
|
|
343
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
344
|
-
*
|
|
345
|
-
* This source code is licensed under the MIT license found in the
|
|
346
|
-
* LICENSE file in the root directory of this source tree.
|
|
347
|
-
*/
|
|
348
|
-
|
|
349
|
-
var withSelector_development = createCommonjsModule(function (module, exports) {
|
|
350
|
-
|
|
351
|
-
if (process.env.NODE_ENV !== "production") {
|
|
352
|
-
(function() {
|
|
353
|
-
|
|
354
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
355
|
-
if (
|
|
356
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
357
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
358
|
-
'function'
|
|
359
|
-
) {
|
|
360
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
361
|
-
}
|
|
362
|
-
var React = e;
|
|
363
|
-
var shim$1 = shim;
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
367
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
368
|
-
*/
|
|
369
|
-
function is(x, y) {
|
|
370
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
371
|
-
;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
375
|
-
|
|
376
|
-
var useSyncExternalStore = shim$1.useSyncExternalStore;
|
|
377
|
-
|
|
378
|
-
// for CommonJS interop.
|
|
379
|
-
|
|
380
|
-
var useRef = React.useRef,
|
|
381
|
-
useEffect = React.useEffect,
|
|
382
|
-
useMemo = React.useMemo,
|
|
383
|
-
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
|
|
384
|
-
|
|
385
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
386
|
-
// Use this to track the rendered snapshot.
|
|
387
|
-
var instRef = useRef(null);
|
|
388
|
-
var inst;
|
|
389
|
-
|
|
390
|
-
if (instRef.current === null) {
|
|
391
|
-
inst = {
|
|
392
|
-
hasValue: false,
|
|
393
|
-
value: null
|
|
394
|
-
};
|
|
395
|
-
instRef.current = inst;
|
|
396
|
-
} else {
|
|
397
|
-
inst = instRef.current;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
var _useMemo = useMemo(function () {
|
|
401
|
-
// Track the memoized state using closure variables that are local to this
|
|
402
|
-
// memoized instance of a getSnapshot function. Intentionally not using a
|
|
403
|
-
// useRef hook, because that state would be shared across all concurrent
|
|
404
|
-
// copies of the hook/component.
|
|
405
|
-
var hasMemo = false;
|
|
406
|
-
var memoizedSnapshot;
|
|
407
|
-
var memoizedSelection;
|
|
408
|
-
|
|
409
|
-
var memoizedSelector = function (nextSnapshot) {
|
|
410
|
-
if (!hasMemo) {
|
|
411
|
-
// The first time the hook is called, there is no memoized result.
|
|
412
|
-
hasMemo = true;
|
|
413
|
-
memoizedSnapshot = nextSnapshot;
|
|
414
|
-
|
|
415
|
-
var _nextSelection = selector(nextSnapshot);
|
|
416
|
-
|
|
417
|
-
if (isEqual !== undefined) {
|
|
418
|
-
// Even if the selector has changed, the currently rendered selection
|
|
419
|
-
// may be equal to the new selection. We should attempt to reuse the
|
|
420
|
-
// current value if possible, to preserve downstream memoizations.
|
|
421
|
-
if (inst.hasValue) {
|
|
422
|
-
var currentSelection = inst.value;
|
|
423
|
-
|
|
424
|
-
if (isEqual(currentSelection, _nextSelection)) {
|
|
425
|
-
memoizedSelection = currentSelection;
|
|
426
|
-
return currentSelection;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
memoizedSelection = _nextSelection;
|
|
432
|
-
return _nextSelection;
|
|
433
|
-
} // We may be able to reuse the previous invocation's result.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// We may be able to reuse the previous invocation's result.
|
|
437
|
-
var prevSnapshot = memoizedSnapshot;
|
|
438
|
-
var prevSelection = memoizedSelection;
|
|
439
|
-
|
|
440
|
-
if (objectIs(prevSnapshot, nextSnapshot)) {
|
|
441
|
-
// The snapshot is the same as last time. Reuse the previous selection.
|
|
442
|
-
return prevSelection;
|
|
443
|
-
} // The snapshot has changed, so we need to compute a new selection.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
// The snapshot has changed, so we need to compute a new selection.
|
|
447
|
-
var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
|
|
448
|
-
// has changed. If it hasn't, return the previous selection. That signals
|
|
449
|
-
// to React that the selections are conceptually equal, and we can bail
|
|
450
|
-
// out of rendering.
|
|
451
|
-
|
|
452
|
-
// If a custom isEqual function is provided, use that to check if the data
|
|
453
|
-
// has changed. If it hasn't, return the previous selection. That signals
|
|
454
|
-
// to React that the selections are conceptually equal, and we can bail
|
|
455
|
-
// out of rendering.
|
|
456
|
-
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
|
|
457
|
-
return prevSelection;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
memoizedSnapshot = nextSnapshot;
|
|
461
|
-
memoizedSelection = nextSelection;
|
|
462
|
-
return nextSelection;
|
|
463
|
-
}; // Assigning this to a constant so that Flow knows it can't change.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
// Assigning this to a constant so that Flow knows it can't change.
|
|
467
|
-
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
468
|
-
|
|
469
|
-
var getSnapshotWithSelector = function () {
|
|
470
|
-
return memoizedSelector(getSnapshot());
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
|
|
474
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
475
|
-
};
|
|
476
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
477
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual]),
|
|
478
|
-
getSelection = _useMemo[0],
|
|
479
|
-
getServerSelection = _useMemo[1];
|
|
480
|
-
|
|
481
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
482
|
-
useEffect(function () {
|
|
483
|
-
inst.hasValue = true;
|
|
484
|
-
inst.value = value;
|
|
485
|
-
}, [value]);
|
|
486
|
-
useDebugValue(value);
|
|
487
|
-
return value;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
491
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
492
|
-
if (
|
|
493
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
494
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
495
|
-
'function'
|
|
496
|
-
) {
|
|
497
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
})();
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
var withSelector = createCommonjsModule(function (module) {
|
|
505
|
-
|
|
506
|
-
if (process.env.NODE_ENV === 'production') {
|
|
507
|
-
module.exports = withSelector_production_min;
|
|
508
|
-
} else {
|
|
509
|
-
module.exports = withSelector_development;
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
/*! *****************************************************************************
|
|
514
|
-
Copyright (c) GlobalSport SAS.
|
|
515
|
-
|
|
516
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
517
|
-
purpose with or without fee is hereby granted.
|
|
518
|
-
|
|
519
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
520
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
521
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
522
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
523
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
524
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
525
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
526
|
-
***************************************************************************** */
|
|
527
|
-
/**
|
|
528
|
-
* The State decorator can manage only one asynchronous action of same name at a time.
|
|
529
|
-
* This enum is enumertaing all the policies in such case.
|
|
530
|
-
*/
|
|
531
|
-
var ConflictPolicy;
|
|
532
|
-
(function (ConflictPolicy) {
|
|
533
|
-
/**
|
|
534
|
-
* Reject the promise.
|
|
535
|
-
*/
|
|
536
|
-
ConflictPolicy["REJECT"] = "reject";
|
|
537
|
-
/**
|
|
538
|
-
* Return a resolved promise with no result.
|
|
539
|
-
*/
|
|
540
|
-
ConflictPolicy["IGNORE"] = "ignore";
|
|
541
|
-
/**
|
|
542
|
-
* Execute only the last call that conflicts after the one ongoing.
|
|
543
|
-
*/
|
|
544
|
-
ConflictPolicy["KEEP_LAST"] = "keepLast";
|
|
545
|
-
/**
|
|
546
|
-
* Execute all calls one after another.
|
|
547
|
-
*/
|
|
548
|
-
ConflictPolicy["KEEP_ALL"] = "keepAll";
|
|
549
|
-
/**
|
|
550
|
-
* Execute all calls one after another.
|
|
551
|
-
* @see getPromiseId
|
|
552
|
-
*/
|
|
553
|
-
ConflictPolicy["PARALLEL"] = "parallel";
|
|
554
|
-
/**
|
|
555
|
-
* Reuse the ongoing promise if any and if possible (same arguments). Only for GET requests!
|
|
556
|
-
*/
|
|
557
|
-
ConflictPolicy["REUSE"] = "reuse";
|
|
558
|
-
})(ConflictPolicy || (ConflictPolicy = {}));
|
|
559
|
-
|
|
560
|
-
var useSyncExternalStoreWithSelector = withSelector.useSyncExternalStoreWithSelector;
|
|
561
|
-
// =============================
|
|
562
|
-
//
|
|
563
|
-
// STORE
|
|
564
|
-
//
|
|
565
|
-
// =============================
|
|
566
|
-
/**
|
|
567
|
-
* Create a new store.
|
|
568
|
-
* @param config Store configuration
|
|
569
|
-
* @returns a store.
|
|
570
|
-
*/
|
|
571
|
-
function createStore(config) {
|
|
572
|
-
var stateRef = createRef();
|
|
573
|
-
var derivedStateRef = createRef();
|
|
574
|
-
var propsRef = createRef();
|
|
575
|
-
var actionsRef = createRef();
|
|
576
|
-
var timeoutRef = createRef();
|
|
577
|
-
var loadingParallelMapRef = createRef();
|
|
578
|
-
var loadingMapRef = createRef();
|
|
579
|
-
var loadingRef = createRef();
|
|
580
|
-
var errorMapRef = createRef();
|
|
581
|
-
var promisesRef = createRef();
|
|
582
|
-
var conflictActionsRef = createRef();
|
|
583
|
-
var initializedRef = createRef(false);
|
|
584
|
-
var snapshotRef = createRef();
|
|
585
|
-
var middlewaresRef = createRef([]);
|
|
586
|
-
var getInitialState = config.getInitialState, actionsImpl = config.actions, _a = config.middlewares, middlewares = _a === void 0 ? [] : _a, options = __rest(config, ["getInitialState", "actions", "middlewares"]);
|
|
587
|
-
var stateListeners = {};
|
|
588
|
-
var stateListenerCount = 0;
|
|
589
|
-
function addStateListener(listener) {
|
|
590
|
-
var id = "".concat(stateListenerCount++);
|
|
591
|
-
stateListeners[id] = listener;
|
|
592
|
-
return function () {
|
|
593
|
-
delete stateListeners[id];
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
function notifyStateListeners() {
|
|
597
|
-
updateSnapshot();
|
|
598
|
-
Object.keys(stateListeners).forEach(function (listenerId) {
|
|
599
|
-
stateListeners[listenerId]();
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
function setProps(p) {
|
|
603
|
-
var oldProps = propsRef.current;
|
|
604
|
-
propsRef.current = p;
|
|
605
|
-
if (!initializedRef.current) {
|
|
606
|
-
init(p);
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
onPropChange(stateRef, derivedStateRef, propsRef, oldProps, actionsRef, options, getInitialState, setState, false, false);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
/** Middleware only: sets the internal state, recompute derived state and notify listeners */
|
|
613
|
-
function setInternalState(s) {
|
|
614
|
-
stateRef.current = s;
|
|
615
|
-
computeDerivedValues(stateRef, propsRef, derivedStateRef, options);
|
|
616
|
-
notifyStateListeners();
|
|
617
|
-
}
|
|
618
|
-
function setInternalLoadingMap(map) {
|
|
619
|
-
loadingParallelMapRef.current = map;
|
|
620
|
-
loadingMapRef.current = getLoadingMap();
|
|
621
|
-
loadingRef.current = isAnyLoading();
|
|
622
|
-
}
|
|
623
|
-
function init(p) {
|
|
624
|
-
var _a;
|
|
625
|
-
if (!initializedRef.current) {
|
|
626
|
-
propsRef.current = p;
|
|
627
|
-
initializedRef.current = true;
|
|
628
|
-
stateRef.current = typeof getInitialState === 'function' ? getInitialState(p) : getInitialState;
|
|
629
|
-
var initialActionSet_1 = new Set(options === null || options === void 0 ? void 0 : options.initialActionsMarkedLoading);
|
|
630
|
-
var loadingMap = Object.keys(actionsImpl).reduce(function (acc, name) {
|
|
631
|
-
var _a;
|
|
632
|
-
acc[name] = initialActionSet_1.has(name) ? (_a = {}, _a[DEFAULT_PROMISE_ID] = true, _a) : {};
|
|
633
|
-
return acc;
|
|
634
|
-
}, {});
|
|
635
|
-
setInternalLoadingMap(loadingMap);
|
|
636
|
-
errorMapRef.current = Object.keys(actionsImpl).reduce(function (acc, name) {
|
|
637
|
-
acc[name] = {};
|
|
638
|
-
return acc;
|
|
639
|
-
}, {});
|
|
640
|
-
timeoutRef.current = {};
|
|
641
|
-
promisesRef.current = {};
|
|
642
|
-
conflictActionsRef.current = {};
|
|
643
|
-
derivedStateRef.current = {
|
|
644
|
-
state: null,
|
|
645
|
-
deps: {},
|
|
646
|
-
};
|
|
647
|
-
// init middlewares
|
|
648
|
-
middlewaresRef.current = [];
|
|
649
|
-
var ctx_1 = {
|
|
650
|
-
options: options,
|
|
651
|
-
get state() {
|
|
652
|
-
return stateRef.current;
|
|
653
|
-
},
|
|
654
|
-
actions: actionsImpl,
|
|
655
|
-
setState: setInternalState,
|
|
656
|
-
};
|
|
657
|
-
var mapper = function (m) {
|
|
658
|
-
var _a;
|
|
659
|
-
var middleware = m();
|
|
660
|
-
middlewaresRef.current.push(middleware);
|
|
661
|
-
(_a = middleware.init) === null || _a === void 0 ? void 0 : _a.call(middleware, ctx_1);
|
|
662
|
-
};
|
|
663
|
-
(_a = globalConfig.defaultMiddlewares) === null || _a === void 0 ? void 0 : _a.forEach(mapper);
|
|
664
|
-
middlewares === null || middlewares === void 0 ? void 0 : middlewares.forEach(mapper);
|
|
665
|
-
// end init
|
|
666
|
-
computeDerivedValues(stateRef, propsRef, derivedStateRef, options);
|
|
667
|
-
// manage PropsChange with onMount
|
|
668
|
-
onPropChange(stateRef, derivedStateRef, propsRef, null, actionsRef, options, getInitialState, setState, true, false);
|
|
669
|
-
if (options === null || options === void 0 ? void 0 : options.onMount) {
|
|
670
|
-
options.onMount(buildOnMountInvocationContext(stateRef, derivedStateRef, propsRef, actionsRef));
|
|
671
|
-
}
|
|
672
|
-
notifyStateListeners();
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
function clearError(actionName, promiseId) {
|
|
676
|
-
if (promiseId === void 0) { promiseId = DEFAULT_PROMISE_ID; }
|
|
677
|
-
var map = errorMapRef.current[actionName];
|
|
678
|
-
if (map === null || map === void 0 ? void 0 : map[promiseId]) {
|
|
679
|
-
delete map[promiseId];
|
|
680
|
-
}
|
|
681
|
-
notifyStateListeners();
|
|
682
|
-
}
|
|
683
|
-
function invokeOnMountDeferred() {
|
|
684
|
-
// manage PropsChange with onMount
|
|
685
|
-
onPropChange(stateRef, derivedStateRef, propsRef, null, actionsRef, options, getInitialState, setState, true, true);
|
|
686
|
-
if (options === null || options === void 0 ? void 0 : options.onMountDeferred) {
|
|
687
|
-
options.onMountDeferred(buildOnMountInvocationContext(stateRef, derivedStateRef, propsRef, actionsRef));
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
function abortActionsOnDestroy() {
|
|
691
|
-
var abortedActions = Object.keys(actionsImpl).reduce(function (acc, actionName) {
|
|
692
|
-
var action = actionsImpl[actionName];
|
|
693
|
-
if (isAsyncAction(action) && action.abortable) {
|
|
694
|
-
var map_1 = loadingParallelMapRef.current[actionName];
|
|
695
|
-
var aborted = Object.keys(map_1).reduce(function (acc, promiseId) {
|
|
696
|
-
if (map_1[promiseId]) {
|
|
697
|
-
// ongoing action
|
|
698
|
-
abortAction(actionName, promiseId);
|
|
699
|
-
acc.push(promiseId);
|
|
700
|
-
}
|
|
701
|
-
return acc;
|
|
702
|
-
}, []);
|
|
703
|
-
if (aborted.length > 0) {
|
|
704
|
-
acc[actionName] = aborted;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
return acc;
|
|
708
|
-
}, {});
|
|
709
|
-
return abortedActions;
|
|
710
|
-
}
|
|
711
|
-
function destroy() {
|
|
712
|
-
var _a;
|
|
713
|
-
if (initializedRef.current) {
|
|
714
|
-
var abortedActions = abortActionsOnDestroy();
|
|
715
|
-
(_a = options === null || options === void 0 ? void 0 : options.onUnmount) === null || _a === void 0 ? void 0 : _a.call(options, buildOnUnMountInvocationContext(stateRef, derivedStateRef, propsRef, abortedActions));
|
|
716
|
-
propsRef.current = null;
|
|
717
|
-
stateRef.current = null;
|
|
718
|
-
loadingParallelMapRef.current = null;
|
|
719
|
-
loadingMapRef.current = null;
|
|
720
|
-
loadingRef.current = null;
|
|
721
|
-
errorMapRef.current = null;
|
|
722
|
-
promisesRef.current = null;
|
|
723
|
-
conflictActionsRef.current = null;
|
|
724
|
-
derivedStateRef.current = null;
|
|
725
|
-
snapshotRef.current = null;
|
|
726
|
-
Object.keys(timeoutRef.current).forEach(function (name) {
|
|
727
|
-
clearTimeout(timeoutRef.current[name]);
|
|
728
|
-
});
|
|
729
|
-
timeoutRef.current = null;
|
|
730
|
-
stateListeners = {};
|
|
731
|
-
initializedRef.current = false;
|
|
732
|
-
middlewaresRef.current.forEach(function (m) {
|
|
733
|
-
var _a;
|
|
734
|
-
(_a = m.destroy) === null || _a === void 0 ? void 0 : _a.call(m);
|
|
735
|
-
});
|
|
736
|
-
middlewaresRef.current = [];
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
function setState(newStateIn, newLoadingMapIn, actionName, actionType, isAsync, actionCtx, propsChanged, init) {
|
|
740
|
-
if (propsChanged === void 0) { propsChanged = false; }
|
|
741
|
-
if (init === void 0) { init = false; }
|
|
742
|
-
var hasChanged = false;
|
|
743
|
-
if (!initializedRef.current) {
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
var newLoadingMap = newLoadingMapIn;
|
|
747
|
-
var oldLoading = isAsync
|
|
748
|
-
? isLoadingImpl(newLoadingMap || loadingParallelMapRef.current, [actionName, actionCtx === null || actionCtx === void 0 ? void 0 : actionCtx.promiseId])
|
|
749
|
-
: false;
|
|
750
|
-
var _a = runMiddlewares(middlewaresRef.current, stateRef.current, newStateIn, oldLoading, actionName, actionType, isAsync, actionCtx), newState = _a.newState, newLoading = _a.newLoading;
|
|
751
|
-
if (newState != null) {
|
|
752
|
-
hasChanged = true;
|
|
753
|
-
stateRef.current = newState;
|
|
754
|
-
}
|
|
755
|
-
if (oldLoading !== newLoading) {
|
|
756
|
-
newLoadingMap = buildLoadingMap(newLoadingMap, actionName, (actionCtx === null || actionCtx === void 0 ? void 0 : actionCtx.promiseId) || DEFAULT_PROMISE_ID, newLoading);
|
|
757
|
-
if (Object.keys(newLoadingMap).length === 0) {
|
|
758
|
-
newLoadingMap = undefined;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
if (newLoadingMap != null) {
|
|
762
|
-
hasChanged = true;
|
|
763
|
-
setInternalLoadingMap(newLoadingMap);
|
|
764
|
-
}
|
|
765
|
-
if (hasChanged) {
|
|
766
|
-
computeDerivedValues(stateRef, propsRef, derivedStateRef, options);
|
|
767
|
-
if (!init) {
|
|
768
|
-
stateRef.current = newState || stateRef.current;
|
|
769
|
-
notifyStateListeners();
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
else if (propsChanged) {
|
|
773
|
-
var derivedChanged = computeDerivedValues(stateRef, propsRef, derivedStateRef, options);
|
|
774
|
-
if (derivedChanged && !init) {
|
|
775
|
-
notifyStateListeners();
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
var keys = Object.keys(actionsImpl);
|
|
780
|
-
actionsRef.current = keys.reduce(function (acc, actionName) {
|
|
781
|
-
var action = actionsImpl[actionName];
|
|
782
|
-
if (isSimpleSyncAction(action)) {
|
|
783
|
-
acc[actionName] = decorateSimpleSyncAction(actionName, action, stateRef, derivedStateRef, propsRef, initializedRef, setState);
|
|
784
|
-
}
|
|
785
|
-
else if (isAsyncAction(action)) {
|
|
786
|
-
acc[actionName] = decorateAsyncAction({
|
|
787
|
-
actionName: actionName,
|
|
788
|
-
stateRef: stateRef,
|
|
789
|
-
derivedStateRef: derivedStateRef,
|
|
790
|
-
propsRef: propsRef,
|
|
791
|
-
loadingParallelMapRef: loadingParallelMapRef,
|
|
792
|
-
errorMapRef: errorMapRef,
|
|
793
|
-
actionsRef: actionsRef,
|
|
794
|
-
promisesRef: promisesRef,
|
|
795
|
-
conflictActionsRef: conflictActionsRef,
|
|
796
|
-
initializedRef: initializedRef,
|
|
797
|
-
options: options,
|
|
798
|
-
setState: setState,
|
|
799
|
-
clearError: clearError,
|
|
800
|
-
action: computeAsyncActionInput(action),
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
else if (isSyncAction(action)) {
|
|
804
|
-
acc[actionName] = decorateSyncAction(actionName, action, stateRef, derivedStateRef, propsRef, actionsRef, initializedRef, timeoutRef, options, setState, clearError);
|
|
805
|
-
}
|
|
806
|
-
return acc;
|
|
807
|
-
}, {});
|
|
808
|
-
function isLoading() {
|
|
809
|
-
var props = [];
|
|
810
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
811
|
-
props[_i] = arguments[_i];
|
|
812
|
-
}
|
|
813
|
-
return isLoadingImpl.apply(void 0, __spreadArray([loadingParallelMapRef.current], props, false));
|
|
814
|
-
}
|
|
815
|
-
function abortAction(actionName, promiseId) {
|
|
816
|
-
var _a, _b;
|
|
817
|
-
if (promiseId === void 0) { promiseId = DEFAULT_PROMISE_ID; }
|
|
818
|
-
var abortController = (_b = (_a = promisesRef.current[actionName]) === null || _a === void 0 ? void 0 : _a[promiseId]) === null || _b === void 0 ? void 0 : _b.abortController;
|
|
819
|
-
var res = false;
|
|
820
|
-
if (abortController) {
|
|
821
|
-
abortController.abort();
|
|
822
|
-
res = true;
|
|
823
|
-
}
|
|
824
|
-
return res;
|
|
825
|
-
}
|
|
826
|
-
function isAnyLoading() {
|
|
827
|
-
if (initializedRef.current) {
|
|
828
|
-
var loadingMap_1 = loadingParallelMapRef.current;
|
|
829
|
-
return (Object.keys(loadingMap_1).find(function (actionName) {
|
|
830
|
-
var promises = loadingMap_1[actionName];
|
|
831
|
-
return Object.keys(promises).find(function (pId) { return !!promises[pId]; });
|
|
832
|
-
}) != null);
|
|
833
|
-
}
|
|
834
|
-
return null;
|
|
835
|
-
}
|
|
836
|
-
function getLoadingMap() {
|
|
837
|
-
if (initializedRef.current) {
|
|
838
|
-
var map_2 = loadingParallelMapRef.current;
|
|
839
|
-
var keys_1 = Object.keys(map_2);
|
|
840
|
-
return keys_1.reduce(function (acc, actionName) {
|
|
841
|
-
var subMap = map_2[actionName];
|
|
842
|
-
acc[actionName] = Object.keys(subMap).find(function (pId) { return !!subMap[pId]; }) != null;
|
|
843
|
-
return acc;
|
|
844
|
-
}, {});
|
|
845
|
-
}
|
|
846
|
-
return null;
|
|
847
|
-
}
|
|
848
|
-
function getErrorMap() {
|
|
849
|
-
if (initializedRef.current) {
|
|
850
|
-
return buildErrorMap(errorMapRef.current);
|
|
851
|
-
}
|
|
852
|
-
return null;
|
|
853
|
-
}
|
|
854
|
-
function getConfig() {
|
|
855
|
-
return __assign({}, config);
|
|
856
|
-
}
|
|
857
|
-
function updateSnapshot() {
|
|
858
|
-
snapshotRef.current = __assign(__assign(__assign(__assign({}, actionsRef.current), stateRef.current), derivedStateRef.current.state), { isLoading: isLoading, abortAction: abortAction, loading: loadingRef.current, loadingMap: loadingMapRef.current, loadingParallelMap: loadingParallelMapRef.current, errorMap: getErrorMap(), errorParallelMap: errorMapRef.current });
|
|
859
|
-
}
|
|
860
|
-
function getSnapshot() {
|
|
861
|
-
return snapshotRef.current;
|
|
862
|
-
}
|
|
863
|
-
return {
|
|
864
|
-
getConfig: getConfig,
|
|
865
|
-
setProps: setProps,
|
|
866
|
-
addStateListener: addStateListener,
|
|
867
|
-
init: init,
|
|
868
|
-
destroy: destroy,
|
|
869
|
-
isLoading: isLoading,
|
|
870
|
-
abortAction: abortAction,
|
|
871
|
-
clearError: clearError,
|
|
872
|
-
getSnapshot: getSnapshot,
|
|
873
|
-
invokeOnMountDeferred: invokeOnMountDeferred,
|
|
874
|
-
get actions() {
|
|
875
|
-
return actionsRef.current;
|
|
876
|
-
},
|
|
877
|
-
get state() {
|
|
878
|
-
if (initializedRef.current) {
|
|
879
|
-
return __assign(__assign({}, stateRef.current), derivedStateRef.current.state);
|
|
880
|
-
}
|
|
881
|
-
return null;
|
|
882
|
-
},
|
|
883
|
-
get loading() {
|
|
884
|
-
return loadingRef.current;
|
|
885
|
-
},
|
|
886
|
-
get loadingMap() {
|
|
887
|
-
return loadingMapRef.current;
|
|
888
|
-
},
|
|
889
|
-
get errorMap() {
|
|
890
|
-
return getErrorMap();
|
|
891
|
-
},
|
|
892
|
-
get loadingParallelMap() {
|
|
893
|
-
if (initializedRef.current) {
|
|
894
|
-
return loadingParallelMapRef.current;
|
|
895
|
-
}
|
|
896
|
-
return null;
|
|
897
|
-
},
|
|
898
|
-
get errorParallelMap() {
|
|
899
|
-
if (initializedRef.current) {
|
|
900
|
-
return errorMapRef.current;
|
|
901
|
-
}
|
|
902
|
-
return null;
|
|
903
|
-
},
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
function useStoreSlice(store, funcOrArr) {
|
|
907
|
-
var slicerFunc = useMemo(function () { return (funcOrArr instanceof Function ? funcOrArr : function (ctx) { return pick(ctx, funcOrArr); }); }, [funcOrArr]);
|
|
908
|
-
return useSyncExternalStoreWithSelector(store.addStateListener, store.getSnapshot, store.getSnapshot, slicerFunc, globalConfig.comparator);
|
|
909
|
-
}
|
|
910
|
-
function useStoreContextSlice(storeContext, funcOrArr) {
|
|
911
|
-
var store = useContext(storeContext);
|
|
912
|
-
return useStoreSlice(store, funcOrArr);
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* Binds the store to this component.
|
|
916
|
-
* Store will NOT be destroyed when component is unmouted.
|
|
917
|
-
* Props passed to actions will come from this components.
|
|
918
|
-
* If store is configured to react of props changes, it will used passed props.
|
|
919
|
-
* The component will be refreshed for every change in the store.
|
|
920
|
-
*
|
|
921
|
-
* @param store The store to listen to.
|
|
922
|
-
* @param props The parent component props
|
|
923
|
-
* @param refreshOnUpdate Whether refresh the component if store state changes.
|
|
924
|
-
* @returns The store.
|
|
925
|
-
*/
|
|
926
|
-
function useStore(store, props, refreshOnUpdate) {
|
|
927
|
-
if (props === void 0) { props = null; }
|
|
928
|
-
if (refreshOnUpdate === void 0) { refreshOnUpdate = true; }
|
|
929
|
-
var _a = useReducer(function (s) { return (s > 100 ? 0 : s + 1); }, 0), forceRefresh = _a[1];
|
|
930
|
-
var storeRef = useRef(store);
|
|
931
|
-
store.setProps(props);
|
|
932
|
-
useLayoutEffect(function () {
|
|
933
|
-
// In development mode, React is calling in order:
|
|
934
|
-
// - render
|
|
935
|
-
// - useLayoutEffect
|
|
936
|
-
// - useEffect
|
|
937
|
-
// - useLayoutEffect => delete callback
|
|
938
|
-
// - useEffect => delete callback
|
|
939
|
-
// - useLayoutEffect
|
|
940
|
-
// - useEffect
|
|
941
|
-
//
|
|
942
|
-
// Here we enforce a initialization of the store after a destroy in the useEffect delete callback
|
|
943
|
-
store.init(props);
|
|
944
|
-
}, []);
|
|
945
|
-
useLayoutEffect(function () {
|
|
946
|
-
if (refreshOnUpdate) {
|
|
947
|
-
return storeRef.current.addStateListener(function () {
|
|
948
|
-
forceRefresh();
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
return undefined;
|
|
952
|
-
}, [refreshOnUpdate]);
|
|
953
|
-
return store;
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Creates and manages a local store.
|
|
957
|
-
* The component will be refreshed for every change in the store.
|
|
958
|
-
* Store will NOT be destroyed when component is unmouted.
|
|
959
|
-
*
|
|
960
|
-
* @param getInitialState Function to compute initial state from props.
|
|
961
|
-
* @param actionImpl Actions implementation.
|
|
962
|
-
* @param props Owner component props to update state or react on prop changes
|
|
963
|
-
* @param options The store options.
|
|
964
|
-
* @param refreshOnUpdate Whether refresh the component if store state changes.
|
|
965
|
-
* @returns The state, actions and isLoading function.
|
|
966
|
-
*/
|
|
967
|
-
function useLocalStore(config, props, refreshOnUpdate) {
|
|
968
|
-
if (refreshOnUpdate === void 0) { refreshOnUpdate = true; }
|
|
969
|
-
var storeRef = useRef();
|
|
970
|
-
if (storeRef.current == null) {
|
|
971
|
-
storeRef.current = createStore(config);
|
|
972
|
-
}
|
|
973
|
-
useEffect(function () {
|
|
974
|
-
storeRef.current.invokeOnMountDeferred();
|
|
975
|
-
return function () {
|
|
976
|
-
var _a;
|
|
977
|
-
(_a = storeRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
978
|
-
};
|
|
979
|
-
}, []);
|
|
980
|
-
return useStore(storeRef.current, props, refreshOnUpdate);
|
|
981
|
-
}
|
|
982
|
-
// ------------- UTILS
|
|
983
|
-
/**
|
|
984
|
-
* Creates a new object by picking properties to the object passed a first parameter
|
|
985
|
-
* @param obj Object to pick properties from
|
|
986
|
-
* @param props Property names
|
|
987
|
-
* @returns a new object containing only picked properties
|
|
988
|
-
*/
|
|
989
|
-
function pick(obj, props) {
|
|
990
|
-
return props.reduce(function (acc, p) {
|
|
991
|
-
if (obj.hasOwnProperty(p)) {
|
|
992
|
-
acc[p] = obj[p];
|
|
993
|
-
}
|
|
994
|
-
return acc;
|
|
995
|
-
}, {});
|
|
996
|
-
}
|
|
997
|
-
/**
|
|
998
|
-
* Returns a function that creates a new object by picking properties to the object passed as first parameter.
|
|
999
|
-
* To be used in conjunction of <code>useStoreSlice</code> like in example:
|
|
1000
|
-
* const s = useStoreSlice(myStore, slice('list', 'addItem'));
|
|
1001
|
-
* @param props Property names
|
|
1002
|
-
* @returns a function to pick property from an passed object.
|
|
1003
|
-
*/
|
|
1004
|
-
function slice() {
|
|
1005
|
-
var props = [];
|
|
1006
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1007
|
-
props[_i] = arguments[_i];
|
|
1008
|
-
}
|
|
1009
|
-
return function (store) { return pick(store, props); };
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
export default useLocalStore;
|
|
1013
|
-
export { ConflictPolicy, createStore, pick, slice, useLocalStore, useStore, useStoreContextSlice, useStoreSlice };
|
|
1
|
+
import r,{useMemo as n,useContext as e,useRef as t,useEffect as u,useReducer as o,useLayoutEffect as c}from"react";import{createRef as i,isSimpleSyncAction as a,decorateSimpleSyncAction as l,isAsyncAction as f,decorateAsyncAction as s,computeAsyncActionInput as d,isSyncAction as v,decorateSyncAction as p,globalConfig as O,onPropChange as _,DEFAULT_PROMISE_ID as E,fixDerivedDeps as S,computeDerivedValues as y,buildOnMountInvocationContext as g,buildOnUnMountInvocationContext as L,isLoadingImpl as h,runMiddlewares as b,buildLoadingMap as A,buildErrorMap as m}from"./impl";export{EffectError,ParallelActionError,setGlobalConfig}from"./impl";import{logDetailedEffects as R}from"./development";var T=function(){return T=Object.assign||function(r){for(var n,e=1,t=arguments.length;e<t;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(r[u]=n[u]);return r},T.apply(this,arguments)};function w(r){var n={exports:{}};return r(n,n.exports),n.exports}var M="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},j=r.useState,D=r.useEffect,x=r.useLayoutEffect,V=r.useDebugValue;function k(r){var n=r.getSnapshot;r=r.value;try{var e=n();return!M(r,e)}catch(r){return!0}}var C="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(r,n){return n()}:function(r,n){var e=n(),t=j({inst:{value:e,getSnapshot:n}}),u=t[0].inst,o=t[1];return x((function(){u.value=e,u.getSnapshot=n,k(u)&&o({inst:u})}),[r,e,n]),D((function(){return k(u)&&o({inst:u}),r((function(){k(u)&&o({inst:u})}))}),[r]),V(e),e},I={useSyncExternalStore:void 0!==r.useSyncExternalStore?r.useSyncExternalStore:C},P=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function u(r){for(var n=arguments.length,e=new Array(n>1?n-1:0),u=1;u<n;u++)e[u-1]=arguments[u];!function(r,n,e){var u=t.ReactDebugCurrentFrame.getStackAddendum();""!==u&&(n+="%s",e=e.concat([u]));var o=e.map((function(r){return String(r)}));o.unshift("Warning: "+n),Function.prototype.apply.call(console[r],console,o)}("error",r,e)}var o="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},c=n.useState,i=n.useEffect,a=n.useLayoutEffect,l=n.useDebugValue,f=!1,s=!1;function d(r){var n=r.getSnapshot,e=r.value;try{var t=n();return!o(e,t)}catch(r){return!0}}var v=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(r,n,e){return n()}:function(r,e,t){f||void 0!==n.startTransition&&(f=!0,u("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=e();if(!s){var p=e();o(v,p)||(u("The result of getSnapshot should be cached to avoid an infinite loop"),s=!0)}var O=c({inst:{value:v,getSnapshot:e}}),_=O[0].inst,E=O[1];return a((function(){_.value=v,_.getSnapshot=e,d(_)&&E({inst:_})}),[r,v,e]),i((function(){d(_)&&E({inst:_});return r((function(){d(_)&&E({inst:_})}))}),[r]),l(v),v},p=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:v;e.useSyncExternalStore=p,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),G=w((function(r){"production"===process.env.NODE_ENV?r.exports=I:r.exports=P}));var K,B="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},N=G.useSyncExternalStore,H=r.useRef,U=r.useEffect,W=r.useMemo,F=r.useDebugValue,Y={useSyncExternalStoreWithSelector:function(r,n,e,t,u){var o=H(null);if(null===o.current){var c={hasValue:!1,value:null};o.current=c}else c=o.current;o=W((function(){function r(r){if(!a){if(a=!0,o=r,r=t(r),void 0!==u&&c.hasValue){var n=c.value;if(u(n,r))return i=n}return i=r}if(n=i,B(o,r))return n;var e=t(r);return void 0!==u&&u(n,e)?n:(o=r,i=e)}var o,i,a=!1,l=void 0===e?null:e;return[function(){return r(n())},null===l?void 0:function(){return r(l())}]}),[n,e,t,u]);var i=N(r,o[0],o[1]);return U((function(){c.hasValue=!0,c.value=i}),[i]),F(i),i}},z=w((function(n,e){"production"!==process.env.NODE_ENV&&function(){"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var n=r,t=G;var u="function"==typeof Object.is?Object.is:function(r,n){return r===n&&(0!==r||1/r==1/n)||r!=r&&n!=n},o=t.useSyncExternalStore,c=n.useRef,i=n.useEffect,a=n.useMemo,l=n.useDebugValue;e.useSyncExternalStoreWithSelector=function(r,n,e,t,f){var s,d=c(null);null===d.current?(s={hasValue:!1,value:null},d.current=s):s=d.current;var v=a((function(){var r,o,c=!1,i=function(n){if(!c){c=!0,r=n;var e=t(n);if(void 0!==f&&s.hasValue){var i=s.value;if(f(i,e))return o=i,i}return o=e,e}var a=o;if(u(r,n))return a;var l=t(n);return void 0!==f&&f(a,l)?a:(r=n,o=l,l)},a=void 0===e?null:e;return[function(){return i(n())},null===a?void 0:function(){return i(a())}]}),[n,e,t,f]),p=v[0],O=v[1],_=o(r,p,O);return i((function(){s.hasValue=!0,s.value=_}),[_]),l(_),_},"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()})),J=w((function(r){"production"===process.env.NODE_ENV?r.exports=Y:r.exports=z}));!function(r){r.REJECT="reject",r.IGNORE="ignore",r.KEEP_LAST="keepLast",r.KEEP_ALL="keepAll",r.PARALLEL="parallel",r.REUSE="reuse"}(K||(K={}));var q=J.useSyncExternalStoreWithSelector,Q=G.useSyncExternalStore;function X(r){var n=i(),e=i(),t=i(),u=i(),o=i(),c=i(),w=i(),M=i(),j=i(),D=i(),x=i(),V=i(!1),k=i(),C=i([]),I=r.actions,P=r.middlewares,G=void 0===P?[]:P,K=function(r,n){var e={};for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&n.indexOf(t)<0&&(e[t]=r[t]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var u=0;for(t=Object.getOwnPropertySymbols(r);u<t.length;u++)n.indexOf(t[u])<0&&Object.prototype.propertyIsEnumerable.call(r,t[u])&&(e[t[u]]=r[t[u]])}return e}(r,["actions","middlewares"]),B=r.getInitialState||function(){return r.initialState},N={},H=0;function U(){k.current=T(T(T(T({},u.current),n.current),e.current.state),{isLoading:Q,abortAction:X,loading:M.current,loadingMap:w.current,loadingParallelMap:c.current,errorMap:Z(),errorParallelMap:j.current}),Object.keys(N).forEach((function(r){var n;null===(n=N[r])||void 0===n||n.call(N)}))}function W(r){n.current=r,y(n,t,e,K),U()}function F(r){c.current=r,w.current=function(){if(V.current){var r=c.current;return Object.keys(r).reduce((function(n,e){var t=r[e];return n[e]=null!=Object.keys(t).find((function(r){return!!t[r]})),n}),{})}return null}(),M.current=function(){if(V.current){var r=c.current;return null!=Object.keys(r).find((function(n){var e=r[n];return Object.keys(e).find((function(r){return!!e[r]}))}))}return null}()}function Y(c){var i;if(!V.current){t.current=c,V.current=!0,n.current=B(c);var a=new Set(null==K?void 0:K.initialActionsMarkedLoading),l=Object.keys(I).reduce((function(r,n){var e;return r[n]=a.has(n)?((e={})[E]=!0,e):{},r}),{});F(l),j.current=Object.keys(I).reduce((function(r,n){return r[n]={},r}),{}),o.current={},D.current={},x.current={},e.current={state:null,deps:{}},(null==K?void 0:K.derivedState)&&S(K),C.current=[];var f={options:K,get state(){return n.current},actions:I,setState:W};r.logEnabled&&R&&G.push(R());var s=function(r){var n,e=r();C.current.push(e),null===(n=e.init)||void 0===n||n.call(e,f)};null===(i=O.defaultMiddlewares)||void 0===i||i.forEach(s),null==G||G.forEach(s),y(n,t,e,K),_(n,e,t,null,u,K,B,J,!0,!1),(null==K?void 0:K.onMount)&&K.onMount(g(n,e,t,u)),U()}}function z(r,n){void 0===n&&(n=E);var e=j.current[r];(null==e?void 0:e[n])&&delete e[n],U()}function J(r,u,o,i,a,l,f,s){void 0===f&&(f=!1),void 0===s&&(s=!1);var d=!1;if(V.current){var v=u,p=!!a&&h(v||c.current,[o,null==l?void 0:l.promiseId]),O=b(C.current,n.current,r,p,o,i,a,l),_=O.newState,S=O.newLoading;if(null!=_&&(d=!0,n.current=_),p!==S&&(v=A(v,o,(null==l?void 0:l.promiseId)||E,S),0===Object.keys(v).length&&(v=void 0)),null!=v&&(d=!0,F(v)),d)y(n,t,e,K),s||(n.current=_||n.current,U());else if(f){y(n,t,e,K)&&!s&&U()}}}var q=Object.keys(I);function Q(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return h.apply(void 0,function(r,n,e){if(e||2===arguments.length)for(var t,u=0,o=n.length;u<o;u++)!t&&u in n||(t||(t=Array.prototype.slice.call(n,0,u)),t[u]=n[u]);return r.concat(t||Array.prototype.slice.call(n))}([c.current],r,!1))}function X(r,n){var e,t;void 0===n&&(n=E);var u=null===(t=null===(e=D.current[r])||void 0===e?void 0:e[n])||void 0===t?void 0:t.abortController,o=!1;return u&&(u.abort(),o=!0),o}function Z(){return V.current?m(j.current):null}return u.current=q.reduce((function(r,i){var O=I[i];return a(O)?r[i]=l(i,O,n,e,t,V,K,J):f(O)?r[i]=s({actionName:i,stateRef:n,derivedStateRef:e,propsRef:t,loadingParallelMapRef:c,errorMapRef:j,actionsRef:u,promisesRef:D,conflictActionsRef:x,initializedRef:V,options:K,setState:J,clearError:z,action:d(O)}):v(O)&&(r[i]=p(i,O,n,e,t,u,V,o,K,J,z)),r}),{}),{getConfig:function(){return T({},r)},setProps:function(r){var o=t.current;t.current=r,V.current?_(n,e,t,o,u,K,B,J,!1,!1):Y(r)},addStateListener:function(r){var n="".concat(H++);return N[n]=r,function(){delete N[n]}},init:Y,destroy:function(){var r;if(V.current){var u=Object.keys(I).reduce((function(r,n){var e=I[n];if(f(e)&&e.abortable){var t=c.current[n],u=Object.keys(t).reduce((function(r,e){return t[e]&&(X(n,e),r.push(e)),r}),[]);u.length>0&&(r[n]=u)}return r}),{});null===(r=null==K?void 0:K.onUnmount)||void 0===r||r.call(K,L(n,e,t,u)),t.current=null,n.current=null,c.current=null,w.current=null,M.current=null,j.current=null,D.current=null,x.current=null,e.current=null,k.current=null,Object.keys(o.current).forEach((function(r){clearTimeout(o.current[r])})),o.current=null,N={},V.current=!1,C.current.forEach((function(r){var n;null===(n=r.destroy)||void 0===n||n.call(r)})),C.current=[]}},isLoading:Q,abortAction:X,clearError:z,getSnapshot:function(){return k.current},invokeOnMountDeferred:function(){_(n,e,t,null,u,K,B,J,!0,!0),(null==K?void 0:K.onMountDeferred)&&K.onMountDeferred(g(n,e,t,u))},get actions(){return u.current},get state(){return V.current?T(T({},n.current),e.current.state):null},get loading(){return M.current},get loadingMap(){return w.current},get errorMap(){return Z()},get loadingParallelMap(){return V.current?c.current:null},get errorParallelMap(){return V.current?j.current:null}}}function Z(r,e){var t=n((function(){return e instanceof Function?e:function(r){return er(r,e)}}),[e]);return q(r.addStateListener,r.getSnapshot,r.getSnapshot,t,O.comparator)}function $(r){return Q(r.addStateListener,r.getSnapshot),r}function rr(r,n){return Z(e(r),n)}function nr(r,n,e){void 0===e&&(e=!0);var i=t();return null==i.current&&(i.current=X(r)),u((function(){return i.current.invokeOnMountDeferred(),function(){var r;null===(r=i.current)||void 0===r||r.destroy()}}),[]),function(r,n,e){void 0===n&&(n=null),void 0===e&&(e=!0);var u=o((function(r){return r>100?0:r+1}),0)[1],i=t(r);return r.setProps(n),c((function(){r.init(n)}),[]),c((function(){if(e)return i.current.addStateListener((function(){u()}))}),[e]),r}(i.current,n,e)}function er(r,n){return n.reduce((function(n,e){return r.hasOwnProperty(e)&&(n[e]=r[e]),n}),{})}function tr(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return function(n){return er(n,r)}}export default nr;export{K as ConflictPolicy,X as createStore,er as pick,tr as slice,nr as useLocalStore,$ as useStore,rr as useStoreContextSlice,Z as useStoreSlice};
|
|
1014
2
|
//# sourceMappingURL=index.js.map
|