@depup/reduxjs__toolkit 2.12.0-depup.29 → 2.13.0-depup.0
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 +2 -2
- package/changes.json +1 -1
- package/dist/cjs/redux-toolkit.development.cjs +1755 -2247
- package/dist/cjs/redux-toolkit.development.cjs.map +1 -1
- package/dist/cjs/redux-toolkit.production.min.cjs +1 -2
- package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -1
- package/dist/index.d.mts +1496 -1525
- package/dist/index.d.ts +1496 -1525
- package/dist/query/cjs/rtk-query.development.cjs +2059 -2990
- package/dist/query/cjs/rtk-query.development.cjs.map +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs +1 -1
- package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -1
- package/dist/query/index.d.mts +2300 -2308
- package/dist/query/index.d.ts +2300 -2308
- package/dist/query/react/cjs/rtk-query-react.development.cjs +609 -714
- package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs +1 -1
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -1
- package/dist/query/react/index.d.mts +516 -523
- package/dist/query/react/index.d.ts +516 -523
- package/dist/query/react/rtk-query-react.browser.mjs +1 -1
- package/dist/query/react/rtk-query-react.browser.mjs.map +1 -1
- package/dist/query/react/rtk-query-react.legacy-esm.js +672 -714
- package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -1
- package/dist/query/react/rtk-query-react.modern.mjs +586 -679
- package/dist/query/react/rtk-query-react.modern.mjs.map +1 -1
- package/dist/query/rtk-query.browser.mjs +1 -1
- package/dist/query/rtk-query.browser.mjs.map +1 -1
- package/dist/query/rtk-query.legacy-esm.js +2175 -3014
- package/dist/query/rtk-query.legacy-esm.js.map +1 -1
- package/dist/query/rtk-query.modern.mjs +2052 -2949
- package/dist/query/rtk-query.modern.mjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.development.cjs +30 -51
- package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs +1 -1
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -1
- package/dist/react/index.d.mts +12 -15
- package/dist/react/index.d.ts +12 -15
- package/dist/react/redux-toolkit-react.browser.mjs +1 -1
- package/dist/react/redux-toolkit-react.browser.mjs.map +1 -1
- package/dist/react/redux-toolkit-react.legacy-esm.js +83 -44
- package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -1
- package/dist/react/redux-toolkit-react.modern.mjs +23 -25
- package/dist/react/redux-toolkit-react.modern.mjs.map +1 -1
- package/dist/redux-toolkit.browser.mjs +1 -2
- package/dist/redux-toolkit.browser.mjs.map +1 -1
- package/dist/redux-toolkit.legacy-esm.js +1748 -2201
- package/dist/redux-toolkit.legacy-esm.js.map +1 -1
- package/dist/redux-toolkit.modern.mjs +1670 -2171
- package/dist/redux-toolkit.modern.mjs.map +1 -1
- package/package.json +13 -29
- package/skills/build-modern-redux-apps/modern-redux/SKILL.md +23 -14
- package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +6 -6
- package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +13 -10
- package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +6 -6
- package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +7 -8
- package/skills/manage-server-data/adopt-rtk-query/SKILL.md +13 -11
- package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +26 -14
- package/skills/model-redux-state/design-state-ownership/SKILL.md +11 -12
- package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +6 -6
- package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +27 -23
- package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +4 -4
- package/src/autoBatchEnhancer.ts +5 -3
- package/src/combineSlices.ts +5 -5
- package/src/createAction.ts +11 -6
- package/src/createAsyncThunk.ts +14 -2
- package/src/createReducer.ts +1 -1
- package/src/createSlice.ts +9 -4
- package/src/dynamicMiddleware/index.ts +21 -5
- package/src/entities/models.ts +2 -1
- package/src/entities/sorted_state_adapter.ts +35 -24
- package/src/entities/unsorted_state_adapter.ts +1 -1
- package/src/immutableStateInvariantMiddleware.ts +34 -5
- package/src/listenerMiddleware/types.ts +10 -10
- package/src/mapBuilders.ts +2 -5
- package/src/matchers.ts +7 -1
- package/src/query/core/apiState.ts +1 -1
- package/src/query/core/buildInitiate.ts +19 -15
- package/src/query/core/buildMiddleware/cacheLifecycle.ts +3 -1
- package/src/query/core/buildMiddleware/index.ts +1 -1
- package/src/query/core/buildMiddleware/invalidationByTags.ts +4 -1
- package/src/query/core/buildMiddleware/polling.ts +12 -3
- package/src/query/core/buildMiddleware/types.ts +5 -2
- package/src/query/core/buildSlice.ts +2 -2
- package/src/query/core/buildThunks.ts +19 -0
- package/src/query/core/module.ts +9 -3
- package/src/query/createApi.ts +4 -1
- package/src/query/endpointDefinitions.ts +15 -9
- package/src/query/fetchBaseQuery.ts +1 -1
- package/src/query/react/buildHooks.ts +54 -51
- package/src/query/react/namedHooks.ts +28 -24
- package/src/query/utils/isAbsoluteUrl.ts +8 -3
- package/src/serializableStateInvariantMiddleware.ts +1 -1
|
@@ -1,2351 +1,1898 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
33
|
-
|
|
34
|
-
// src/index.ts
|
|
1
|
+
import { applyMiddleware, combineReducers, combineReducers as combineReducers$1, compose, createStore, isAction, isPlainObject } from "redux";
|
|
2
|
+
import { current, freeze, isDraft, isDraftable, original, produce as createNextState } from "immer";
|
|
3
|
+
import { createSelector, createSelectorCreator, lruMemoize, weakMapMemoize } from "reselect";
|
|
4
|
+
import { thunk, withExtraArgument } from "redux-thunk";
|
|
35
5
|
export * from "redux";
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// src/createDraftSafeSelector.ts
|
|
48
|
-
var createDraftSafeSelectorCreator = (...args) => {
|
|
49
|
-
const createSelector2 = createSelectorCreator(...args);
|
|
50
|
-
const createDraftSafeSelector2 = Object.assign((...args2) => {
|
|
51
|
-
const selector = createSelector2(...args2);
|
|
52
|
-
const wrappedSelector = (value, ...rest) => selector(isDraft(value) ? current(value) : value, ...rest);
|
|
53
|
-
Object.assign(wrappedSelector, selector);
|
|
54
|
-
return wrappedSelector;
|
|
55
|
-
}, {
|
|
56
|
-
withTypes: () => createDraftSafeSelector2
|
|
57
|
-
});
|
|
58
|
-
return createDraftSafeSelector2;
|
|
6
|
+
//#region src/createDraftSafeSelector.ts
|
|
7
|
+
const createDraftSafeSelectorCreator = (...args) => {
|
|
8
|
+
const createSelector = createSelectorCreator(...args);
|
|
9
|
+
const createDraftSafeSelector = Object.assign((...args) => {
|
|
10
|
+
const selector = createSelector(...args);
|
|
11
|
+
const wrappedSelector = (value, ...rest) => selector(isDraft(value) ? current(value) : value, ...rest);
|
|
12
|
+
Object.assign(wrappedSelector, selector);
|
|
13
|
+
return wrappedSelector;
|
|
14
|
+
}, { withTypes: () => createDraftSafeSelector });
|
|
15
|
+
return createDraftSafeSelector;
|
|
59
16
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (arguments.length === 0) return void 0;
|
|
68
|
-
if (typeof arguments[0] === "object") return compose;
|
|
69
|
-
return compose.apply(null, arguments);
|
|
17
|
+
const createDraftSafeSelector = /* @__PURE__ */ createDraftSafeSelectorCreator(weakMapMemoize);
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/devtoolsExtension.ts
|
|
20
|
+
const composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
|
21
|
+
if (arguments.length === 0) return void 0;
|
|
22
|
+
if (typeof arguments[0] === "object") return compose;
|
|
23
|
+
return compose.apply(null, arguments);
|
|
70
24
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
25
|
+
typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/tsHelpers.ts
|
|
28
|
+
const hasMatchFunction = (v) => {
|
|
29
|
+
return v && typeof v.match === "function";
|
|
75
30
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/typeof.js
|
|
33
|
+
function _typeof(o) {
|
|
34
|
+
"@babel/helpers - typeof";
|
|
35
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
36
|
+
return typeof o;
|
|
37
|
+
} : function(o) {
|
|
38
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
39
|
+
}, _typeof(o);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPrimitive.js
|
|
43
|
+
function toPrimitive(t, r) {
|
|
44
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
45
|
+
var e = t[Symbol.toPrimitive];
|
|
46
|
+
if (void 0 !== e) {
|
|
47
|
+
var i = e.call(t, r || "default");
|
|
48
|
+
if ("object" != _typeof(i)) return i;
|
|
49
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
50
|
+
}
|
|
51
|
+
return ("string" === r ? String : Number)(t);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPropertyKey.js
|
|
55
|
+
function toPropertyKey(t) {
|
|
56
|
+
var i = toPrimitive(t, "string");
|
|
57
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/defineProperty.js
|
|
61
|
+
function _defineProperty(e, r, t) {
|
|
62
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
63
|
+
value: t,
|
|
64
|
+
enumerable: !0,
|
|
65
|
+
configurable: !0,
|
|
66
|
+
writable: !0
|
|
67
|
+
}) : e[r] = t, e;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/objectSpread2.js
|
|
71
|
+
function ownKeys(e, r) {
|
|
72
|
+
var t = Object.keys(e);
|
|
73
|
+
if (Object.getOwnPropertySymbols) {
|
|
74
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
75
|
+
r && (o = o.filter(function(r) {
|
|
76
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
77
|
+
})), t.push.apply(t, o);
|
|
78
|
+
}
|
|
79
|
+
return t;
|
|
80
|
+
}
|
|
81
|
+
function _objectSpread2(e) {
|
|
82
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
83
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
84
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
85
|
+
_defineProperty(e, r, t[r]);
|
|
86
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
87
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return e;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/createAction.ts
|
|
86
94
|
function createAction(type, prepareAction) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
actionCreator.toString = () => `${type}`;
|
|
108
|
-
actionCreator.type = type;
|
|
109
|
-
actionCreator.match = (action) => isAction(action) && action.type === type;
|
|
110
|
-
return actionCreator;
|
|
95
|
+
function actionCreator(...args) {
|
|
96
|
+
if (prepareAction) {
|
|
97
|
+
let prepared = prepareAction(...args);
|
|
98
|
+
if (!prepared) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "prepareAction did not return an object");
|
|
99
|
+
return _objectSpread2(_objectSpread2({
|
|
100
|
+
type,
|
|
101
|
+
payload: prepared.payload
|
|
102
|
+
}, "meta" in prepared && { meta: prepared.meta }), "error" in prepared && { error: prepared.error });
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
type,
|
|
106
|
+
payload: args[0]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
actionCreator.toString = () => `${type}`;
|
|
110
|
+
actionCreator.type = type;
|
|
111
|
+
actionCreator.match = (action) => isAction(action) && action.type === type;
|
|
112
|
+
return actionCreator;
|
|
111
113
|
}
|
|
112
114
|
function isActionCreator(action) {
|
|
113
|
-
|
|
114
|
-
hasMatchFunction(action);
|
|
115
|
+
return typeof action === "function" && "type" in action && hasMatchFunction(action);
|
|
115
116
|
}
|
|
116
117
|
function isFSA(action) {
|
|
117
|
-
|
|
118
|
+
return isAction(action) && Object.keys(action).every(isValidKey);
|
|
118
119
|
}
|
|
119
120
|
function isValidKey(key) {
|
|
120
|
-
|
|
121
|
+
return [
|
|
122
|
+
"type",
|
|
123
|
+
"payload",
|
|
124
|
+
"error",
|
|
125
|
+
"meta"
|
|
126
|
+
].indexOf(key) > -1;
|
|
121
127
|
}
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/actionCreatorInvariantMiddleware.ts
|
|
124
130
|
function getMessage(type) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
const splitType = type ? `${type}`.split("/") : [];
|
|
132
|
+
const actionName = splitType[splitType.length - 1] || "actionCreator";
|
|
133
|
+
return `Detected an action creator with type "${type || "unknown"}" being dispatched.
|
|
128
134
|
Make sure you're calling the action creator before dispatching, i.e. \`dispatch(${actionName}())\` instead of \`dispatch(${actionName})\`. This is necessary even if the action has no payload.`;
|
|
129
135
|
}
|
|
130
136
|
function createActionCreatorInvariantMiddleware(options = {}) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return () => (next) => (action) => {
|
|
138
|
-
if (isActionCreator2(action)) {
|
|
139
|
-
console.warn(getMessage(action.type));
|
|
140
|
-
}
|
|
141
|
-
return next(action);
|
|
142
|
-
};
|
|
137
|
+
if (process.env.NODE_ENV === "production") return () => (next) => (action) => next(action);
|
|
138
|
+
const { isActionCreator: isActionCreator$1 = isActionCreator } = options;
|
|
139
|
+
return () => (next) => (action) => {
|
|
140
|
+
if (isActionCreator$1(action)) console.warn(getMessage(action.type));
|
|
141
|
+
return next(action);
|
|
142
|
+
};
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/utils.ts
|
|
146
146
|
function getTimeMeasureUtils(maxDelay, fnName) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (elapsed > maxDelay) {
|
|
160
|
-
console.warn(`${fnName} took ${elapsed}ms, which is more than the warning threshold of ${maxDelay}ms.
|
|
147
|
+
let elapsed = 0;
|
|
148
|
+
return {
|
|
149
|
+
measureTime(fn) {
|
|
150
|
+
const started = Date.now();
|
|
151
|
+
try {
|
|
152
|
+
return fn();
|
|
153
|
+
} finally {
|
|
154
|
+
elapsed += Date.now() - started;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
warnIfExceeded() {
|
|
158
|
+
if (elapsed > maxDelay) console.warn(`${fnName} took ${elapsed}ms, which is more than the warning threshold of ${maxDelay}ms.
|
|
161
159
|
If your state or actions are very large, you may want to disable the middleware as it might cause too much of a slowdown in development mode. See https://redux-toolkit.js.org/api/getDefaultMiddleware for instructions.
|
|
162
160
|
It is disabled in production builds, so you don't need to worry about that.`);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
return new _Tuple(...arr.concat(this));
|
|
183
|
-
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
var Tuple = class Tuple extends Array {
|
|
165
|
+
constructor(...items) {
|
|
166
|
+
super(...items);
|
|
167
|
+
Object.setPrototypeOf(this, Tuple.prototype);
|
|
168
|
+
}
|
|
169
|
+
static get [Symbol.species]() {
|
|
170
|
+
return Tuple;
|
|
171
|
+
}
|
|
172
|
+
concat(...arr) {
|
|
173
|
+
return super.concat.apply(this, arr);
|
|
174
|
+
}
|
|
175
|
+
prepend(...arr) {
|
|
176
|
+
if (arr.length === 1 && Array.isArray(arr[0])) return new Tuple(...arr[0].concat(this));
|
|
177
|
+
return new Tuple(...arr.concat(this));
|
|
178
|
+
}
|
|
184
179
|
};
|
|
185
180
|
function freezeDraftable(val) {
|
|
186
|
-
|
|
187
|
-
}) : val;
|
|
181
|
+
return isDraftable(val) ? createNextState(val, () => {}) : val;
|
|
188
182
|
}
|
|
189
183
|
function getOrInsertComputed(map, key, compute) {
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
if (map.has(key)) return map.get(key);
|
|
185
|
+
return map.set(key, compute(key)).get(key);
|
|
192
186
|
}
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/immutableStateInvariantMiddleware.ts
|
|
195
189
|
function isImmutableDefault(value) {
|
|
196
|
-
|
|
190
|
+
return typeof value !== "object" || value == null || Object.isFrozen(value);
|
|
197
191
|
}
|
|
198
192
|
function trackForMutations(isImmutable, ignoredPaths, obj) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (hasIgnoredPaths) {
|
|
257
|
-
const hasMatches = ignoredPaths.some((ignored) => {
|
|
258
|
-
if (ignored instanceof RegExp) {
|
|
259
|
-
return ignored.test(nestedPath);
|
|
260
|
-
}
|
|
261
|
-
return nestedPath === ignored;
|
|
262
|
-
});
|
|
263
|
-
if (hasMatches) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath);
|
|
268
|
-
if (result.wasMutated) {
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
wasMutated: false
|
|
274
|
-
};
|
|
193
|
+
const trackedProperties = trackProperties(isImmutable, ignoredPaths, obj);
|
|
194
|
+
return { detectMutations() {
|
|
195
|
+
return detectMutations(isImmutable, ignoredPaths, trackedProperties, obj);
|
|
196
|
+
} };
|
|
197
|
+
}
|
|
198
|
+
function trackProperties(isImmutable, ignoredPaths = [], obj, path = "", inProgress = /* @__PURE__ */ new Map()) {
|
|
199
|
+
const tracked = { value: obj };
|
|
200
|
+
if (!isImmutable(obj)) {
|
|
201
|
+
const alreadyInProgress = inProgress.get(obj);
|
|
202
|
+
if (alreadyInProgress) return alreadyInProgress;
|
|
203
|
+
tracked.children = {};
|
|
204
|
+
inProgress.set(obj, tracked);
|
|
205
|
+
const hasIgnoredPaths = ignoredPaths.length > 0;
|
|
206
|
+
for (const key in obj) {
|
|
207
|
+
const nestedPath = path ? path + "." + key : key;
|
|
208
|
+
if (hasIgnoredPaths) {
|
|
209
|
+
if (ignoredPaths.some((ignored) => {
|
|
210
|
+
if (ignored instanceof RegExp) return ignored.test(nestedPath);
|
|
211
|
+
return nestedPath === ignored;
|
|
212
|
+
})) continue;
|
|
213
|
+
}
|
|
214
|
+
tracked.children[key] = trackProperties(isImmutable, ignoredPaths, obj[key], nestedPath, inProgress);
|
|
215
|
+
}
|
|
216
|
+
inProgress.delete(obj);
|
|
217
|
+
}
|
|
218
|
+
return tracked;
|
|
219
|
+
}
|
|
220
|
+
function detectMutations(isImmutable, ignoredPaths = [], trackedProperty, obj, sameParentRef = false, path = "", seen = /* @__PURE__ */ new Map()) {
|
|
221
|
+
const prevObj = trackedProperty ? trackedProperty.value : void 0;
|
|
222
|
+
const sameRef = prevObj === obj;
|
|
223
|
+
if (sameParentRef && !sameRef && !Number.isNaN(obj)) return {
|
|
224
|
+
wasMutated: true,
|
|
225
|
+
path
|
|
226
|
+
};
|
|
227
|
+
if (isImmutable(prevObj) || isImmutable(obj)) return { wasMutated: false };
|
|
228
|
+
let seenValues = seen.get(trackedProperty);
|
|
229
|
+
if (!seenValues) {
|
|
230
|
+
seenValues = /* @__PURE__ */ new Set();
|
|
231
|
+
seen.set(trackedProperty, seenValues);
|
|
232
|
+
} else if (seenValues.has(obj)) return { wasMutated: false };
|
|
233
|
+
seenValues.add(obj);
|
|
234
|
+
const keysToDetect = {};
|
|
235
|
+
for (let key in trackedProperty.children) keysToDetect[key] = true;
|
|
236
|
+
for (let key in obj) keysToDetect[key] = true;
|
|
237
|
+
const hasIgnoredPaths = ignoredPaths.length > 0;
|
|
238
|
+
for (let key in keysToDetect) {
|
|
239
|
+
const nestedPath = path ? path + "." + key : key;
|
|
240
|
+
if (hasIgnoredPaths) {
|
|
241
|
+
if (ignoredPaths.some((ignored) => {
|
|
242
|
+
if (ignored instanceof RegExp) return ignored.test(nestedPath);
|
|
243
|
+
return nestedPath === ignored;
|
|
244
|
+
})) continue;
|
|
245
|
+
}
|
|
246
|
+
const result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath, seen);
|
|
247
|
+
if (result.wasMutated) return result;
|
|
248
|
+
}
|
|
249
|
+
return { wasMutated: false };
|
|
275
250
|
}
|
|
276
251
|
function createImmutableStateInvariantMiddleware(options = {}) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
});
|
|
330
|
-
measureUtils.warnIfExceeded();
|
|
331
|
-
return dispatchedAction;
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
}
|
|
252
|
+
if (process.env.NODE_ENV === "production") return () => (next) => (action) => next(action);
|
|
253
|
+
else {
|
|
254
|
+
function stringify(obj, serializer, indent, decycler) {
|
|
255
|
+
return JSON.stringify(obj, getSerialize(serializer, decycler), indent);
|
|
256
|
+
}
|
|
257
|
+
function getSerialize(serializer, decycler) {
|
|
258
|
+
let stack = [], keys = [];
|
|
259
|
+
if (!decycler) decycler = function(_, value) {
|
|
260
|
+
if (stack[0] === value) return "[Circular ~]";
|
|
261
|
+
return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
|
262
|
+
};
|
|
263
|
+
return function(key, value) {
|
|
264
|
+
if (stack.length > 0) {
|
|
265
|
+
var thisPos = stack.indexOf(this);
|
|
266
|
+
if (~thisPos) {
|
|
267
|
+
stack.splice(thisPos + 1);
|
|
268
|
+
keys.splice(thisPos, Infinity, key);
|
|
269
|
+
} else {
|
|
270
|
+
stack.push(this);
|
|
271
|
+
keys.push(key);
|
|
272
|
+
}
|
|
273
|
+
if (~stack.indexOf(value)) value = decycler.call(this, key, value);
|
|
274
|
+
} else stack.push(value);
|
|
275
|
+
return serializer == null ? value : serializer.call(this, key, value);
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
let { isImmutable = isImmutableDefault, ignoredPaths, warnAfter = 32 } = options;
|
|
279
|
+
const track = trackForMutations.bind(null, isImmutable, ignoredPaths);
|
|
280
|
+
return ({ getState }) => {
|
|
281
|
+
let state = getState();
|
|
282
|
+
let tracker = track(state);
|
|
283
|
+
let result;
|
|
284
|
+
return (next) => (action) => {
|
|
285
|
+
const measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
|
|
286
|
+
measureUtils.measureTime(() => {
|
|
287
|
+
state = getState();
|
|
288
|
+
result = tracker.detectMutations();
|
|
289
|
+
tracker = track(state);
|
|
290
|
+
if (result.wasMutated) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(19) : `A state mutation was detected between dispatches, in the path '${result.path || ""}'. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`);
|
|
291
|
+
});
|
|
292
|
+
const dispatchedAction = next(action);
|
|
293
|
+
measureUtils.measureTime(() => {
|
|
294
|
+
state = getState();
|
|
295
|
+
result = tracker.detectMutations();
|
|
296
|
+
tracker = track(state);
|
|
297
|
+
if (result.wasMutated) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(20) : `A state mutation was detected inside a dispatch, in the path: ${result.path || ""}. Take a look at the reducer(s) handling the action ${stringify(action)}. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`);
|
|
298
|
+
});
|
|
299
|
+
measureUtils.warnIfExceeded();
|
|
300
|
+
return dispatchedAction;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
}
|
|
335
304
|
}
|
|
336
|
-
|
|
337
|
-
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/serializableStateInvariantMiddleware.ts
|
|
338
307
|
function isPlain(val) {
|
|
339
|
-
|
|
340
|
-
|
|
308
|
+
const type = typeof val;
|
|
309
|
+
return val == null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
|
|
341
310
|
}
|
|
342
311
|
function findNonSerializableValue(value, path = "", isSerializable = isPlain, getEntries, ignoredPaths = [], cache) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
keyPath: nestedPath,
|
|
372
|
-
value: nestedValue
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
if (typeof nestedValue === "object") {
|
|
376
|
-
foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
|
|
377
|
-
if (foundNestedSerializable) {
|
|
378
|
-
return foundNestedSerializable;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (cache && isNestedFrozen(value)) cache.add(value);
|
|
383
|
-
return false;
|
|
312
|
+
let foundNestedSerializable;
|
|
313
|
+
if (!isSerializable(value)) return {
|
|
314
|
+
keyPath: path || "<root>",
|
|
315
|
+
value
|
|
316
|
+
};
|
|
317
|
+
if (typeof value !== "object" || value === null) return false;
|
|
318
|
+
if (cache === null || cache === void 0 ? void 0 : cache.has(value)) return false;
|
|
319
|
+
const entries = getEntries != null ? getEntries(value) : Object.entries(value);
|
|
320
|
+
const hasIgnoredPaths = ignoredPaths.length > 0;
|
|
321
|
+
for (const [key, nestedValue] of entries) {
|
|
322
|
+
const nestedPath = path ? path + "." + key : key;
|
|
323
|
+
if (hasIgnoredPaths) {
|
|
324
|
+
if (ignoredPaths.some((ignored) => {
|
|
325
|
+
if (ignored instanceof RegExp) return ignored.test(nestedPath);
|
|
326
|
+
return nestedPath === ignored;
|
|
327
|
+
})) continue;
|
|
328
|
+
}
|
|
329
|
+
if (!isSerializable(nestedValue)) return {
|
|
330
|
+
keyPath: nestedPath,
|
|
331
|
+
value: nestedValue
|
|
332
|
+
};
|
|
333
|
+
if (typeof nestedValue === "object") {
|
|
334
|
+
foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
|
|
335
|
+
if (foundNestedSerializable) return foundNestedSerializable;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (cache && isNestedFrozen(value)) cache.add(value);
|
|
339
|
+
return false;
|
|
384
340
|
}
|
|
385
341
|
function isNestedFrozen(value) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
342
|
+
if (!Object.isFrozen(value)) return false;
|
|
343
|
+
for (const nestedValue of Object.values(value)) {
|
|
344
|
+
if (typeof nestedValue !== "object" || nestedValue === null) continue;
|
|
345
|
+
if (!isNestedFrozen(nestedValue)) return false;
|
|
346
|
+
}
|
|
347
|
+
return true;
|
|
392
348
|
}
|
|
393
349
|
function createSerializableStateInvariantMiddleware(options = {}) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) {
|
|
416
|
-
measureUtils.measureTime(() => {
|
|
417
|
-
const foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
|
|
418
|
-
if (foundActionNonSerializableValue) {
|
|
419
|
-
const {
|
|
420
|
-
keyPath,
|
|
421
|
-
value
|
|
422
|
-
} = foundActionNonSerializableValue;
|
|
423
|
-
console.error(`A non-serializable value was detected in an action, in the path: \`${keyPath}\`. Value:`, value, "\nTake a look at the logic that dispatched this action: ", action, "\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)", "\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)");
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
if (!ignoreState) {
|
|
428
|
-
measureUtils.measureTime(() => {
|
|
429
|
-
const state = storeAPI.getState();
|
|
430
|
-
const foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths, cache);
|
|
431
|
-
if (foundStateNonSerializableValue) {
|
|
432
|
-
const {
|
|
433
|
-
keyPath,
|
|
434
|
-
value
|
|
435
|
-
} = foundStateNonSerializableValue;
|
|
436
|
-
console.error(`A non-serializable value was detected in the state, in the path: \`${keyPath}\`. Value:`, value, `
|
|
350
|
+
if (process.env.NODE_ENV === "production") return () => (next) => (action) => next(action);
|
|
351
|
+
else {
|
|
352
|
+
const { isSerializable = isPlain, getEntries, ignoredActions = [], ignoredActionPaths = ["meta.arg", "meta.baseQueryMeta"], ignoredPaths = [], warnAfter = 32, ignoreState = false, ignoreActions = false, disableCache = false } = options;
|
|
353
|
+
const cache = !disableCache && WeakSet ? /* @__PURE__ */ new WeakSet() : void 0;
|
|
354
|
+
return (storeAPI) => (next) => (action) => {
|
|
355
|
+
if (!isAction(action)) return next(action);
|
|
356
|
+
const result = next(action);
|
|
357
|
+
const measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
|
|
358
|
+
if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) measureUtils.measureTime(() => {
|
|
359
|
+
const foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
|
|
360
|
+
if (foundActionNonSerializableValue) {
|
|
361
|
+
const { keyPath, value } = foundActionNonSerializableValue;
|
|
362
|
+
console.error(`A non-serializable value was detected in an action, in the path: \`${keyPath}\`. Value:`, value, "\nTake a look at the logic that dispatched this action: ", action, "\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-why-should-my-action-types-be-constants)", "\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)");
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
if (!ignoreState) {
|
|
366
|
+
measureUtils.measureTime(() => {
|
|
367
|
+
const foundStateNonSerializableValue = findNonSerializableValue(storeAPI.getState(), "", isSerializable, getEntries, ignoredPaths, cache);
|
|
368
|
+
if (foundStateNonSerializableValue) {
|
|
369
|
+
const { keyPath, value } = foundStateNonSerializableValue;
|
|
370
|
+
console.error(`A non-serializable value was detected in the state, in the path: \`${keyPath}\`. Value:`, value, `
|
|
437
371
|
Take a look at the reducer(s) handling this action type: ${action.type}.
|
|
438
372
|
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)`);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
measureUtils.warnIfExceeded();
|
|
376
|
+
}
|
|
377
|
+
return result;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
446
380
|
}
|
|
447
|
-
|
|
448
|
-
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/getDefaultMiddleware.ts
|
|
449
383
|
function isBoolean(x) {
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (!isBoolean(serializableCheck)) {
|
|
478
|
-
serializableOptions = serializableCheck;
|
|
479
|
-
}
|
|
480
|
-
middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
|
|
481
|
-
}
|
|
482
|
-
if (actionCreatorCheck) {
|
|
483
|
-
let actionCreatorOptions = {};
|
|
484
|
-
if (!isBoolean(actionCreatorCheck)) {
|
|
485
|
-
actionCreatorOptions = actionCreatorCheck;
|
|
486
|
-
}
|
|
487
|
-
middlewareArray.unshift(createActionCreatorInvariantMiddleware(actionCreatorOptions));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return middlewareArray;
|
|
384
|
+
return typeof x === "boolean";
|
|
385
|
+
}
|
|
386
|
+
const buildGetDefaultMiddleware = () => function getDefaultMiddleware(options) {
|
|
387
|
+
const { thunk: thunk$1 = true, immutableCheck = true, serializableCheck = true, actionCreatorCheck = true } = options !== null && options !== void 0 ? options : {};
|
|
388
|
+
let middlewareArray = new Tuple();
|
|
389
|
+
if (thunk$1) {
|
|
390
|
+
if (isBoolean(thunk$1)) middlewareArray.push(thunk);
|
|
391
|
+
else middlewareArray.push(withExtraArgument(thunk$1.extraArgument));
|
|
392
|
+
}
|
|
393
|
+
if (process.env.NODE_ENV !== "production") {
|
|
394
|
+
if (immutableCheck) {
|
|
395
|
+
let immutableOptions = {};
|
|
396
|
+
if (!isBoolean(immutableCheck)) immutableOptions = immutableCheck;
|
|
397
|
+
middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
|
|
398
|
+
}
|
|
399
|
+
if (serializableCheck) {
|
|
400
|
+
let serializableOptions = {};
|
|
401
|
+
if (!isBoolean(serializableCheck)) serializableOptions = serializableCheck;
|
|
402
|
+
middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
|
|
403
|
+
}
|
|
404
|
+
if (actionCreatorCheck) {
|
|
405
|
+
let actionCreatorOptions = {};
|
|
406
|
+
if (!isBoolean(actionCreatorCheck)) actionCreatorOptions = actionCreatorCheck;
|
|
407
|
+
middlewareArray.unshift(createActionCreatorInvariantMiddleware(actionCreatorOptions));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return middlewareArray;
|
|
491
411
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
[SHOULD_AUTOBATCH]: true
|
|
499
|
-
}
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/autoBatchEnhancer.ts
|
|
414
|
+
const SHOULD_AUTOBATCH = "RTK_autoBatch";
|
|
415
|
+
const prepareAutoBatched = () => (payload) => ({
|
|
416
|
+
payload,
|
|
417
|
+
meta: { [SHOULD_AUTOBATCH]: true }
|
|
500
418
|
});
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
419
|
+
const createQueueWithTimer = (timeout) => {
|
|
420
|
+
return (notify) => {
|
|
421
|
+
setTimeout(notify, timeout);
|
|
422
|
+
};
|
|
505
423
|
};
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
424
|
+
const createRafWithFallbackTimer = (raf, timeout) => {
|
|
425
|
+
return (notify) => {
|
|
426
|
+
let called = false;
|
|
427
|
+
let rafId;
|
|
428
|
+
let timerId;
|
|
429
|
+
const callback = () => {
|
|
430
|
+
if (called) return;
|
|
431
|
+
called = true;
|
|
432
|
+
cancelAnimationFrame(rafId);
|
|
433
|
+
clearTimeout(timerId);
|
|
434
|
+
notify();
|
|
435
|
+
};
|
|
436
|
+
rafId = raf(callback);
|
|
437
|
+
timerId = setTimeout(callback, timeout);
|
|
438
|
+
};
|
|
519
439
|
};
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
queueCallback(notifyListeners);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
return store.dispatch(action);
|
|
565
|
-
} finally {
|
|
566
|
-
notifying = true;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
});
|
|
440
|
+
const autoBatchEnhancer = (options = { type: "raf" }) => (next) => (...args) => {
|
|
441
|
+
const store = next(...args);
|
|
442
|
+
let notifying = true;
|
|
443
|
+
let shouldNotifyAtEndOfTick = false;
|
|
444
|
+
let notificationQueued = false;
|
|
445
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
446
|
+
const queueCallback = options.type === "tick" ? queueMicrotask : options.type === "raf" ? typeof window !== "undefined" && window.requestAnimationFrame ? createRafWithFallbackTimer(window.requestAnimationFrame, 100) : createQueueWithTimer(10) : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
|
|
447
|
+
const notifyListeners = () => {
|
|
448
|
+
notificationQueued = false;
|
|
449
|
+
if (shouldNotifyAtEndOfTick) {
|
|
450
|
+
shouldNotifyAtEndOfTick = false;
|
|
451
|
+
listeners.forEach((l) => l());
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
return Object.assign({}, store, {
|
|
455
|
+
subscribe(listener) {
|
|
456
|
+
const wrappedListener = () => notifying && listener();
|
|
457
|
+
const unsubscribe = store.subscribe(wrappedListener);
|
|
458
|
+
listeners.add(listener);
|
|
459
|
+
return () => {
|
|
460
|
+
unsubscribe();
|
|
461
|
+
listeners.delete(listener);
|
|
462
|
+
};
|
|
463
|
+
},
|
|
464
|
+
dispatch(action) {
|
|
465
|
+
try {
|
|
466
|
+
var _action$meta;
|
|
467
|
+
notifying = !(action === null || action === void 0 || (_action$meta = action.meta) === null || _action$meta === void 0 ? void 0 : _action$meta[SHOULD_AUTOBATCH]);
|
|
468
|
+
shouldNotifyAtEndOfTick = !notifying;
|
|
469
|
+
if (shouldNotifyAtEndOfTick) {
|
|
470
|
+
if (!notificationQueued) {
|
|
471
|
+
notificationQueued = true;
|
|
472
|
+
queueCallback(notifyListeners);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return store.dispatch(action);
|
|
476
|
+
} finally {
|
|
477
|
+
notifying = true;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
});
|
|
570
481
|
};
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (autoBatch) {
|
|
579
|
-
enhancerArray.push(autoBatchEnhancer(typeof autoBatch === "object" ? autoBatch : void 0));
|
|
580
|
-
}
|
|
581
|
-
return enhancerArray;
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/getDefaultEnhancers.ts
|
|
484
|
+
const buildGetDefaultEnhancers = (middlewareEnhancer) => function getDefaultEnhancers(options) {
|
|
485
|
+
const { autoBatch = true } = options !== null && options !== void 0 ? options : {};
|
|
486
|
+
let enhancerArray = new Tuple(middlewareEnhancer);
|
|
487
|
+
if (autoBatch) enhancerArray.push(autoBatchEnhancer(typeof autoBatch === "object" ? autoBatch : void 0));
|
|
488
|
+
return enhancerArray;
|
|
582
489
|
};
|
|
583
|
-
|
|
584
|
-
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/configureStore.ts
|
|
585
492
|
function configureStore(options) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
if (process.env.NODE_ENV !== "production" && duplicateMiddlewareCheck) {
|
|
619
|
-
let middlewareReferences = /* @__PURE__ */ new Set();
|
|
620
|
-
finalMiddleware.forEach((middleware2) => {
|
|
621
|
-
if (middlewareReferences.has(middleware2)) {
|
|
622
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(42) : "Duplicate middleware references found when creating the store. Ensure that each middleware is only included once.");
|
|
623
|
-
}
|
|
624
|
-
middlewareReferences.add(middleware2);
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
let finalCompose = compose;
|
|
628
|
-
if (devTools) {
|
|
629
|
-
finalCompose = composeWithDevTools(__spreadValues({
|
|
630
|
-
// Enable capture of stack traces for dispatched Redux actions
|
|
631
|
-
trace: process.env.NODE_ENV !== "production"
|
|
632
|
-
}, typeof devTools === "object" && devTools));
|
|
633
|
-
}
|
|
634
|
-
const middlewareEnhancer = applyMiddleware(...finalMiddleware);
|
|
635
|
-
const getDefaultEnhancers = buildGetDefaultEnhancers(middlewareEnhancer);
|
|
636
|
-
if (process.env.NODE_ENV !== "production" && enhancers && typeof enhancers !== "function") {
|
|
637
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(5) : "`enhancers` field must be a callback");
|
|
638
|
-
}
|
|
639
|
-
let storeEnhancers = typeof enhancers === "function" ? enhancers(getDefaultEnhancers) : getDefaultEnhancers();
|
|
640
|
-
if (process.env.NODE_ENV !== "production" && !Array.isArray(storeEnhancers)) {
|
|
641
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(6) : "`enhancers` callback must return an array");
|
|
642
|
-
}
|
|
643
|
-
if (process.env.NODE_ENV !== "production" && storeEnhancers.some((item) => typeof item !== "function")) {
|
|
644
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(7) : "each enhancer provided to configureStore must be a function");
|
|
645
|
-
}
|
|
646
|
-
if (process.env.NODE_ENV !== "production" && finalMiddleware.length && !storeEnhancers.includes(middlewareEnhancer)) {
|
|
647
|
-
console.error("middlewares were provided, but middleware enhancer was not included in final enhancers - make sure to call `getDefaultEnhancers`");
|
|
648
|
-
}
|
|
649
|
-
const composedEnhancer = finalCompose(...storeEnhancers);
|
|
650
|
-
return createStore(rootReducer, preloadedState, composedEnhancer);
|
|
493
|
+
const getDefaultMiddleware = buildGetDefaultMiddleware();
|
|
494
|
+
const { reducer = void 0, middleware, devTools = true, duplicateMiddlewareCheck = true, preloadedState = void 0, enhancers = void 0 } = options || {};
|
|
495
|
+
let rootReducer;
|
|
496
|
+
if (typeof reducer === "function") rootReducer = reducer;
|
|
497
|
+
else if (isPlainObject(reducer)) rootReducer = combineReducers$1(reducer);
|
|
498
|
+
else throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(1) : "`reducer` is a required argument, and must be a function or an object of functions that can be passed to combineReducers");
|
|
499
|
+
if (process.env.NODE_ENV !== "production" && middleware && typeof middleware !== "function") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(2) : "`middleware` field must be a callback");
|
|
500
|
+
let finalMiddleware;
|
|
501
|
+
if (typeof middleware === "function") {
|
|
502
|
+
finalMiddleware = middleware(getDefaultMiddleware);
|
|
503
|
+
if (process.env.NODE_ENV !== "production" && !Array.isArray(finalMiddleware)) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(3) : "when using a middleware builder function, an array of middleware must be returned");
|
|
504
|
+
} else finalMiddleware = getDefaultMiddleware();
|
|
505
|
+
if (process.env.NODE_ENV !== "production" && finalMiddleware.some((item) => typeof item !== "function")) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(4) : "each middleware provided to configureStore must be a function");
|
|
506
|
+
if (process.env.NODE_ENV !== "production" && duplicateMiddlewareCheck) {
|
|
507
|
+
let middlewareReferences = /* @__PURE__ */ new Set();
|
|
508
|
+
finalMiddleware.forEach((middleware) => {
|
|
509
|
+
if (middlewareReferences.has(middleware)) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(42) : "Duplicate middleware references found when creating the store. Ensure that each middleware is only included once.");
|
|
510
|
+
middlewareReferences.add(middleware);
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
let finalCompose = compose;
|
|
514
|
+
if (devTools) finalCompose = composeWithDevTools(_objectSpread2({ trace: process.env.NODE_ENV !== "production" }, typeof devTools === "object" && devTools));
|
|
515
|
+
const middlewareEnhancer = applyMiddleware(...finalMiddleware);
|
|
516
|
+
const getDefaultEnhancers = buildGetDefaultEnhancers(middlewareEnhancer);
|
|
517
|
+
if (process.env.NODE_ENV !== "production" && enhancers && typeof enhancers !== "function") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(5) : "`enhancers` field must be a callback");
|
|
518
|
+
let storeEnhancers = typeof enhancers === "function" ? enhancers(getDefaultEnhancers) : getDefaultEnhancers();
|
|
519
|
+
if (process.env.NODE_ENV !== "production" && !Array.isArray(storeEnhancers)) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(6) : "`enhancers` callback must return an array");
|
|
520
|
+
if (process.env.NODE_ENV !== "production" && storeEnhancers.some((item) => typeof item !== "function")) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(7) : "each enhancer provided to configureStore must be a function");
|
|
521
|
+
if (process.env.NODE_ENV !== "production" && finalMiddleware.length && !storeEnhancers.includes(middlewareEnhancer)) console.error("middlewares were provided, but middleware enhancer was not included in final enhancers - make sure to call `getDefaultEnhancers`");
|
|
522
|
+
const composedEnhancer = finalCompose(...storeEnhancers);
|
|
523
|
+
return createStore(rootReducer, preloadedState, composedEnhancer);
|
|
651
524
|
}
|
|
652
|
-
|
|
653
|
-
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/mapBuilders.ts
|
|
654
527
|
function executeReducerBuilderCallback(builderCallback) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (defaultCaseReducer) {
|
|
708
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
defaultCaseReducer = reducer;
|
|
712
|
-
return builder;
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
builderCallback(builder);
|
|
716
|
-
return [actionsMap, actionMatchers, defaultCaseReducer];
|
|
528
|
+
const actionsMap = {};
|
|
529
|
+
const actionMatchers = [];
|
|
530
|
+
let defaultCaseReducer;
|
|
531
|
+
const builder = {
|
|
532
|
+
addCase(typeOrActionCreator, reducer) {
|
|
533
|
+
if (process.env.NODE_ENV !== "production") {
|
|
534
|
+
if (actionMatchers.length > 0) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(26) : "`builder.addCase` should only be called before calling `builder.addMatcher`");
|
|
535
|
+
if (defaultCaseReducer) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(27) : "`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
|
536
|
+
}
|
|
537
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
538
|
+
if (!type) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(28) : "`builder.addCase` cannot be called with an empty action type");
|
|
539
|
+
if (type in actionsMap) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(29) : `\`builder.addCase\` cannot be called with two reducers for the same action type '${type}'`);
|
|
540
|
+
actionsMap[type] = reducer;
|
|
541
|
+
return builder;
|
|
542
|
+
},
|
|
543
|
+
addAsyncThunk(asyncThunk, reducers) {
|
|
544
|
+
if (process.env.NODE_ENV !== "production") {
|
|
545
|
+
if (defaultCaseReducer) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
|
|
546
|
+
}
|
|
547
|
+
if (reducers.pending) actionsMap[asyncThunk.pending.type] = reducers.pending;
|
|
548
|
+
if (reducers.rejected) actionsMap[asyncThunk.rejected.type] = reducers.rejected;
|
|
549
|
+
if (reducers.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers.fulfilled;
|
|
550
|
+
if (reducers.settled) actionMatchers.push({
|
|
551
|
+
matcher: asyncThunk.settled,
|
|
552
|
+
reducer: reducers.settled
|
|
553
|
+
});
|
|
554
|
+
return builder;
|
|
555
|
+
},
|
|
556
|
+
addMatcher(matcher, reducer) {
|
|
557
|
+
if (process.env.NODE_ENV !== "production") {
|
|
558
|
+
if (defaultCaseReducer) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(30) : "`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
|
559
|
+
}
|
|
560
|
+
actionMatchers.push({
|
|
561
|
+
matcher,
|
|
562
|
+
reducer
|
|
563
|
+
});
|
|
564
|
+
return builder;
|
|
565
|
+
},
|
|
566
|
+
addDefaultCase(reducer) {
|
|
567
|
+
if (process.env.NODE_ENV !== "production") {
|
|
568
|
+
if (defaultCaseReducer) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
|
569
|
+
}
|
|
570
|
+
defaultCaseReducer = reducer;
|
|
571
|
+
return builder;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
builderCallback(builder);
|
|
575
|
+
return [
|
|
576
|
+
actionsMap,
|
|
577
|
+
actionMatchers,
|
|
578
|
+
defaultCaseReducer
|
|
579
|
+
];
|
|
717
580
|
}
|
|
718
|
-
|
|
719
|
-
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region src/createReducer.ts
|
|
720
583
|
function isStateFunction(x) {
|
|
721
|
-
|
|
584
|
+
return typeof x === "function";
|
|
722
585
|
}
|
|
723
586
|
function createReducer(initialState, mapOrBuilderCallback) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return previousState;
|
|
760
|
-
}
|
|
761
|
-
throw Error("A case reducer on a non-draftable value must not return undefined");
|
|
762
|
-
}
|
|
763
|
-
return result;
|
|
764
|
-
} else {
|
|
765
|
-
return produce(previousState, (draft) => {
|
|
766
|
-
return caseReducer(draft, action);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
return previousState;
|
|
771
|
-
}, state);
|
|
772
|
-
}
|
|
773
|
-
reducer.getInitialState = getInitialState;
|
|
774
|
-
return reducer;
|
|
587
|
+
if (process.env.NODE_ENV !== "production") {
|
|
588
|
+
if (typeof mapOrBuilderCallback === "object") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
589
|
+
}
|
|
590
|
+
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
591
|
+
let getInitialState;
|
|
592
|
+
if (isStateFunction(initialState)) getInitialState = () => freezeDraftable(initialState());
|
|
593
|
+
else {
|
|
594
|
+
const frozenInitialState = freezeDraftable(initialState);
|
|
595
|
+
getInitialState = () => frozenInitialState;
|
|
596
|
+
}
|
|
597
|
+
function reducer(state = getInitialState(), action) {
|
|
598
|
+
let caseReducers = [actionsMap[action.type], ...finalActionMatchers.filter(({ matcher }) => matcher(action)).map(({ reducer }) => reducer)];
|
|
599
|
+
if (caseReducers.filter((cr) => !!cr).length === 0) caseReducers = [finalDefaultCaseReducer];
|
|
600
|
+
return caseReducers.reduce((previousState, caseReducer) => {
|
|
601
|
+
if (caseReducer) {
|
|
602
|
+
if (isDraft(previousState)) {
|
|
603
|
+
const result = caseReducer(previousState, action);
|
|
604
|
+
if (result === void 0) return previousState;
|
|
605
|
+
return result;
|
|
606
|
+
} else if (!isDraftable(previousState)) {
|
|
607
|
+
const result = caseReducer(previousState, action);
|
|
608
|
+
if (result === void 0) {
|
|
609
|
+
if (previousState === null) return previousState;
|
|
610
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(9) : "A case reducer on a non-draftable value must not return undefined");
|
|
611
|
+
}
|
|
612
|
+
return result;
|
|
613
|
+
} else return createNextState(previousState, (draft) => {
|
|
614
|
+
return caseReducer(draft, action);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
return previousState;
|
|
618
|
+
}, state);
|
|
619
|
+
}
|
|
620
|
+
reducer.getInitialState = getInitialState;
|
|
621
|
+
return reducer;
|
|
775
622
|
}
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
} else {
|
|
782
|
-
return matcher(action);
|
|
783
|
-
}
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region src/matchers.ts
|
|
625
|
+
const matches = (matcher, action) => {
|
|
626
|
+
if (hasMatchFunction(matcher)) return matcher.match(action);
|
|
627
|
+
else return matcher(action);
|
|
784
628
|
};
|
|
785
629
|
function isAnyOf(...matchers) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
630
|
+
return (action) => {
|
|
631
|
+
return matchers.some((matcher) => matches(matcher, action));
|
|
632
|
+
};
|
|
789
633
|
}
|
|
790
634
|
function isAllOf(...matchers) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
635
|
+
return (action) => {
|
|
636
|
+
return matchers.every((matcher) => matches(matcher, action));
|
|
637
|
+
};
|
|
794
638
|
}
|
|
795
639
|
function hasExpectedRequestMetadata(action, validStatus) {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
640
|
+
if (!action || !action.meta) return false;
|
|
641
|
+
const hasValidRequestId = typeof action.meta.requestId === "string";
|
|
642
|
+
const hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
|
|
643
|
+
return hasValidRequestId && hasValidRequestStatus;
|
|
800
644
|
}
|
|
801
645
|
function isAsyncThunkArray(a) {
|
|
802
|
-
|
|
646
|
+
return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
|
|
803
647
|
}
|
|
804
648
|
function isPending(...asyncThunks) {
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (!isAsyncThunkArray(asyncThunks)) {
|
|
809
|
-
return isPending()(asyncThunks[0]);
|
|
810
|
-
}
|
|
811
|
-
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.pending));
|
|
649
|
+
if (asyncThunks.length === 0) return (action) => hasExpectedRequestMetadata(action, ["pending"]);
|
|
650
|
+
if (!isAsyncThunkArray(asyncThunks)) return isPending()(asyncThunks[0]);
|
|
651
|
+
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.pending));
|
|
812
652
|
}
|
|
813
653
|
function isRejected(...asyncThunks) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (!isAsyncThunkArray(asyncThunks)) {
|
|
818
|
-
return isRejected()(asyncThunks[0]);
|
|
819
|
-
}
|
|
820
|
-
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.rejected));
|
|
654
|
+
if (asyncThunks.length === 0) return (action) => hasExpectedRequestMetadata(action, ["rejected"]);
|
|
655
|
+
if (!isAsyncThunkArray(asyncThunks)) return isRejected()(asyncThunks[0]);
|
|
656
|
+
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.rejected));
|
|
821
657
|
}
|
|
822
658
|
function isRejectedWithValue(...asyncThunks) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (!isAsyncThunkArray(asyncThunks)) {
|
|
830
|
-
return isRejectedWithValue()(asyncThunks[0]);
|
|
831
|
-
}
|
|
832
|
-
return isAllOf(isRejected(...asyncThunks), hasFlag);
|
|
659
|
+
const hasFlag = (action) => {
|
|
660
|
+
return action && action.meta && action.meta.rejectedWithValue;
|
|
661
|
+
};
|
|
662
|
+
if (asyncThunks.length === 0) return isAllOf(isRejected(...asyncThunks), hasFlag);
|
|
663
|
+
if (!isAsyncThunkArray(asyncThunks)) return isRejectedWithValue()(asyncThunks[0]);
|
|
664
|
+
return isAllOf(isRejected(...asyncThunks), hasFlag);
|
|
833
665
|
}
|
|
834
666
|
function isFulfilled(...asyncThunks) {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
if (!isAsyncThunkArray(asyncThunks)) {
|
|
839
|
-
return isFulfilled()(asyncThunks[0]);
|
|
840
|
-
}
|
|
841
|
-
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.fulfilled));
|
|
667
|
+
if (asyncThunks.length === 0) return (action) => hasExpectedRequestMetadata(action, ["fulfilled"]);
|
|
668
|
+
if (!isAsyncThunkArray(asyncThunks)) return isFulfilled()(asyncThunks[0]);
|
|
669
|
+
return isAnyOf(...asyncThunks.map((asyncThunk) => asyncThunk.fulfilled));
|
|
842
670
|
}
|
|
843
671
|
function isAsyncThunkAction(...asyncThunks) {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
672
|
+
if (asyncThunks.length === 0) return (action) => hasExpectedRequestMetadata(action, [
|
|
673
|
+
"pending",
|
|
674
|
+
"fulfilled",
|
|
675
|
+
"rejected"
|
|
676
|
+
]);
|
|
677
|
+
if (!isAsyncThunkArray(asyncThunks)) return isAsyncThunkAction()(asyncThunks[0]);
|
|
678
|
+
return isAnyOf(...asyncThunks.flatMap((asyncThunk) => [
|
|
679
|
+
asyncThunk.pending,
|
|
680
|
+
asyncThunk.rejected,
|
|
681
|
+
asyncThunk.fulfilled
|
|
682
|
+
]));
|
|
851
683
|
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
return id;
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/nanoid.ts
|
|
686
|
+
let urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
|
687
|
+
let nanoid = (size = 21) => {
|
|
688
|
+
let id = "";
|
|
689
|
+
let i = size;
|
|
690
|
+
while (i--) id += urlAlphabet[Math.random() * 64 | 0];
|
|
691
|
+
return id;
|
|
862
692
|
};
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
693
|
+
//#endregion
|
|
694
|
+
//#region src/createAsyncThunk.ts
|
|
695
|
+
const commonProperties = [
|
|
696
|
+
"name",
|
|
697
|
+
"message",
|
|
698
|
+
"stack",
|
|
699
|
+
"code"
|
|
700
|
+
];
|
|
866
701
|
var RejectWithValue = class {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
does not exist at runtime
|
|
873
|
-
*/
|
|
874
|
-
__publicField(this, "_type");
|
|
875
|
-
}
|
|
702
|
+
constructor(payload, meta) {
|
|
703
|
+
this.payload = payload;
|
|
704
|
+
this.meta = meta;
|
|
705
|
+
_defineProperty(this, "_type", void 0);
|
|
706
|
+
}
|
|
876
707
|
};
|
|
877
708
|
var FulfillWithMeta = class {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
does not exist at runtime
|
|
884
|
-
*/
|
|
885
|
-
__publicField(this, "_type");
|
|
886
|
-
}
|
|
709
|
+
constructor(payload, meta) {
|
|
710
|
+
this.payload = payload;
|
|
711
|
+
this.meta = meta;
|
|
712
|
+
_defineProperty(this, "_type", void 0);
|
|
713
|
+
}
|
|
887
714
|
};
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
}
|
|
896
|
-
return simpleError;
|
|
897
|
-
}
|
|
898
|
-
return {
|
|
899
|
-
message: String(value)
|
|
900
|
-
};
|
|
715
|
+
const miniSerializeError = (value) => {
|
|
716
|
+
if (typeof value === "object" && value !== null) {
|
|
717
|
+
const simpleError = {};
|
|
718
|
+
for (const property of commonProperties) if (typeof value[property] === "string") simpleError[property] = value[property];
|
|
719
|
+
return simpleError;
|
|
720
|
+
}
|
|
721
|
+
return { message: String(value) };
|
|
901
722
|
};
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
requestId,
|
|
1027
|
-
arg,
|
|
1028
|
-
unwrap() {
|
|
1029
|
-
return promise.then(unwrapResult);
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
return Object.assign(actionCreator, {
|
|
1035
|
-
pending,
|
|
1036
|
-
rejected,
|
|
1037
|
-
fulfilled,
|
|
1038
|
-
settled: isAnyOf(rejected, fulfilled),
|
|
1039
|
-
typePrefix
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
createAsyncThunk2.withTypes = () => createAsyncThunk2;
|
|
1043
|
-
return createAsyncThunk2;
|
|
723
|
+
const externalAbortMessage = "External signal was aborted";
|
|
724
|
+
const createAsyncThunk = /* @__PURE__ */ (() => {
|
|
725
|
+
function createAsyncThunk(typePrefix, payloadCreator, options) {
|
|
726
|
+
const fulfilled = createAction(typePrefix + "/fulfilled", (payload, requestId, arg, meta) => ({
|
|
727
|
+
payload,
|
|
728
|
+
meta: _objectSpread2(_objectSpread2({}, meta || {}), {}, {
|
|
729
|
+
arg,
|
|
730
|
+
requestId,
|
|
731
|
+
requestStatus: "fulfilled"
|
|
732
|
+
})
|
|
733
|
+
}));
|
|
734
|
+
const pending = createAction(typePrefix + "/pending", (requestId, arg, meta) => ({
|
|
735
|
+
payload: void 0,
|
|
736
|
+
meta: _objectSpread2(_objectSpread2({}, meta || {}), {}, {
|
|
737
|
+
arg,
|
|
738
|
+
requestId,
|
|
739
|
+
requestStatus: "pending"
|
|
740
|
+
})
|
|
741
|
+
}));
|
|
742
|
+
const rejected = createAction(typePrefix + "/rejected", (error, requestId, arg, payload, meta) => ({
|
|
743
|
+
payload,
|
|
744
|
+
error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
|
745
|
+
meta: _objectSpread2(_objectSpread2({}, meta || {}), {}, {
|
|
746
|
+
arg,
|
|
747
|
+
requestId,
|
|
748
|
+
rejectedWithValue: payload !== void 0,
|
|
749
|
+
requestStatus: "rejected",
|
|
750
|
+
aborted: (error === null || error === void 0 ? void 0 : error.name) === "AbortError",
|
|
751
|
+
condition: (error === null || error === void 0 ? void 0 : error.name) === "ConditionError"
|
|
752
|
+
})
|
|
753
|
+
}));
|
|
754
|
+
function actionCreator(arg, { signal } = {}) {
|
|
755
|
+
return (dispatch, getState, extra) => {
|
|
756
|
+
const requestId = (options === null || options === void 0 ? void 0 : options.idGenerator) ? options.idGenerator(arg) : nanoid();
|
|
757
|
+
const abortController = new AbortController();
|
|
758
|
+
let abortHandler;
|
|
759
|
+
let abortReason;
|
|
760
|
+
function abort(reason) {
|
|
761
|
+
abortReason = reason;
|
|
762
|
+
abortController.abort();
|
|
763
|
+
}
|
|
764
|
+
if (signal) {
|
|
765
|
+
if (signal.aborted) abort(externalAbortMessage);
|
|
766
|
+
else signal.addEventListener("abort", () => abort(externalAbortMessage), { once: true });
|
|
767
|
+
}
|
|
768
|
+
const promise = async function() {
|
|
769
|
+
let finalAction;
|
|
770
|
+
try {
|
|
771
|
+
var _options$condition, _options$getPendingMe;
|
|
772
|
+
let conditionResult = options === null || options === void 0 || (_options$condition = options.condition) === null || _options$condition === void 0 ? void 0 : _options$condition.call(options, arg, {
|
|
773
|
+
getState,
|
|
774
|
+
extra
|
|
775
|
+
});
|
|
776
|
+
if (isThenable(conditionResult)) conditionResult = await conditionResult;
|
|
777
|
+
if (conditionResult === false) throw {
|
|
778
|
+
name: "ConditionError",
|
|
779
|
+
message: "Aborted due to condition callback returning false."
|
|
780
|
+
};
|
|
781
|
+
if (abortController.signal.aborted) throw {
|
|
782
|
+
name: "AbortError",
|
|
783
|
+
message: abortReason || "Aborted"
|
|
784
|
+
};
|
|
785
|
+
const abortedPromise = new Promise((_, reject) => {
|
|
786
|
+
abortHandler = () => {
|
|
787
|
+
reject({
|
|
788
|
+
name: "AbortError",
|
|
789
|
+
message: abortReason || "Aborted"
|
|
790
|
+
});
|
|
791
|
+
};
|
|
792
|
+
abortController.signal.addEventListener("abort", abortHandler, { once: true });
|
|
793
|
+
});
|
|
794
|
+
dispatch(pending(requestId, arg, options === null || options === void 0 || (_options$getPendingMe = options.getPendingMeta) === null || _options$getPendingMe === void 0 ? void 0 : _options$getPendingMe.call(options, {
|
|
795
|
+
requestId,
|
|
796
|
+
arg
|
|
797
|
+
}, {
|
|
798
|
+
getState,
|
|
799
|
+
extra
|
|
800
|
+
})));
|
|
801
|
+
finalAction = await Promise.race([abortedPromise, Promise.resolve(payloadCreator(arg, {
|
|
802
|
+
dispatch,
|
|
803
|
+
getState,
|
|
804
|
+
extra,
|
|
805
|
+
requestId,
|
|
806
|
+
signal: abortController.signal,
|
|
807
|
+
abort,
|
|
808
|
+
rejectWithValue: ((value, meta) => {
|
|
809
|
+
return new RejectWithValue(value, meta);
|
|
810
|
+
}),
|
|
811
|
+
fulfillWithValue: ((value, meta) => {
|
|
812
|
+
return new FulfillWithMeta(value, meta);
|
|
813
|
+
})
|
|
814
|
+
})).then((result) => {
|
|
815
|
+
if (result instanceof RejectWithValue) throw result;
|
|
816
|
+
if (result instanceof FulfillWithMeta) return fulfilled(result.payload, requestId, arg, result.meta);
|
|
817
|
+
return fulfilled(result, requestId, arg);
|
|
818
|
+
})]);
|
|
819
|
+
} catch (err) {
|
|
820
|
+
finalAction = err instanceof RejectWithValue ? rejected(null, requestId, arg, err.payload, err.meta) : rejected(err, requestId, arg);
|
|
821
|
+
} finally {
|
|
822
|
+
if (abortHandler) abortController.signal.removeEventListener("abort", abortHandler);
|
|
823
|
+
}
|
|
824
|
+
if (!(options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition)) dispatch(finalAction);
|
|
825
|
+
return finalAction;
|
|
826
|
+
}();
|
|
827
|
+
return Object.assign(promise, {
|
|
828
|
+
abort,
|
|
829
|
+
requestId,
|
|
830
|
+
arg,
|
|
831
|
+
unwrap() {
|
|
832
|
+
return promise.then(unwrapResult);
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
return Object.assign(actionCreator, {
|
|
838
|
+
pending,
|
|
839
|
+
rejected,
|
|
840
|
+
fulfilled,
|
|
841
|
+
settled: isAnyOf(rejected, fulfilled),
|
|
842
|
+
typePrefix
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
createAsyncThunk.withTypes = () => createAsyncThunk;
|
|
846
|
+
return createAsyncThunk;
|
|
1044
847
|
})();
|
|
1045
848
|
function unwrapResult(action) {
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
if (action.error) {
|
|
1050
|
-
throw action.error;
|
|
1051
|
-
}
|
|
1052
|
-
return action.payload;
|
|
849
|
+
if (action.meta && action.meta.rejectedWithValue) throw action.payload;
|
|
850
|
+
if (action.error) throw action.error;
|
|
851
|
+
return action.payload;
|
|
1053
852
|
}
|
|
1054
853
|
function isThenable(value) {
|
|
1055
|
-
|
|
854
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
1056
855
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
858
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
859
|
+
if (null == r) return {};
|
|
860
|
+
var t = {};
|
|
861
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
862
|
+
if (e.includes(n)) continue;
|
|
863
|
+
t[n] = r[n];
|
|
864
|
+
}
|
|
865
|
+
return t;
|
|
866
|
+
}
|
|
867
|
+
//#endregion
|
|
868
|
+
//#region \0@oxc-project+runtime@0.144.0/helpers/esm/objectWithoutProperties.js
|
|
869
|
+
function _objectWithoutProperties(e, t) {
|
|
870
|
+
if (null == e) return {};
|
|
871
|
+
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
872
|
+
if (Object.getOwnPropertySymbols) {
|
|
873
|
+
var s = Object.getOwnPropertySymbols(e);
|
|
874
|
+
for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
875
|
+
}
|
|
876
|
+
return i;
|
|
877
|
+
}
|
|
878
|
+
//#endregion
|
|
879
|
+
//#region src/createSlice.ts
|
|
880
|
+
const _excluded = ["reducerPath"];
|
|
881
|
+
const asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
882
|
+
const asyncThunkCreator = { [asyncThunkSymbol]: createAsyncThunk };
|
|
883
|
+
let ReducerType = /* @__PURE__ */ function(ReducerType) {
|
|
884
|
+
ReducerType["reducer"] = "reducer";
|
|
885
|
+
ReducerType["reducerWithPrepare"] = "reducerWithPrepare";
|
|
886
|
+
ReducerType["asyncThunk"] = "asyncThunk";
|
|
887
|
+
return ReducerType;
|
|
888
|
+
}({});
|
|
1069
889
|
function getType(slice, actionKey) {
|
|
1070
|
-
|
|
1071
|
-
}
|
|
1072
|
-
function buildCreateSlice({
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
for (const [name2, selector] of Object.entries((_a2 = options.selectors) != null ? _a2 : {})) {
|
|
1192
|
-
map[name2] = wrapSelector(selector, selectState, () => getOrInsertComputed(injectedStateCache, selectState, getInitialState), injected);
|
|
1193
|
-
}
|
|
1194
|
-
return map;
|
|
1195
|
-
});
|
|
1196
|
-
}
|
|
1197
|
-
return {
|
|
1198
|
-
reducerPath: reducerPath2,
|
|
1199
|
-
getSelectors,
|
|
1200
|
-
get selectors() {
|
|
1201
|
-
return getSelectors(selectSlice);
|
|
1202
|
-
},
|
|
1203
|
-
selectSlice
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
const slice = __spreadProps(__spreadValues({
|
|
1207
|
-
name,
|
|
1208
|
-
reducer,
|
|
1209
|
-
actions: context.actionCreators,
|
|
1210
|
-
caseReducers: context.sliceCaseReducersByName,
|
|
1211
|
-
getInitialState
|
|
1212
|
-
}, makeSelectorProps(reducerPath)), {
|
|
1213
|
-
injectInto(injectable, _a2 = {}) {
|
|
1214
|
-
var _b = _a2, {
|
|
1215
|
-
reducerPath: pathOpt
|
|
1216
|
-
} = _b, config = __objRest(_b, [
|
|
1217
|
-
"reducerPath"
|
|
1218
|
-
]);
|
|
1219
|
-
const newReducerPath = pathOpt != null ? pathOpt : reducerPath;
|
|
1220
|
-
injectable.inject({
|
|
1221
|
-
reducerPath: newReducerPath,
|
|
1222
|
-
reducer
|
|
1223
|
-
}, config);
|
|
1224
|
-
return __spreadValues(__spreadValues({}, slice), makeSelectorProps(newReducerPath, true));
|
|
1225
|
-
}
|
|
1226
|
-
});
|
|
1227
|
-
return slice;
|
|
1228
|
-
};
|
|
890
|
+
return `${slice}/${actionKey}`;
|
|
891
|
+
}
|
|
892
|
+
function buildCreateSlice({ creators } = {}) {
|
|
893
|
+
var _creators$asyncThunk;
|
|
894
|
+
const cAT = creators === null || creators === void 0 || (_creators$asyncThunk = creators.asyncThunk) === null || _creators$asyncThunk === void 0 ? void 0 : _creators$asyncThunk[asyncThunkSymbol];
|
|
895
|
+
return function createSlice(options) {
|
|
896
|
+
const { name, reducerPath = name } = options;
|
|
897
|
+
if (!name) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "`name` is a required option for createSlice");
|
|
898
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
899
|
+
if (options.initialState === void 0) console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
900
|
+
}
|
|
901
|
+
const reducers = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
902
|
+
const reducerNames = Object.keys(reducers);
|
|
903
|
+
const context = {
|
|
904
|
+
sliceCaseReducersByName: {},
|
|
905
|
+
sliceCaseReducersByType: {},
|
|
906
|
+
actionCreators: {},
|
|
907
|
+
sliceMatchers: []
|
|
908
|
+
};
|
|
909
|
+
const contextMethods = {
|
|
910
|
+
addCase(typeOrActionCreator, reducer) {
|
|
911
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
912
|
+
if (!type) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : "`context.addCase` cannot be called with an empty action type");
|
|
913
|
+
if (type in context.sliceCaseReducersByType) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : "`context.addCase` cannot be called with two reducers for the same action type: " + type);
|
|
914
|
+
context.sliceCaseReducersByType[type] = reducer;
|
|
915
|
+
return contextMethods;
|
|
916
|
+
},
|
|
917
|
+
addMatcher(matcher, reducer) {
|
|
918
|
+
context.sliceMatchers.push({
|
|
919
|
+
matcher,
|
|
920
|
+
reducer
|
|
921
|
+
});
|
|
922
|
+
return contextMethods;
|
|
923
|
+
},
|
|
924
|
+
exposeAction(name, actionCreator) {
|
|
925
|
+
context.actionCreators[name] = actionCreator;
|
|
926
|
+
return contextMethods;
|
|
927
|
+
},
|
|
928
|
+
exposeCaseReducer(name, reducer) {
|
|
929
|
+
context.sliceCaseReducersByName[name] = reducer;
|
|
930
|
+
return contextMethods;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
reducerNames.forEach((reducerName) => {
|
|
934
|
+
const reducerDefinition = reducers[reducerName];
|
|
935
|
+
const reducerDetails = {
|
|
936
|
+
reducerName,
|
|
937
|
+
type: getType(name, reducerName),
|
|
938
|
+
createNotation: typeof options.reducers === "function"
|
|
939
|
+
};
|
|
940
|
+
if (isAsyncThunkSliceReducerDefinition(reducerDefinition)) handleThunkCaseReducerDefinition(reducerDetails, reducerDefinition, contextMethods, cAT);
|
|
941
|
+
else handleNormalReducerDefinition(reducerDetails, reducerDefinition, contextMethods);
|
|
942
|
+
});
|
|
943
|
+
function buildReducer() {
|
|
944
|
+
if (process.env.NODE_ENV !== "production") {
|
|
945
|
+
if (typeof options.extraReducers === "object") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : "The object notation for `createSlice.extraReducers` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
|
946
|
+
}
|
|
947
|
+
const [extraReducers = {}, actionMatchers = [], defaultCaseReducer = void 0] = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers];
|
|
948
|
+
const finalCaseReducers = _objectSpread2(_objectSpread2({}, extraReducers), context.sliceCaseReducersByType);
|
|
949
|
+
return createReducer(options.initialState, (builder) => {
|
|
950
|
+
for (let key in finalCaseReducers) builder.addCase(key, finalCaseReducers[key]);
|
|
951
|
+
for (let sM of context.sliceMatchers) builder.addMatcher(sM.matcher, sM.reducer);
|
|
952
|
+
for (let m of actionMatchers) builder.addMatcher(m.matcher, m.reducer);
|
|
953
|
+
if (defaultCaseReducer) builder.addDefaultCase(defaultCaseReducer);
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
const selectSelf = (state) => state;
|
|
957
|
+
const injectedSelectorCache = /* @__PURE__ */ new Map();
|
|
958
|
+
const injectedStateCache = /* @__PURE__ */ new WeakMap();
|
|
959
|
+
let _reducer;
|
|
960
|
+
function reducer(state, action) {
|
|
961
|
+
if (!_reducer) _reducer = buildReducer();
|
|
962
|
+
return _reducer(state, action);
|
|
963
|
+
}
|
|
964
|
+
function getInitialState() {
|
|
965
|
+
if (!_reducer) _reducer = buildReducer();
|
|
966
|
+
return _reducer.getInitialState();
|
|
967
|
+
}
|
|
968
|
+
function makeSelectorProps(reducerPath, injected = false) {
|
|
969
|
+
function selectSlice(state) {
|
|
970
|
+
let sliceState = state[reducerPath];
|
|
971
|
+
if (typeof sliceState === "undefined") {
|
|
972
|
+
if (injected) sliceState = getOrInsertComputed(injectedStateCache, selectSlice, getInitialState);
|
|
973
|
+
else if (process.env.NODE_ENV !== "production") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "selectSlice returned undefined for an uninjected slice reducer");
|
|
974
|
+
}
|
|
975
|
+
return sliceState;
|
|
976
|
+
}
|
|
977
|
+
function getSelectors(selectState = selectSelf) {
|
|
978
|
+
return getOrInsertComputed(getOrInsertComputed(injectedSelectorCache, injected, () => /* @__PURE__ */ new WeakMap()), selectState, () => {
|
|
979
|
+
var _options$selectors;
|
|
980
|
+
const map = {};
|
|
981
|
+
for (const [name, selector] of Object.entries((_options$selectors = options.selectors) !== null && _options$selectors !== void 0 ? _options$selectors : {})) map[name] = wrapSelector(selector, selectState, () => getOrInsertComputed(injectedStateCache, selectState, getInitialState), injected);
|
|
982
|
+
return map;
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
return {
|
|
986
|
+
reducerPath,
|
|
987
|
+
getSelectors,
|
|
988
|
+
get selectors() {
|
|
989
|
+
return getSelectors(selectSlice);
|
|
990
|
+
},
|
|
991
|
+
selectSlice
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
const slice = _objectSpread2(_objectSpread2({
|
|
995
|
+
name,
|
|
996
|
+
reducer,
|
|
997
|
+
actions: context.actionCreators,
|
|
998
|
+
caseReducers: context.sliceCaseReducersByName,
|
|
999
|
+
getInitialState
|
|
1000
|
+
}, makeSelectorProps(reducerPath)), {}, { injectInto(injectable, _ref = {}) {
|
|
1001
|
+
let { reducerPath: pathOpt } = _ref, config = _objectWithoutProperties(_ref, _excluded);
|
|
1002
|
+
const newReducerPath = pathOpt !== null && pathOpt !== void 0 ? pathOpt : reducerPath;
|
|
1003
|
+
injectable.inject({
|
|
1004
|
+
reducerPath: newReducerPath,
|
|
1005
|
+
reducer
|
|
1006
|
+
}, config);
|
|
1007
|
+
return _objectSpread2(_objectSpread2({}, slice), makeSelectorProps(newReducerPath, true));
|
|
1008
|
+
} });
|
|
1009
|
+
return slice;
|
|
1010
|
+
};
|
|
1229
1011
|
}
|
|
1230
1012
|
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
return wrapper;
|
|
1244
|
-
}
|
|
1245
|
-
var createSlice = /* @__PURE__ */ buildCreateSlice();
|
|
1013
|
+
function wrapper(rootState, ...args) {
|
|
1014
|
+
let sliceState = selectState(rootState);
|
|
1015
|
+
if (typeof sliceState === "undefined") {
|
|
1016
|
+
if (injected) sliceState = getInitialState();
|
|
1017
|
+
else if (process.env.NODE_ENV !== "production") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : "selectState returned undefined for an uninjected slice reducer");
|
|
1018
|
+
}
|
|
1019
|
+
return selector(sliceState, ...args);
|
|
1020
|
+
}
|
|
1021
|
+
wrapper.unwrapped = selector;
|
|
1022
|
+
return wrapper;
|
|
1023
|
+
}
|
|
1024
|
+
const createSlice = /* @__PURE__ */ buildCreateSlice();
|
|
1246
1025
|
function buildReducerCreators() {
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
createNotation
|
|
1280
|
-
}, maybeReducerWithPrepare, context) {
|
|
1281
|
-
let caseReducer;
|
|
1282
|
-
let prepareCallback;
|
|
1283
|
-
if ("reducer" in maybeReducerWithPrepare) {
|
|
1284
|
-
if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) {
|
|
1285
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
|
1286
|
-
}
|
|
1287
|
-
caseReducer = maybeReducerWithPrepare.reducer;
|
|
1288
|
-
prepareCallback = maybeReducerWithPrepare.prepare;
|
|
1289
|
-
} else {
|
|
1290
|
-
caseReducer = maybeReducerWithPrepare;
|
|
1291
|
-
}
|
|
1292
|
-
context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
|
1026
|
+
function asyncThunk(payloadCreator, config) {
|
|
1027
|
+
return _objectSpread2({
|
|
1028
|
+
_reducerDefinitionType: "asyncThunk",
|
|
1029
|
+
payloadCreator
|
|
1030
|
+
}, config);
|
|
1031
|
+
}
|
|
1032
|
+
asyncThunk.withTypes = () => asyncThunk;
|
|
1033
|
+
return {
|
|
1034
|
+
reducer(caseReducer) {
|
|
1035
|
+
return Object.assign({ [caseReducer.name](...args) {
|
|
1036
|
+
return caseReducer(...args);
|
|
1037
|
+
} }[caseReducer.name], { _reducerDefinitionType: "reducer" });
|
|
1038
|
+
},
|
|
1039
|
+
preparedReducer(prepare, reducer) {
|
|
1040
|
+
return {
|
|
1041
|
+
_reducerDefinitionType: "reducerWithPrepare",
|
|
1042
|
+
prepare,
|
|
1043
|
+
reducer
|
|
1044
|
+
};
|
|
1045
|
+
},
|
|
1046
|
+
asyncThunk
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function handleNormalReducerDefinition({ type, reducerName, createNotation }, maybeReducerWithPrepare, context) {
|
|
1050
|
+
let caseReducer;
|
|
1051
|
+
let prepareCallback;
|
|
1052
|
+
if ("reducer" in maybeReducerWithPrepare) {
|
|
1053
|
+
if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
|
1054
|
+
caseReducer = maybeReducerWithPrepare.reducer;
|
|
1055
|
+
prepareCallback = maybeReducerWithPrepare.prepare;
|
|
1056
|
+
} else caseReducer = maybeReducerWithPrepare;
|
|
1057
|
+
context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
|
1293
1058
|
}
|
|
1294
1059
|
function isAsyncThunkSliceReducerDefinition(reducerDefinition) {
|
|
1295
|
-
|
|
1060
|
+
return reducerDefinition._reducerDefinitionType === "asyncThunk";
|
|
1296
1061
|
}
|
|
1297
1062
|
function isCaseReducerWithPrepareDefinition(reducerDefinition) {
|
|
1298
|
-
|
|
1299
|
-
}
|
|
1300
|
-
function handleThunkCaseReducerDefinition({
|
|
1301
|
-
type,
|
|
1302
|
-
reducerName
|
|
1303
|
-
}, reducerDefinition, context, cAT) {
|
|
1304
|
-
if (!cAT) {
|
|
1305
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
|
1306
|
-
}
|
|
1307
|
-
const {
|
|
1308
|
-
payloadCreator,
|
|
1309
|
-
fulfilled,
|
|
1310
|
-
pending,
|
|
1311
|
-
rejected,
|
|
1312
|
-
settled,
|
|
1313
|
-
options
|
|
1314
|
-
} = reducerDefinition;
|
|
1315
|
-
const thunk = cAT(type, payloadCreator, options);
|
|
1316
|
-
context.exposeAction(reducerName, thunk);
|
|
1317
|
-
if (fulfilled) {
|
|
1318
|
-
context.addCase(thunk.fulfilled, fulfilled);
|
|
1319
|
-
}
|
|
1320
|
-
if (pending) {
|
|
1321
|
-
context.addCase(thunk.pending, pending);
|
|
1322
|
-
}
|
|
1323
|
-
if (rejected) {
|
|
1324
|
-
context.addCase(thunk.rejected, rejected);
|
|
1325
|
-
}
|
|
1326
|
-
if (settled) {
|
|
1327
|
-
context.addMatcher(thunk.settled, settled);
|
|
1328
|
-
}
|
|
1329
|
-
context.exposeCaseReducer(reducerName, {
|
|
1330
|
-
fulfilled: fulfilled || noop,
|
|
1331
|
-
pending: pending || noop,
|
|
1332
|
-
rejected: rejected || noop,
|
|
1333
|
-
settled: settled || noop
|
|
1334
|
-
});
|
|
1335
|
-
}
|
|
1336
|
-
function noop() {
|
|
1063
|
+
return reducerDefinition._reducerDefinitionType === "reducerWithPrepare";
|
|
1337
1064
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1065
|
+
function handleThunkCaseReducerDefinition({ type, reducerName }, reducerDefinition, context, cAT) {
|
|
1066
|
+
if (!cAT) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
|
1067
|
+
const { payloadCreator, fulfilled, pending, rejected, settled, options } = reducerDefinition;
|
|
1068
|
+
const thunk = cAT(type, payloadCreator, options);
|
|
1069
|
+
context.exposeAction(reducerName, thunk);
|
|
1070
|
+
if (fulfilled) context.addCase(thunk.fulfilled, fulfilled);
|
|
1071
|
+
if (pending) context.addCase(thunk.pending, pending);
|
|
1072
|
+
if (rejected) context.addCase(thunk.rejected, rejected);
|
|
1073
|
+
if (settled) context.addMatcher(thunk.settled, settled);
|
|
1074
|
+
context.exposeCaseReducer(reducerName, {
|
|
1075
|
+
fulfilled: fulfilled || noop$1,
|
|
1076
|
+
pending: pending || noop$1,
|
|
1077
|
+
rejected: rejected || noop$1,
|
|
1078
|
+
settled: settled || noop$1
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
function noop$1() {}
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region src/entities/entity_state.ts
|
|
1340
1084
|
function getInitialEntityState() {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1085
|
+
return {
|
|
1086
|
+
ids: [],
|
|
1087
|
+
entities: {}
|
|
1088
|
+
};
|
|
1345
1089
|
}
|
|
1346
1090
|
function createInitialStateFactory(stateAdapter) {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
getInitialState
|
|
1353
|
-
};
|
|
1091
|
+
function getInitialState(additionalState = {}, entities) {
|
|
1092
|
+
const state = Object.assign(getInitialEntityState(), additionalState);
|
|
1093
|
+
return entities ? stateAdapter.setAll(state, entities) : state;
|
|
1094
|
+
}
|
|
1095
|
+
return { getInitialState };
|
|
1354
1096
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1097
|
+
//#endregion
|
|
1098
|
+
//#region src/entities/state_selectors.ts
|
|
1357
1099
|
function createSelectorsFactory() {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
selectById: createSelector2(selectGlobalizedEntities, selectId, selectById)
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
return {
|
|
1387
|
-
getSelectors
|
|
1388
|
-
};
|
|
1100
|
+
function getSelectors(selectState, options = {}) {
|
|
1101
|
+
const { createSelector = createDraftSafeSelector } = options;
|
|
1102
|
+
const selectIds = (state) => state.ids;
|
|
1103
|
+
const selectEntities = (state) => state.entities;
|
|
1104
|
+
const selectAll = createSelector(selectIds, selectEntities, (ids, entities) => ids.map((id) => entities[id]));
|
|
1105
|
+
const selectId = (_, id) => id;
|
|
1106
|
+
const selectById = (entities, id) => entities[id];
|
|
1107
|
+
const selectTotal = createSelector(selectIds, (ids) => ids.length);
|
|
1108
|
+
if (!selectState) return {
|
|
1109
|
+
selectIds,
|
|
1110
|
+
selectEntities,
|
|
1111
|
+
selectAll,
|
|
1112
|
+
selectTotal,
|
|
1113
|
+
selectById: createSelector(selectEntities, selectId, selectById)
|
|
1114
|
+
};
|
|
1115
|
+
const selectGlobalizedEntities = createSelector(selectState, selectEntities);
|
|
1116
|
+
return {
|
|
1117
|
+
selectIds: createSelector(selectState, selectIds),
|
|
1118
|
+
selectEntities: selectGlobalizedEntities,
|
|
1119
|
+
selectAll: createSelector(selectState, selectAll),
|
|
1120
|
+
selectTotal: createSelector(selectState, selectTotal),
|
|
1121
|
+
selectById: createSelector(selectGlobalizedEntities, selectId, selectById)
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
return { getSelectors };
|
|
1389
1125
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1126
|
+
//#endregion
|
|
1127
|
+
//#region src/entities/state_adapter.ts
|
|
1128
|
+
const isDraftTyped = isDraft;
|
|
1393
1129
|
function createSingleArgumentStateOperator(mutator) {
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1130
|
+
const operator = createStateOperator((_, state) => mutator(state));
|
|
1131
|
+
return function operation(state) {
|
|
1132
|
+
return operator(state, void 0);
|
|
1133
|
+
};
|
|
1398
1134
|
}
|
|
1399
1135
|
function createStateOperator(mutator) {
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
}
|
|
1415
|
-
return produce(state, runMutator);
|
|
1416
|
-
};
|
|
1136
|
+
return function operation(state, arg) {
|
|
1137
|
+
function isPayloadActionArgument(arg) {
|
|
1138
|
+
return isFSA(arg);
|
|
1139
|
+
}
|
|
1140
|
+
const runMutator = (draft) => {
|
|
1141
|
+
if (isPayloadActionArgument(arg)) mutator(arg.payload, draft);
|
|
1142
|
+
else mutator(arg, draft);
|
|
1143
|
+
};
|
|
1144
|
+
if (isDraftTyped(state)) {
|
|
1145
|
+
runMutator(state);
|
|
1146
|
+
return state;
|
|
1147
|
+
}
|
|
1148
|
+
return createNextState(state, runMutator);
|
|
1149
|
+
};
|
|
1417
1150
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/entities/utils.ts
|
|
1420
1153
|
function selectIdValue(entity, selectId) {
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1425
|
-
return key;
|
|
1154
|
+
const key = selectId(entity);
|
|
1155
|
+
if (process.env.NODE_ENV !== "production" && key === void 0) console.warn("The entity passed to the `selectId` implementation returned undefined.", "You should probably provide your own `selectId` implementation.", "The entity that was passed:", entity, "The `selectId` implementation:", selectId.toString());
|
|
1156
|
+
return key;
|
|
1426
1157
|
}
|
|
1427
1158
|
function ensureEntitiesArray(entities) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
}
|
|
1431
|
-
return entities;
|
|
1159
|
+
if (!Array.isArray(entities)) entities = Object.values(entities);
|
|
1160
|
+
return entities;
|
|
1432
1161
|
}
|
|
1433
1162
|
function getCurrent(value) {
|
|
1434
|
-
|
|
1163
|
+
return isDraft(value) ? current(value) : value;
|
|
1435
1164
|
}
|
|
1436
1165
|
function splitAddedUpdatedEntities(newEntities, selectId, state) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1166
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1167
|
+
const existingIdsArray = getCurrent(state.ids);
|
|
1168
|
+
const existingIds = new Set(existingIdsArray);
|
|
1169
|
+
const added = [];
|
|
1170
|
+
const addedIds = /* @__PURE__ */ new Set([]);
|
|
1171
|
+
const updated = [];
|
|
1172
|
+
for (const entity of newEntities) {
|
|
1173
|
+
const id = selectIdValue(entity, selectId);
|
|
1174
|
+
if (existingIds.has(id) || addedIds.has(id)) updated.push({
|
|
1175
|
+
id,
|
|
1176
|
+
changes: entity
|
|
1177
|
+
});
|
|
1178
|
+
else {
|
|
1179
|
+
addedIds.add(id);
|
|
1180
|
+
added.push(entity);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return [
|
|
1184
|
+
added,
|
|
1185
|
+
updated,
|
|
1186
|
+
existingIdsArray
|
|
1187
|
+
];
|
|
1456
1188
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1189
|
+
//#endregion
|
|
1190
|
+
//#region src/entities/unsorted_state_adapter.ts
|
|
1459
1191
|
function createUnsortedStateAdapter(selectId) {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
function upsertManyMutably(newEntities, state) {
|
|
1561
|
-
const [added, updated] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
|
1562
|
-
addManyMutably(added, state);
|
|
1563
|
-
updateManyMutably(updated, state);
|
|
1564
|
-
}
|
|
1565
|
-
return {
|
|
1566
|
-
removeAll: createSingleArgumentStateOperator(removeAllMutably),
|
|
1567
|
-
addOne: createStateOperator(addOneMutably),
|
|
1568
|
-
addMany: createStateOperator(addManyMutably),
|
|
1569
|
-
setOne: createStateOperator(setOneMutably),
|
|
1570
|
-
setMany: createStateOperator(setManyMutably),
|
|
1571
|
-
setAll: createStateOperator(setAllMutably),
|
|
1572
|
-
updateOne: createStateOperator(updateOneMutably),
|
|
1573
|
-
updateMany: createStateOperator(updateManyMutably),
|
|
1574
|
-
upsertOne: createStateOperator(upsertOneMutably),
|
|
1575
|
-
upsertMany: createStateOperator(upsertManyMutably),
|
|
1576
|
-
removeOne: createStateOperator(removeOneMutably),
|
|
1577
|
-
removeMany: createStateOperator(removeManyMutably)
|
|
1578
|
-
};
|
|
1192
|
+
function addOneMutably(entity, state) {
|
|
1193
|
+
const key = selectIdValue(entity, selectId);
|
|
1194
|
+
if (key in state.entities) return;
|
|
1195
|
+
state.ids.push(key);
|
|
1196
|
+
state.entities[key] = entity;
|
|
1197
|
+
}
|
|
1198
|
+
function addManyMutably(newEntities, state) {
|
|
1199
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1200
|
+
for (const entity of newEntities) addOneMutably(entity, state);
|
|
1201
|
+
}
|
|
1202
|
+
function setOneMutably(entity, state) {
|
|
1203
|
+
const key = selectIdValue(entity, selectId);
|
|
1204
|
+
if (!(key in state.entities)) state.ids.push(key);
|
|
1205
|
+
state.entities[key] = entity;
|
|
1206
|
+
}
|
|
1207
|
+
function setManyMutably(newEntities, state) {
|
|
1208
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1209
|
+
for (const entity of newEntities) setOneMutably(entity, state);
|
|
1210
|
+
}
|
|
1211
|
+
function setAllMutably(newEntities, state) {
|
|
1212
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1213
|
+
state.ids = [];
|
|
1214
|
+
state.entities = {};
|
|
1215
|
+
setManyMutably(newEntities, state);
|
|
1216
|
+
}
|
|
1217
|
+
function removeOneMutably(key, state) {
|
|
1218
|
+
return removeManyMutably([key], state);
|
|
1219
|
+
}
|
|
1220
|
+
function removeManyMutably(keys, state) {
|
|
1221
|
+
let didMutate = false;
|
|
1222
|
+
keys.forEach((key) => {
|
|
1223
|
+
if (key in state.entities) {
|
|
1224
|
+
delete state.entities[key];
|
|
1225
|
+
didMutate = true;
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
if (didMutate) state.ids = state.ids.filter((id) => id in state.entities);
|
|
1229
|
+
}
|
|
1230
|
+
function removeAllMutably(state) {
|
|
1231
|
+
Object.assign(state, {
|
|
1232
|
+
ids: [],
|
|
1233
|
+
entities: {}
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
function takeNewKey(keys, update, state) {
|
|
1237
|
+
const original = state.entities[update.id];
|
|
1238
|
+
if (original === void 0) return false;
|
|
1239
|
+
const updated = Object.assign({}, original, update.changes);
|
|
1240
|
+
const newKey = selectIdValue(updated, selectId);
|
|
1241
|
+
const hasNewKey = newKey !== update.id;
|
|
1242
|
+
if (hasNewKey) {
|
|
1243
|
+
keys[update.id] = newKey;
|
|
1244
|
+
delete state.entities[update.id];
|
|
1245
|
+
}
|
|
1246
|
+
state.entities[newKey] = updated;
|
|
1247
|
+
return hasNewKey;
|
|
1248
|
+
}
|
|
1249
|
+
function updateOneMutably(update, state) {
|
|
1250
|
+
return updateManyMutably([update], state);
|
|
1251
|
+
}
|
|
1252
|
+
function updateManyMutably(updates, state) {
|
|
1253
|
+
const newKeys = {};
|
|
1254
|
+
const updatesPerEntity = {};
|
|
1255
|
+
updates.forEach((update) => {
|
|
1256
|
+
if (update.id in state.entities) {
|
|
1257
|
+
var _updatesPerEntity$upd;
|
|
1258
|
+
updatesPerEntity[update.id] = {
|
|
1259
|
+
id: update.id,
|
|
1260
|
+
changes: _objectSpread2(_objectSpread2({}, (_updatesPerEntity$upd = updatesPerEntity[update.id]) === null || _updatesPerEntity$upd === void 0 ? void 0 : _updatesPerEntity$upd.changes), update.changes)
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
updates = Object.values(updatesPerEntity);
|
|
1265
|
+
if (updates.length > 0) {
|
|
1266
|
+
if (updates.filter((update) => takeNewKey(newKeys, update, state)).length > 0) state.ids = Object.values(state.entities).map((e) => selectIdValue(e, selectId));
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
function upsertOneMutably(entity, state) {
|
|
1270
|
+
return upsertManyMutably([entity], state);
|
|
1271
|
+
}
|
|
1272
|
+
function upsertManyMutably(newEntities, state) {
|
|
1273
|
+
const [added, updated] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
|
1274
|
+
addManyMutably(added, state);
|
|
1275
|
+
updateManyMutably(updated, state);
|
|
1276
|
+
}
|
|
1277
|
+
return {
|
|
1278
|
+
removeAll: createSingleArgumentStateOperator(removeAllMutably),
|
|
1279
|
+
addOne: createStateOperator(addOneMutably),
|
|
1280
|
+
addMany: createStateOperator(addManyMutably),
|
|
1281
|
+
setOne: createStateOperator(setOneMutably),
|
|
1282
|
+
setMany: createStateOperator(setManyMutably),
|
|
1283
|
+
setAll: createStateOperator(setAllMutably),
|
|
1284
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
1285
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
1286
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
1287
|
+
upsertMany: createStateOperator(upsertManyMutably),
|
|
1288
|
+
removeOne: createStateOperator(removeOneMutably),
|
|
1289
|
+
removeMany: createStateOperator(removeManyMutably)
|
|
1290
|
+
};
|
|
1579
1291
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1292
|
+
//#endregion
|
|
1293
|
+
//#region src/entities/sorted_state_adapter.ts
|
|
1582
1294
|
function findInsertIndex(sortedItems, item, comparisonFunction) {
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
highIndex = middleIndex;
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
return lowIndex;
|
|
1295
|
+
let lowIndex = 0;
|
|
1296
|
+
let highIndex = sortedItems.length;
|
|
1297
|
+
while (lowIndex < highIndex) {
|
|
1298
|
+
let middleIndex = lowIndex + highIndex >>> 1;
|
|
1299
|
+
const currentItem = sortedItems[middleIndex];
|
|
1300
|
+
if (comparisonFunction(item, currentItem) >= 0) lowIndex = middleIndex + 1;
|
|
1301
|
+
else highIndex = middleIndex;
|
|
1302
|
+
}
|
|
1303
|
+
return lowIndex;
|
|
1596
1304
|
}
|
|
1597
1305
|
function insert(sortedItems, item, comparisonFunction) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1306
|
+
const insertAtIndex = findInsertIndex(sortedItems, item, comparisonFunction);
|
|
1307
|
+
sortedItems.splice(insertAtIndex, 0, item);
|
|
1308
|
+
return sortedItems;
|
|
1601
1309
|
}
|
|
1602
1310
|
function createSortedStateAdapter(selectId, comparer) {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
sortedEntities.sort(comparer);
|
|
1723
|
-
}
|
|
1724
|
-
const newSortedIds = sortedEntities.map(selectId);
|
|
1725
|
-
if (!areArraysEqual(currentIds, newSortedIds)) {
|
|
1726
|
-
state.ids = newSortedIds;
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
return {
|
|
1730
|
-
removeOne,
|
|
1731
|
-
removeMany,
|
|
1732
|
-
removeAll,
|
|
1733
|
-
addOne: createStateOperator(addOneMutably),
|
|
1734
|
-
updateOne: createStateOperator(updateOneMutably),
|
|
1735
|
-
upsertOne: createStateOperator(upsertOneMutably),
|
|
1736
|
-
setOne: createStateOperator(setOneMutably),
|
|
1737
|
-
setMany: createStateOperator(setManyMutably),
|
|
1738
|
-
setAll: createStateOperator(setAllMutably),
|
|
1739
|
-
addMany: createStateOperator(addManyMutably),
|
|
1740
|
-
updateMany: createStateOperator(updateManyMutably),
|
|
1741
|
-
upsertMany: createStateOperator(upsertManyMutably)
|
|
1742
|
-
};
|
|
1311
|
+
const { removeOne, removeMany, removeAll } = createUnsortedStateAdapter(selectId);
|
|
1312
|
+
function addOneMutably(entity, state) {
|
|
1313
|
+
return addManyMutably([entity], state);
|
|
1314
|
+
}
|
|
1315
|
+
function addManyMutably(newEntities, state, existingIds) {
|
|
1316
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1317
|
+
const existingKeys = new Set(existingIds !== null && existingIds !== void 0 ? existingIds : getCurrent(state.ids));
|
|
1318
|
+
const addedKeys = /* @__PURE__ */ new Set();
|
|
1319
|
+
const models = newEntities.filter((model) => {
|
|
1320
|
+
const modelId = selectIdValue(model, selectId);
|
|
1321
|
+
const notAdded = !addedKeys.has(modelId);
|
|
1322
|
+
if (notAdded) addedKeys.add(modelId);
|
|
1323
|
+
return !existingKeys.has(modelId) && notAdded;
|
|
1324
|
+
});
|
|
1325
|
+
if (models.length !== 0) mergeFunction(state, models);
|
|
1326
|
+
}
|
|
1327
|
+
function setOneMutably(entity, state) {
|
|
1328
|
+
return setManyMutably([entity], state);
|
|
1329
|
+
}
|
|
1330
|
+
function setManyMutably(newEntities, state) {
|
|
1331
|
+
let deduplicatedEntities = {};
|
|
1332
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1333
|
+
if (newEntities.length !== 0) {
|
|
1334
|
+
for (const item of newEntities) {
|
|
1335
|
+
const entityId = selectId(item);
|
|
1336
|
+
deduplicatedEntities[entityId] = item;
|
|
1337
|
+
delete state.entities[entityId];
|
|
1338
|
+
}
|
|
1339
|
+
newEntities = ensureEntitiesArray(deduplicatedEntities);
|
|
1340
|
+
mergeFunction(state, newEntities);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
function setAllMutably(newEntities, state) {
|
|
1344
|
+
newEntities = ensureEntitiesArray(newEntities);
|
|
1345
|
+
state.entities = {};
|
|
1346
|
+
state.ids = [];
|
|
1347
|
+
setManyMutably(newEntities, state);
|
|
1348
|
+
}
|
|
1349
|
+
function updateOneMutably(update, state) {
|
|
1350
|
+
return updateManyMutably([update], state);
|
|
1351
|
+
}
|
|
1352
|
+
function updateManyMutably(updates, state) {
|
|
1353
|
+
let appliedUpdates = false;
|
|
1354
|
+
let replacedIds = false;
|
|
1355
|
+
const updatesPerEntity = {};
|
|
1356
|
+
for (const update of updates) if (update.id in state.entities) {
|
|
1357
|
+
var _updatesPerEntity$upd;
|
|
1358
|
+
updatesPerEntity[update.id] = {
|
|
1359
|
+
id: update.id,
|
|
1360
|
+
changes: _objectSpread2(_objectSpread2({}, (_updatesPerEntity$upd = updatesPerEntity[update.id]) === null || _updatesPerEntity$upd === void 0 ? void 0 : _updatesPerEntity$upd.changes), update.changes)
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
for (const update of Object.values(updatesPerEntity)) {
|
|
1364
|
+
const entity = state.entities[update.id];
|
|
1365
|
+
if (!entity) continue;
|
|
1366
|
+
appliedUpdates = true;
|
|
1367
|
+
Object.assign(entity, update.changes);
|
|
1368
|
+
const newId = selectId(entity);
|
|
1369
|
+
if (update.id !== newId) {
|
|
1370
|
+
replacedIds = true;
|
|
1371
|
+
delete state.entities[update.id];
|
|
1372
|
+
const oldIndex = state.ids.indexOf(update.id);
|
|
1373
|
+
state.ids[oldIndex] = newId;
|
|
1374
|
+
state.entities[newId] = entity;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
if (appliedUpdates) mergeFunction(state, [], appliedUpdates, replacedIds);
|
|
1378
|
+
}
|
|
1379
|
+
function upsertOneMutably(entity, state) {
|
|
1380
|
+
return upsertManyMutably([entity], state);
|
|
1381
|
+
}
|
|
1382
|
+
function upsertManyMutably(newEntities, state) {
|
|
1383
|
+
const [added, updated, existingIdsArray] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
|
1384
|
+
if (added.length) addManyMutably(added, state, existingIdsArray);
|
|
1385
|
+
if (updated.length) updateManyMutably(updated, state);
|
|
1386
|
+
}
|
|
1387
|
+
function areArraysEqual(a, b) {
|
|
1388
|
+
if (a.length !== b.length) return false;
|
|
1389
|
+
for (let i = 0; i < a.length; i++) {
|
|
1390
|
+
if (a[i] === b[i]) continue;
|
|
1391
|
+
return false;
|
|
1392
|
+
}
|
|
1393
|
+
return true;
|
|
1394
|
+
}
|
|
1395
|
+
function mergeFunction(state, addedItems, appliedUpdates, replacedIds) {
|
|
1396
|
+
const currentEntities = getCurrent(state.entities);
|
|
1397
|
+
const currentIds = getCurrent(state.ids);
|
|
1398
|
+
const stateEntities = state.entities;
|
|
1399
|
+
let ids = currentIds;
|
|
1400
|
+
if (replacedIds) ids = new Set(currentIds);
|
|
1401
|
+
let sortedEntities = [];
|
|
1402
|
+
for (const id of ids) {
|
|
1403
|
+
const entity = currentEntities[id];
|
|
1404
|
+
if (entity) sortedEntities.push(entity);
|
|
1405
|
+
}
|
|
1406
|
+
const wasPreviouslyEmpty = sortedEntities.length === 0;
|
|
1407
|
+
for (const item of addedItems) {
|
|
1408
|
+
stateEntities[selectId(item)] = item;
|
|
1409
|
+
if (!wasPreviouslyEmpty) insert(sortedEntities, item, comparer);
|
|
1410
|
+
}
|
|
1411
|
+
if (wasPreviouslyEmpty) sortedEntities = addedItems.slice().sort(comparer);
|
|
1412
|
+
else if (appliedUpdates) sortedEntities.sort(comparer);
|
|
1413
|
+
const newSortedIds = sortedEntities.map(selectId);
|
|
1414
|
+
if (!areArraysEqual(currentIds, newSortedIds)) state.ids = newSortedIds;
|
|
1415
|
+
}
|
|
1416
|
+
return {
|
|
1417
|
+
removeOne,
|
|
1418
|
+
removeMany,
|
|
1419
|
+
removeAll,
|
|
1420
|
+
addOne: createStateOperator(addOneMutably),
|
|
1421
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
1422
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
1423
|
+
setOne: createStateOperator(setOneMutably),
|
|
1424
|
+
setMany: createStateOperator(setManyMutably),
|
|
1425
|
+
setAll: createStateOperator(setAllMutably),
|
|
1426
|
+
addMany: createStateOperator(addManyMutably),
|
|
1427
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
1428
|
+
upsertMany: createStateOperator(upsertManyMutably)
|
|
1429
|
+
};
|
|
1743
1430
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1431
|
+
//#endregion
|
|
1432
|
+
//#region src/entities/create_adapter.ts
|
|
1746
1433
|
function createEntityAdapter(options = {}) {
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
selectId,
|
|
1759
|
-
sortComparer
|
|
1760
|
-
}, stateFactory), selectorsFactory), stateAdapter);
|
|
1434
|
+
const { selectId, sortComparer } = _objectSpread2({
|
|
1435
|
+
sortComparer: false,
|
|
1436
|
+
selectId: (instance) => instance.id
|
|
1437
|
+
}, options);
|
|
1438
|
+
const stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
|
|
1439
|
+
const stateFactory = createInitialStateFactory(stateAdapter);
|
|
1440
|
+
const selectorsFactory = createSelectorsFactory();
|
|
1441
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({
|
|
1442
|
+
selectId,
|
|
1443
|
+
sortComparer
|
|
1444
|
+
}, stateFactory), selectorsFactory), stateAdapter);
|
|
1761
1445
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1446
|
+
//#endregion
|
|
1447
|
+
//#region src/listenerMiddleware/exceptions.ts
|
|
1448
|
+
const task = "task";
|
|
1449
|
+
const listener = "listener";
|
|
1450
|
+
const completed = "completed";
|
|
1451
|
+
const cancelled = "cancelled";
|
|
1452
|
+
const taskCancelled = `task-${cancelled}`;
|
|
1453
|
+
const taskCompleted = `task-${completed}`;
|
|
1454
|
+
const listenerCancelled = `${listener}-${cancelled}`;
|
|
1455
|
+
const listenerCompleted = `${listener}-${completed}`;
|
|
1772
1456
|
var TaskAbortError = class {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
};
|
|
1780
|
-
|
|
1781
|
-
// src/listenerMiddleware/utils.ts
|
|
1782
|
-
var assertFunction = (func, expected) => {
|
|
1783
|
-
if (typeof func !== "function") {
|
|
1784
|
-
throw new TypeError(process.env.NODE_ENV === "production" ? formatProdErrorMessage(32) : `${expected} is not a function`);
|
|
1785
|
-
}
|
|
1457
|
+
constructor(code) {
|
|
1458
|
+
this.code = code;
|
|
1459
|
+
_defineProperty(this, "name", "TaskAbortError");
|
|
1460
|
+
_defineProperty(this, "message", void 0);
|
|
1461
|
+
this.message = `${task} ${cancelled} (reason: ${code})`;
|
|
1462
|
+
}
|
|
1786
1463
|
};
|
|
1787
|
-
|
|
1464
|
+
//#endregion
|
|
1465
|
+
//#region src/listenerMiddleware/utils.ts
|
|
1466
|
+
const assertFunction = (func, expected) => {
|
|
1467
|
+
if (typeof func !== "function") throw new TypeError(process.env.NODE_ENV === "production" ? formatProdErrorMessage(32) : `${expected} is not a function`);
|
|
1788
1468
|
};
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1469
|
+
const noop = () => {};
|
|
1470
|
+
const catchRejection = (promise, onError = noop) => {
|
|
1471
|
+
promise.catch(onError);
|
|
1472
|
+
return promise;
|
|
1792
1473
|
};
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
});
|
|
1797
|
-
return () => abortSignal.removeEventListener("abort", callback);
|
|
1474
|
+
const addAbortSignalListener = (abortSignal, callback) => {
|
|
1475
|
+
abortSignal.addEventListener("abort", callback, { once: true });
|
|
1476
|
+
return () => abortSignal.removeEventListener("abort", callback);
|
|
1798
1477
|
};
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
throw new TaskAbortError(signal.reason);
|
|
1804
|
-
}
|
|
1478
|
+
//#endregion
|
|
1479
|
+
//#region src/listenerMiddleware/task.ts
|
|
1480
|
+
const validateActive = (signal) => {
|
|
1481
|
+
if (signal.aborted) throw new TaskAbortError(signal.reason);
|
|
1805
1482
|
};
|
|
1806
1483
|
function raceWithSignal(signal, promise) {
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
}
|
|
1484
|
+
let cleanup = noop;
|
|
1485
|
+
return new Promise((resolve, reject) => {
|
|
1486
|
+
const notifyRejection = () => reject(new TaskAbortError(signal.reason));
|
|
1487
|
+
if (signal.aborted) {
|
|
1488
|
+
notifyRejection();
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
cleanup = addAbortSignalListener(signal, notifyRejection);
|
|
1492
|
+
promise.finally(() => cleanup()).then(resolve, reject);
|
|
1493
|
+
}).finally(() => {
|
|
1494
|
+
cleanup = noop;
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
const runTask = async (task, cleanUp) => {
|
|
1498
|
+
try {
|
|
1499
|
+
await Promise.resolve();
|
|
1500
|
+
return {
|
|
1501
|
+
status: "ok",
|
|
1502
|
+
value: await task()
|
|
1503
|
+
};
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
return {
|
|
1506
|
+
status: error instanceof TaskAbortError ? "cancelled" : "rejected",
|
|
1507
|
+
error
|
|
1508
|
+
};
|
|
1509
|
+
} finally {
|
|
1510
|
+
cleanUp === null || cleanUp === void 0 || cleanUp();
|
|
1511
|
+
}
|
|
1836
1512
|
};
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1513
|
+
const createPause = (signal) => {
|
|
1514
|
+
return (promise) => {
|
|
1515
|
+
return catchRejection(raceWithSignal(signal, promise).then((output) => {
|
|
1516
|
+
validateActive(signal);
|
|
1517
|
+
return output;
|
|
1518
|
+
}));
|
|
1519
|
+
};
|
|
1844
1520
|
};
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1521
|
+
const createDelay = (signal) => {
|
|
1522
|
+
const pause = createPause(signal);
|
|
1523
|
+
return (timeoutMs) => {
|
|
1524
|
+
return pause(new Promise((resolve) => setTimeout(resolve, timeoutMs)));
|
|
1525
|
+
};
|
|
1850
1526
|
};
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
childAbortController.abort(taskCancelled);
|
|
1882
|
-
}
|
|
1883
|
-
};
|
|
1884
|
-
};
|
|
1527
|
+
//#endregion
|
|
1528
|
+
//#region src/listenerMiddleware/index.ts
|
|
1529
|
+
const { assign } = Object;
|
|
1530
|
+
const INTERNAL_NIL_TOKEN = {};
|
|
1531
|
+
const alm = "listenerMiddleware";
|
|
1532
|
+
const createFork = (parentAbortSignal, parentBlockingPromises) => {
|
|
1533
|
+
const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () => controller.abort(parentAbortSignal.reason));
|
|
1534
|
+
return (taskExecutor, opts) => {
|
|
1535
|
+
assertFunction(taskExecutor, "taskExecutor");
|
|
1536
|
+
const childAbortController = new AbortController();
|
|
1537
|
+
linkControllers(childAbortController);
|
|
1538
|
+
const result = runTask(async () => {
|
|
1539
|
+
validateActive(parentAbortSignal);
|
|
1540
|
+
validateActive(childAbortController.signal);
|
|
1541
|
+
const result = await taskExecutor({
|
|
1542
|
+
pause: createPause(childAbortController.signal),
|
|
1543
|
+
delay: createDelay(childAbortController.signal),
|
|
1544
|
+
signal: childAbortController.signal
|
|
1545
|
+
});
|
|
1546
|
+
validateActive(childAbortController.signal);
|
|
1547
|
+
return result;
|
|
1548
|
+
}, () => childAbortController.abort(taskCompleted));
|
|
1549
|
+
if (opts === null || opts === void 0 ? void 0 : opts.autoJoin) parentBlockingPromises.push(result.catch(noop));
|
|
1550
|
+
return {
|
|
1551
|
+
result: createPause(parentAbortSignal)(result),
|
|
1552
|
+
cancel() {
|
|
1553
|
+
childAbortController.abort(taskCancelled);
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
};
|
|
1885
1557
|
};
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1558
|
+
const createTakePattern = (startListening, signal) => {
|
|
1559
|
+
const take = async (predicate, timeout) => {
|
|
1560
|
+
validateActive(signal);
|
|
1561
|
+
let unsubscribe = () => {};
|
|
1562
|
+
const promises = [new Promise((resolve, reject) => {
|
|
1563
|
+
let stopListening = startListening({
|
|
1564
|
+
predicate,
|
|
1565
|
+
effect: (action, listenerApi) => {
|
|
1566
|
+
listenerApi.unsubscribe();
|
|
1567
|
+
resolve([
|
|
1568
|
+
action,
|
|
1569
|
+
listenerApi.getState(),
|
|
1570
|
+
listenerApi.getOriginalState()
|
|
1571
|
+
]);
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
unsubscribe = () => {
|
|
1575
|
+
stopListening();
|
|
1576
|
+
reject();
|
|
1577
|
+
};
|
|
1578
|
+
})];
|
|
1579
|
+
if (timeout != null) promises.push(new Promise((resolve) => setTimeout(resolve, timeout, null)));
|
|
1580
|
+
try {
|
|
1581
|
+
const output = await raceWithSignal(signal, Promise.race(promises));
|
|
1582
|
+
validateActive(signal);
|
|
1583
|
+
return output;
|
|
1584
|
+
} finally {
|
|
1585
|
+
unsubscribe();
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
return ((predicate, timeout) => catchRejection(take(predicate, timeout)));
|
|
1917
1589
|
};
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
predicate = matcher;
|
|
1933
|
-
} else if (predicate) {
|
|
1934
|
-
} else {
|
|
1935
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(21) : "Creating or removing a listener requires one of the known fields for matching an action");
|
|
1936
|
-
}
|
|
1937
|
-
assertFunction(effect, "options.listener");
|
|
1938
|
-
return {
|
|
1939
|
-
predicate,
|
|
1940
|
-
type,
|
|
1941
|
-
effect
|
|
1942
|
-
};
|
|
1590
|
+
const getListenerEntryPropsFrom = (options) => {
|
|
1591
|
+
let { type, actionCreator, matcher, predicate, effect } = options;
|
|
1592
|
+
if (type) predicate = createAction(type).match;
|
|
1593
|
+
else if (actionCreator) {
|
|
1594
|
+
type = actionCreator.type;
|
|
1595
|
+
predicate = actionCreator.match;
|
|
1596
|
+
} else if (matcher) predicate = matcher;
|
|
1597
|
+
else if (predicate) {} else throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(21) : "Creating or removing a listener requires one of the known fields for matching an action");
|
|
1598
|
+
assertFunction(effect, "options.listener");
|
|
1599
|
+
return {
|
|
1600
|
+
predicate,
|
|
1601
|
+
type,
|
|
1602
|
+
effect
|
|
1603
|
+
};
|
|
1943
1604
|
};
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
}
|
|
1962
|
-
withTypes: () => createListenerEntry
|
|
1963
|
-
});
|
|
1964
|
-
var findListenerEntry = (listenerMap, options) => {
|
|
1965
|
-
const {
|
|
1966
|
-
type,
|
|
1967
|
-
effect,
|
|
1968
|
-
predicate
|
|
1969
|
-
} = getListenerEntryPropsFrom(options);
|
|
1970
|
-
return Array.from(listenerMap.values()).find((entry) => {
|
|
1971
|
-
const matchPredicateOrType = typeof type === "string" ? entry.type === type : entry.predicate === predicate;
|
|
1972
|
-
return matchPredicateOrType && entry.effect === effect;
|
|
1973
|
-
});
|
|
1605
|
+
const createListenerEntry = /* @__PURE__ */ assign((options) => {
|
|
1606
|
+
const { type, predicate, effect } = getListenerEntryPropsFrom(options);
|
|
1607
|
+
return {
|
|
1608
|
+
id: nanoid(),
|
|
1609
|
+
effect,
|
|
1610
|
+
type,
|
|
1611
|
+
predicate,
|
|
1612
|
+
pending: /* @__PURE__ */ new Set(),
|
|
1613
|
+
unsubscribe: () => {
|
|
1614
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(22) : "Unsubscribe not initialized");
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
}, { withTypes: () => createListenerEntry });
|
|
1618
|
+
const findListenerEntry = (listenerMap, options) => {
|
|
1619
|
+
const { type, effect, predicate } = getListenerEntryPropsFrom(options);
|
|
1620
|
+
return Array.from(listenerMap.values()).find((entry) => {
|
|
1621
|
+
return (typeof type === "string" ? entry.type === type : entry.predicate === predicate) && entry.effect === effect;
|
|
1622
|
+
});
|
|
1974
1623
|
};
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1624
|
+
const cancelActiveListeners = (entry) => {
|
|
1625
|
+
entry.pending.forEach((controller) => {
|
|
1626
|
+
controller.abort(listenerCancelled);
|
|
1627
|
+
});
|
|
1979
1628
|
};
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
listenerMap.clear();
|
|
1986
|
-
};
|
|
1629
|
+
const createClearListenerMiddleware = (listenerMap, executingListeners) => {
|
|
1630
|
+
return () => {
|
|
1631
|
+
for (const listener of executingListeners.keys()) cancelActiveListeners(listener);
|
|
1632
|
+
listenerMap.clear();
|
|
1633
|
+
};
|
|
1987
1634
|
};
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1635
|
+
const safelyNotifyError = (errorHandler, errorToNotify, errorInfo) => {
|
|
1636
|
+
try {
|
|
1637
|
+
errorHandler(errorToNotify, errorInfo);
|
|
1638
|
+
} catch (errorHandlerError) {
|
|
1639
|
+
setTimeout(() => {
|
|
1640
|
+
throw errorHandlerError;
|
|
1641
|
+
}, 0);
|
|
1642
|
+
}
|
|
1996
1643
|
};
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
});
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
withTypes: () => removeListener
|
|
2003
|
-
});
|
|
2004
|
-
var defaultErrorHandler = (...args) => {
|
|
2005
|
-
console.error(`${alm}/error`, ...args);
|
|
1644
|
+
const addListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/add`), { withTypes: () => addListener });
|
|
1645
|
+
const clearAllListeners = /* @__PURE__ */ createAction(`${alm}/removeAll`);
|
|
1646
|
+
const removeListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/remove`), { withTypes: () => removeListener });
|
|
1647
|
+
const defaultErrorHandler = (...args) => {
|
|
1648
|
+
console.error(`${alm}/error`, ...args);
|
|
2006
1649
|
};
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
};
|
|
2135
|
-
let result;
|
|
2136
|
-
try {
|
|
2137
|
-
result = next(action);
|
|
2138
|
-
if (listenerMap.size > 0) {
|
|
2139
|
-
const currentState = api.getState();
|
|
2140
|
-
const listenerEntries = Array.from(listenerMap.values());
|
|
2141
|
-
for (const entry of listenerEntries) {
|
|
2142
|
-
let runListener = false;
|
|
2143
|
-
try {
|
|
2144
|
-
runListener = entry.predicate(action, currentState, originalState);
|
|
2145
|
-
} catch (predicateError) {
|
|
2146
|
-
runListener = false;
|
|
2147
|
-
safelyNotifyError(onError, predicateError, {
|
|
2148
|
-
raisedBy: "predicate"
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
if (!runListener) {
|
|
2152
|
-
continue;
|
|
2153
|
-
}
|
|
2154
|
-
notifyListener(entry, action, api, getOriginalState);
|
|
2155
|
-
}
|
|
2156
|
-
}
|
|
2157
|
-
} finally {
|
|
2158
|
-
originalState = INTERNAL_NIL_TOKEN;
|
|
2159
|
-
}
|
|
2160
|
-
return result;
|
|
2161
|
-
};
|
|
2162
|
-
return {
|
|
2163
|
-
middleware,
|
|
2164
|
-
startListening,
|
|
2165
|
-
stopListening,
|
|
2166
|
-
clearListeners: clearListenerMiddleware
|
|
2167
|
-
};
|
|
1650
|
+
const createListenerMiddleware = (middlewareOptions = {}) => {
|
|
1651
|
+
const listenerMap = /* @__PURE__ */ new Map();
|
|
1652
|
+
const executingListeners = /* @__PURE__ */ new Map();
|
|
1653
|
+
const trackExecutingListener = (entry) => {
|
|
1654
|
+
var _executingListeners$g;
|
|
1655
|
+
const count = (_executingListeners$g = executingListeners.get(entry)) !== null && _executingListeners$g !== void 0 ? _executingListeners$g : 0;
|
|
1656
|
+
executingListeners.set(entry, count + 1);
|
|
1657
|
+
};
|
|
1658
|
+
const untrackExecutingListener = (entry) => {
|
|
1659
|
+
var _executingListeners$g2;
|
|
1660
|
+
const count = (_executingListeners$g2 = executingListeners.get(entry)) !== null && _executingListeners$g2 !== void 0 ? _executingListeners$g2 : 1;
|
|
1661
|
+
if (count === 1) executingListeners.delete(entry);
|
|
1662
|
+
else executingListeners.set(entry, count - 1);
|
|
1663
|
+
};
|
|
1664
|
+
const { extra, onError = defaultErrorHandler } = middlewareOptions;
|
|
1665
|
+
assertFunction(onError, "onError");
|
|
1666
|
+
const insertEntry = (entry) => {
|
|
1667
|
+
entry.unsubscribe = () => listenerMap.delete(entry.id);
|
|
1668
|
+
listenerMap.set(entry.id, entry);
|
|
1669
|
+
return (cancelOptions) => {
|
|
1670
|
+
entry.unsubscribe();
|
|
1671
|
+
if (cancelOptions === null || cancelOptions === void 0 ? void 0 : cancelOptions.cancelActive) cancelActiveListeners(entry);
|
|
1672
|
+
};
|
|
1673
|
+
};
|
|
1674
|
+
const startListening = ((options) => {
|
|
1675
|
+
var _findListenerEntry;
|
|
1676
|
+
const entry = (_findListenerEntry = findListenerEntry(listenerMap, options)) !== null && _findListenerEntry !== void 0 ? _findListenerEntry : createListenerEntry(options);
|
|
1677
|
+
return insertEntry(entry);
|
|
1678
|
+
});
|
|
1679
|
+
assign(startListening, { withTypes: () => startListening });
|
|
1680
|
+
const stopListening = (options) => {
|
|
1681
|
+
const entry = findListenerEntry(listenerMap, options);
|
|
1682
|
+
if (entry) {
|
|
1683
|
+
entry.unsubscribe();
|
|
1684
|
+
if (options.cancelActive) cancelActiveListeners(entry);
|
|
1685
|
+
}
|
|
1686
|
+
return !!entry;
|
|
1687
|
+
};
|
|
1688
|
+
assign(stopListening, { withTypes: () => stopListening });
|
|
1689
|
+
const notifyListener = async (entry, action, api, getOriginalState) => {
|
|
1690
|
+
const internalTaskController = new AbortController();
|
|
1691
|
+
const take = createTakePattern(startListening, internalTaskController.signal);
|
|
1692
|
+
const autoJoinPromises = [];
|
|
1693
|
+
try {
|
|
1694
|
+
entry.pending.add(internalTaskController);
|
|
1695
|
+
trackExecutingListener(entry);
|
|
1696
|
+
await Promise.resolve(entry.effect(action, assign({}, api, {
|
|
1697
|
+
getOriginalState,
|
|
1698
|
+
condition: (predicate, timeout) => take(predicate, timeout).then(Boolean),
|
|
1699
|
+
take,
|
|
1700
|
+
delay: createDelay(internalTaskController.signal),
|
|
1701
|
+
pause: createPause(internalTaskController.signal),
|
|
1702
|
+
extra,
|
|
1703
|
+
signal: internalTaskController.signal,
|
|
1704
|
+
fork: createFork(internalTaskController.signal, autoJoinPromises),
|
|
1705
|
+
unsubscribe: entry.unsubscribe,
|
|
1706
|
+
subscribe: () => {
|
|
1707
|
+
listenerMap.set(entry.id, entry);
|
|
1708
|
+
},
|
|
1709
|
+
cancelActiveListeners: () => {
|
|
1710
|
+
entry.pending.forEach((controller, _, set) => {
|
|
1711
|
+
if (controller !== internalTaskController) {
|
|
1712
|
+
controller.abort(listenerCancelled);
|
|
1713
|
+
set.delete(controller);
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
},
|
|
1717
|
+
cancel: () => {
|
|
1718
|
+
internalTaskController.abort(listenerCancelled);
|
|
1719
|
+
entry.pending.delete(internalTaskController);
|
|
1720
|
+
},
|
|
1721
|
+
throwIfCancelled: () => {
|
|
1722
|
+
validateActive(internalTaskController.signal);
|
|
1723
|
+
}
|
|
1724
|
+
})));
|
|
1725
|
+
} catch (listenerError) {
|
|
1726
|
+
if (!(listenerError instanceof TaskAbortError)) safelyNotifyError(onError, listenerError, { raisedBy: "effect" });
|
|
1727
|
+
} finally {
|
|
1728
|
+
await Promise.all(autoJoinPromises);
|
|
1729
|
+
internalTaskController.abort(listenerCompleted);
|
|
1730
|
+
untrackExecutingListener(entry);
|
|
1731
|
+
entry.pending.delete(internalTaskController);
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
const clearListenerMiddleware = createClearListenerMiddleware(listenerMap, executingListeners);
|
|
1735
|
+
const middleware = (api) => (next) => (action) => {
|
|
1736
|
+
if (!isAction(action)) return next(action);
|
|
1737
|
+
if (addListener.match(action)) return startListening(action.payload);
|
|
1738
|
+
if (clearAllListeners.match(action)) {
|
|
1739
|
+
clearListenerMiddleware();
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
if (removeListener.match(action)) return stopListening(action.payload);
|
|
1743
|
+
let originalState = api.getState();
|
|
1744
|
+
const getOriginalState = () => {
|
|
1745
|
+
if (originalState === INTERNAL_NIL_TOKEN) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(23) : `${alm}: getOriginalState can only be called synchronously`);
|
|
1746
|
+
return originalState;
|
|
1747
|
+
};
|
|
1748
|
+
let result;
|
|
1749
|
+
try {
|
|
1750
|
+
result = next(action);
|
|
1751
|
+
if (listenerMap.size > 0) {
|
|
1752
|
+
const currentState = api.getState();
|
|
1753
|
+
const listenerEntries = Array.from(listenerMap.values());
|
|
1754
|
+
for (const entry of listenerEntries) {
|
|
1755
|
+
let runListener = false;
|
|
1756
|
+
try {
|
|
1757
|
+
runListener = entry.predicate(action, currentState, originalState);
|
|
1758
|
+
} catch (predicateError) {
|
|
1759
|
+
runListener = false;
|
|
1760
|
+
safelyNotifyError(onError, predicateError, { raisedBy: "predicate" });
|
|
1761
|
+
}
|
|
1762
|
+
if (!runListener) continue;
|
|
1763
|
+
notifyListener(entry, action, api, getOriginalState);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
} finally {
|
|
1767
|
+
originalState = INTERNAL_NIL_TOKEN;
|
|
1768
|
+
}
|
|
1769
|
+
return result;
|
|
1770
|
+
};
|
|
1771
|
+
return {
|
|
1772
|
+
middleware,
|
|
1773
|
+
startListening,
|
|
1774
|
+
stopListening,
|
|
1775
|
+
clearListeners: clearListenerMiddleware
|
|
1776
|
+
};
|
|
2168
1777
|
};
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
1778
|
+
//#endregion
|
|
1779
|
+
//#region src/dynamicMiddleware/index.ts
|
|
1780
|
+
const createMiddlewareEntry = (middleware) => ({
|
|
1781
|
+
middleware,
|
|
1782
|
+
applied: /* @__PURE__ */ new Map()
|
|
2174
1783
|
});
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
1784
|
+
const matchInstance = (instanceId) => (action) => {
|
|
1785
|
+
var _action$meta;
|
|
1786
|
+
return (action === null || action === void 0 || (_action$meta = action.meta) === null || _action$meta === void 0 ? void 0 : _action$meta.instanceId) === instanceId;
|
|
2178
1787
|
};
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
1788
|
+
const createDynamicMiddleware = () => {
|
|
1789
|
+
const instanceId = nanoid();
|
|
1790
|
+
const middlewareMap = /* @__PURE__ */ new Map();
|
|
1791
|
+
let middlewareVersion = 0;
|
|
1792
|
+
const withMiddleware = Object.assign(createAction("dynamicMiddleware/add", (...middlewares) => ({
|
|
1793
|
+
payload: middlewares,
|
|
1794
|
+
meta: { instanceId }
|
|
1795
|
+
})), { withTypes: () => withMiddleware });
|
|
1796
|
+
const addMiddleware = Object.assign(function addMiddleware(...middlewares) {
|
|
1797
|
+
const previousSize = middlewareMap.size;
|
|
1798
|
+
middlewares.forEach((middleware) => {
|
|
1799
|
+
getOrInsertComputed(middlewareMap, middleware, createMiddlewareEntry);
|
|
1800
|
+
});
|
|
1801
|
+
if (middlewareMap.size !== previousSize) middlewareVersion++;
|
|
1802
|
+
}, { withTypes: () => addMiddleware });
|
|
1803
|
+
const getFinalMiddleware = (api) => {
|
|
1804
|
+
const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) => getOrInsertComputed(entry.applied, api, entry.middleware));
|
|
1805
|
+
return compose(...appliedMiddleware);
|
|
1806
|
+
};
|
|
1807
|
+
const isWithMiddleware = isAllOf(withMiddleware, matchInstance(instanceId));
|
|
1808
|
+
const middleware = (api) => (next) => {
|
|
1809
|
+
let appliedVersion = -1;
|
|
1810
|
+
let dispatch = next;
|
|
1811
|
+
return (action) => {
|
|
1812
|
+
if (isWithMiddleware(action)) {
|
|
1813
|
+
addMiddleware(...action.payload);
|
|
1814
|
+
return api.dispatch;
|
|
1815
|
+
}
|
|
1816
|
+
if (appliedVersion !== middlewareVersion) {
|
|
1817
|
+
dispatch = getFinalMiddleware(api)(next);
|
|
1818
|
+
appliedVersion = middlewareVersion;
|
|
1819
|
+
}
|
|
1820
|
+
return dispatch(action);
|
|
1821
|
+
};
|
|
1822
|
+
};
|
|
1823
|
+
return {
|
|
1824
|
+
middleware,
|
|
1825
|
+
addMiddleware,
|
|
1826
|
+
withMiddleware,
|
|
1827
|
+
instanceId
|
|
1828
|
+
};
|
|
2215
1829
|
};
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
return result;
|
|
2244
|
-
}
|
|
2245
|
-
}));
|
|
2246
|
-
var original = (state) => {
|
|
2247
|
-
if (!isStateProxy(state)) {
|
|
2248
|
-
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(25) : "original must be used on state Proxy");
|
|
2249
|
-
}
|
|
2250
|
-
return state[ORIGINAL_STATE];
|
|
1830
|
+
//#endregion
|
|
1831
|
+
//#region src/combineSlices.ts
|
|
1832
|
+
const isSliceLike = (maybeSliceLike) => "reducerPath" in maybeSliceLike && typeof maybeSliceLike.reducerPath === "string";
|
|
1833
|
+
const getReducers = (slices) => slices.flatMap((sliceOrMap) => isSliceLike(sliceOrMap) ? [[sliceOrMap.reducerPath, sliceOrMap.reducer]] : Object.entries(sliceOrMap));
|
|
1834
|
+
const ORIGINAL_STATE = Symbol.for("rtk-state-proxy-original");
|
|
1835
|
+
const isStateProxy = (value) => !!value && !!value[ORIGINAL_STATE];
|
|
1836
|
+
const createStateProxy = (stateProxyMap, state, reducerMap, initialStateCache) => getOrInsertComputed(stateProxyMap, state, () => new Proxy(state, { get: (target, prop, receiver) => {
|
|
1837
|
+
if (prop === ORIGINAL_STATE) return target;
|
|
1838
|
+
const result = Reflect.get(target, prop, receiver);
|
|
1839
|
+
if (typeof result === "undefined") {
|
|
1840
|
+
const cached = initialStateCache[prop];
|
|
1841
|
+
if (typeof cached !== "undefined") return cached;
|
|
1842
|
+
const reducer = reducerMap[prop];
|
|
1843
|
+
if (reducer) {
|
|
1844
|
+
const reducerResult = reducer(void 0, { type: nanoid() });
|
|
1845
|
+
if (typeof reducerResult === "undefined") throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(24) : `The slice reducer for key "${prop.toString()}" returned undefined when called for selector(). If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
|
|
1846
|
+
initialStateCache[prop] = reducerResult;
|
|
1847
|
+
return reducerResult;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
return result;
|
|
1851
|
+
} }));
|
|
1852
|
+
const original$1 = (state) => {
|
|
1853
|
+
if (!isStateProxy(state)) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(25) : "original must be used on state Proxy");
|
|
1854
|
+
return state[ORIGINAL_STATE];
|
|
2251
1855
|
};
|
|
2252
|
-
|
|
2253
|
-
|
|
1856
|
+
const emptyObject = {};
|
|
1857
|
+
const noopReducer = (state = emptyObject) => state;
|
|
2254
1858
|
function combineSlices(...slices) {
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
};
|
|
2286
|
-
}, {
|
|
2287
|
-
original
|
|
2288
|
-
});
|
|
2289
|
-
return Object.assign(combinedReducer, {
|
|
2290
|
-
inject,
|
|
2291
|
-
selector
|
|
2292
|
-
});
|
|
1859
|
+
const stateProxyMap = /* @__PURE__ */ new WeakMap();
|
|
1860
|
+
const reducerMap = Object.fromEntries(getReducers(slices));
|
|
1861
|
+
const getReducer = () => Object.keys(reducerMap).length ? combineReducers(reducerMap) : noopReducer;
|
|
1862
|
+
let reducer = getReducer();
|
|
1863
|
+
function combinedReducer(state, action) {
|
|
1864
|
+
return reducer(state, action);
|
|
1865
|
+
}
|
|
1866
|
+
combinedReducer.withLazyLoadedSlices = () => combinedReducer;
|
|
1867
|
+
const initialStateCache = {};
|
|
1868
|
+
const inject = (slice, config = {}) => {
|
|
1869
|
+
const { reducerPath, reducer: reducerToInject } = slice;
|
|
1870
|
+
const currentReducer = reducerMap[reducerPath];
|
|
1871
|
+
if (!config.overrideExisting && currentReducer && currentReducer !== reducerToInject) {
|
|
1872
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") console.error(`called \`inject\` to override already-existing reducer ${reducerPath} without specifying \`overrideExisting: true\``);
|
|
1873
|
+
return combinedReducer;
|
|
1874
|
+
}
|
|
1875
|
+
if (config.overrideExisting && currentReducer !== reducerToInject) delete initialStateCache[reducerPath];
|
|
1876
|
+
reducerMap[reducerPath] = reducerToInject;
|
|
1877
|
+
reducer = getReducer();
|
|
1878
|
+
return combinedReducer;
|
|
1879
|
+
};
|
|
1880
|
+
const selector = Object.assign(function makeSelector(selectorFn, selectState) {
|
|
1881
|
+
return function selector(state, ...args) {
|
|
1882
|
+
return selectorFn(createStateProxy(stateProxyMap, selectState ? selectState(state, ...args) : state, reducerMap, initialStateCache), ...args);
|
|
1883
|
+
};
|
|
1884
|
+
}, { original: original$1 });
|
|
1885
|
+
return Object.assign(combinedReducer, {
|
|
1886
|
+
inject,
|
|
1887
|
+
selector
|
|
1888
|
+
});
|
|
2293
1889
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
1890
|
+
//#endregion
|
|
1891
|
+
//#region src/formatProdErrorMessage.ts
|
|
2296
1892
|
function formatProdErrorMessage(code) {
|
|
2297
|
-
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
TaskAbortError,
|
|
2303
|
-
Tuple,
|
|
2304
|
-
addListener,
|
|
2305
|
-
asyncThunkCreator,
|
|
2306
|
-
autoBatchEnhancer,
|
|
2307
|
-
buildCreateSlice,
|
|
2308
|
-
clearAllListeners,
|
|
2309
|
-
combineSlices,
|
|
2310
|
-
configureStore,
|
|
2311
|
-
createAction,
|
|
2312
|
-
createActionCreatorInvariantMiddleware,
|
|
2313
|
-
createAsyncThunk,
|
|
2314
|
-
createDraftSafeSelector,
|
|
2315
|
-
createDraftSafeSelectorCreator,
|
|
2316
|
-
createDynamicMiddleware,
|
|
2317
|
-
createEntityAdapter,
|
|
2318
|
-
createImmutableStateInvariantMiddleware,
|
|
2319
|
-
createListenerMiddleware,
|
|
2320
|
-
produce as createNextState,
|
|
2321
|
-
createReducer,
|
|
2322
|
-
createSelector,
|
|
2323
|
-
createSelectorCreator,
|
|
2324
|
-
createSerializableStateInvariantMiddleware,
|
|
2325
|
-
createSlice,
|
|
2326
|
-
current,
|
|
2327
|
-
findNonSerializableValue,
|
|
2328
|
-
formatProdErrorMessage,
|
|
2329
|
-
freeze,
|
|
2330
|
-
isActionCreator,
|
|
2331
|
-
isAllOf,
|
|
2332
|
-
isAnyOf,
|
|
2333
|
-
isAsyncThunkAction,
|
|
2334
|
-
isDraft,
|
|
2335
|
-
isFSA as isFluxStandardAction,
|
|
2336
|
-
isFulfilled,
|
|
2337
|
-
isImmutableDefault,
|
|
2338
|
-
isPending,
|
|
2339
|
-
isPlain,
|
|
2340
|
-
isRejected,
|
|
2341
|
-
isRejectedWithValue,
|
|
2342
|
-
lruMemoize,
|
|
2343
|
-
miniSerializeError,
|
|
2344
|
-
nanoid,
|
|
2345
|
-
original2 as original,
|
|
2346
|
-
prepareAutoBatched,
|
|
2347
|
-
removeListener,
|
|
2348
|
-
unwrapResult,
|
|
2349
|
-
weakMapMemoize
|
|
2350
|
-
};
|
|
1893
|
+
return `Minified Redux Toolkit error #${code}; visit https://redux-toolkit.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
|
|
1894
|
+
}
|
|
1895
|
+
//#endregion
|
|
1896
|
+
export { ReducerType, SHOULD_AUTOBATCH, TaskAbortError, Tuple, addListener, asyncThunkCreator, autoBatchEnhancer, buildCreateSlice, clearAllListeners, combineSlices, configureStore, createAction, createActionCreatorInvariantMiddleware, createAsyncThunk, createDraftSafeSelector, createDraftSafeSelectorCreator, createDynamicMiddleware, createEntityAdapter, createImmutableStateInvariantMiddleware, createListenerMiddleware, createNextState, createReducer, createSelector, createSelectorCreator, createSerializableStateInvariantMiddleware, createSlice, current, findNonSerializableValue, formatProdErrorMessage, freeze, isActionCreator, isAllOf, isAnyOf, isAsyncThunkAction, isDraft, isFSA as isFluxStandardAction, isFulfilled, isImmutableDefault, isPending, isPlain, isRejected, isRejectedWithValue, lruMemoize, miniSerializeError, nanoid, original, prepareAutoBatched, removeListener, unwrapResult, weakMapMemoize };
|
|
1897
|
+
|
|
2351
1898
|
//# sourceMappingURL=redux-toolkit.legacy-esm.js.map
|