123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091 |
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- if (typeof b !== "function" && b !== null)
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- };
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
- to[j] = from[i];
- return to;
- };
- var __create = Object.create;
- var __defProp = Object.defineProperty;
- var __defProps = Object.defineProperties;
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
- var __getOwnPropNames = Object.getOwnPropertyNames;
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
- var __getProtoOf = Object.getPrototypeOf;
- var __hasOwnProp = Object.prototype.hasOwnProperty;
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
- var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
- var __spreadValues = function (a, b) {
- for (var prop in b || (b = {}))
- if (__hasOwnProp.call(b, prop))
- __defNormalProp(a, prop, b[prop]);
- if (__getOwnPropSymbols)
- for (var _i = 0, _c = __getOwnPropSymbols(b); _i < _c.length; _i++) {
- var prop = _c[_i];
- if (__propIsEnum.call(b, prop))
- __defNormalProp(a, prop, b[prop]);
- }
- return a;
- };
- var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
- var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };
- var __export = function (target, all) {
- for (var name in all)
- __defProp(target, name, { get: all[name], enumerable: true });
- };
- var __reExport = function (target, module2, desc) {
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
- var _loop_1 = function (key) {
- if (!__hasOwnProp.call(target, key) && key !== "default")
- __defProp(target, key, { get: function () { return module2[key]; }, enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
- };
- for (var _i = 0, _c = __getOwnPropNames(module2); _i < _c.length; _i++) {
- var key = _c[_i];
- _loop_1(key);
- }
- }
- return target;
- };
- var __toModule = function (module2) {
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: function () { return module2.default; }, enumerable: true } : { value: module2, enumerable: true })), module2);
- };
- var __async = function (__this, __arguments, generator) {
- return new Promise(function (resolve, reject) {
- var fulfilled = function (value) {
- try {
- step(generator.next(value));
- }
- catch (e) {
- reject(e);
- }
- };
- var rejected = function (value) {
- try {
- step(generator.throw(value));
- }
- catch (e) {
- reject(e);
- }
- };
- var step = function (x) { return x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); };
- step((generator = generator.apply(__this, __arguments)).next());
- });
- };
- // src/index.ts
- __markAsModule(exports);
- __export(exports, {
- EnhancerArray: function () { return EnhancerArray; },
- MiddlewareArray: function () { return MiddlewareArray; },
- SHOULD_AUTOBATCH: function () { return SHOULD_AUTOBATCH; },
- TaskAbortError: function () { return TaskAbortError; },
- addListener: function () { return addListener; },
- autoBatchEnhancer: function () { return autoBatchEnhancer; },
- clearAllListeners: function () { return clearAllListeners; },
- configureStore: function () { return configureStore; },
- createAction: function () { return createAction; },
- createActionCreatorInvariantMiddleware: function () { return createActionCreatorInvariantMiddleware; },
- createAsyncThunk: function () { return createAsyncThunk; },
- createDraftSafeSelector: function () { return createDraftSafeSelector; },
- createEntityAdapter: function () { return createEntityAdapter; },
- createImmutableStateInvariantMiddleware: function () { return createImmutableStateInvariantMiddleware; },
- createListenerMiddleware: function () { return createListenerMiddleware; },
- createNextState: function () { return import_immer6.default; },
- createReducer: function () { return createReducer; },
- createSelector: function () { return import_reselect2.createSelector; },
- createSerializableStateInvariantMiddleware: function () { return createSerializableStateInvariantMiddleware; },
- createSlice: function () { return createSlice; },
- current: function () { return import_immer6.current; },
- findNonSerializableValue: function () { return findNonSerializableValue; },
- freeze: function () { return import_immer6.freeze; },
- getDefaultMiddleware: function () { return getDefaultMiddleware; },
- getType: function () { return getType; },
- isAction: function () { return isAction; },
- isActionCreator: function () { return isActionCreator; },
- isAllOf: function () { return isAllOf; },
- isAnyOf: function () { return isAnyOf; },
- isAsyncThunkAction: function () { return isAsyncThunkAction; },
- isDraft: function () { return import_immer6.isDraft; },
- isFluxStandardAction: function () { return isFSA; },
- isFulfilled: function () { return isFulfilled; },
- isImmutableDefault: function () { return isImmutableDefault; },
- isPending: function () { return isPending; },
- isPlain: function () { return isPlain; },
- isPlainObject: function () { return isPlainObject; },
- isRejected: function () { return isRejected; },
- isRejectedWithValue: function () { return isRejectedWithValue; },
- miniSerializeError: function () { return miniSerializeError; },
- nanoid: function () { return nanoid; },
- original: function () { return import_immer6.original; },
- prepareAutoBatched: function () { return prepareAutoBatched; },
- removeListener: function () { return removeListener; },
- unwrapResult: function () { return unwrapResult; }
- });
- var import_immer5 = __toModule(require("immer"));
- __reExport(exports, __toModule(require("redux")));
- var import_immer6 = __toModule(require("immer"));
- var import_reselect2 = __toModule(require("reselect"));
- // src/createDraftSafeSelector.ts
- var import_immer = __toModule(require("immer"));
- var import_reselect = __toModule(require("reselect"));
- var createDraftSafeSelector = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- var selector = (0, import_reselect.createSelector).apply(void 0, args);
- var wrappedSelector = function (value) {
- var rest = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- rest[_i - 1] = arguments[_i];
- }
- return selector.apply(void 0, __spreadArray([(0, import_immer.isDraft)(value) ? (0, import_immer.current)(value) : value], rest));
- };
- return wrappedSelector;
- };
- // src/configureStore.ts
- var import_redux2 = __toModule(require("redux"));
- // src/devtoolsExtension.ts
- var import_redux = __toModule(require("redux"));
- var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function () {
- if (arguments.length === 0)
- return void 0;
- if (typeof arguments[0] === "object")
- return import_redux.compose;
- return import_redux.compose.apply(null, arguments);
- };
- var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function () {
- return function (noop2) {
- return noop2;
- };
- };
- // src/isPlainObject.ts
- function isPlainObject(value) {
- if (typeof value !== "object" || value === null)
- return false;
- var proto = Object.getPrototypeOf(value);
- if (proto === null)
- return true;
- var baseProto = proto;
- while (Object.getPrototypeOf(baseProto) !== null) {
- baseProto = Object.getPrototypeOf(baseProto);
- }
- return proto === baseProto;
- }
- // src/getDefaultMiddleware.ts
- var import_redux_thunk = __toModule(require("redux-thunk"));
- // src/tsHelpers.ts
- var hasMatchFunction = function (v) {
- return v && typeof v.match === "function";
- };
- // src/createAction.ts
- function createAction(type, prepareAction) {
- function actionCreator() {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- if (prepareAction) {
- var prepared = prepareAction.apply(void 0, args);
- if (!prepared) {
- throw new Error("prepareAction did not return an object");
- }
- return __spreadValues(__spreadValues({
- type: type,
- payload: prepared.payload
- }, "meta" in prepared && { meta: prepared.meta }), "error" in prepared && { error: prepared.error });
- }
- return { type: type, payload: args[0] };
- }
- actionCreator.toString = function () { return "" + type; };
- actionCreator.type = type;
- actionCreator.match = function (action) { return action.type === type; };
- return actionCreator;
- }
- function isAction(action) {
- return isPlainObject(action) && "type" in action;
- }
- function isActionCreator(action) {
- return typeof action === "function" && "type" in action && hasMatchFunction(action);
- }
- function isFSA(action) {
- return isAction(action) && typeof action.type === "string" && Object.keys(action).every(isValidKey);
- }
- function isValidKey(key) {
- return ["type", "payload", "error", "meta"].indexOf(key) > -1;
- }
- function getType(actionCreator) {
- return "" + actionCreator;
- }
- // src/actionCreatorInvariantMiddleware.ts
- function getMessage(type) {
- var splitType = type ? ("" + type).split("/") : [];
- var actionName = splitType[splitType.length - 1] || "actionCreator";
- return "Detected an action creator with type \"" + (type || "unknown") + "\" being dispatched. \nMake 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.";
- }
- function createActionCreatorInvariantMiddleware(options) {
- if (options === void 0) { options = {}; }
- if (false) {
- return function () { return function (next) { return function (action) { return next(action); }; }; };
- }
- var _c = options.isActionCreator, isActionCreator2 = _c === void 0 ? isActionCreator : _c;
- return function () { return function (next) { return function (action) {
- if (isActionCreator2(action)) {
- console.warn(getMessage(action.type));
- }
- return next(action);
- }; }; };
- }
- // src/utils.ts
- var import_immer2 = __toModule(require("immer"));
- function getTimeMeasureUtils(maxDelay, fnName) {
- var elapsed = 0;
- return {
- measureTime: function (fn) {
- var started = Date.now();
- try {
- return fn();
- }
- finally {
- var finished = Date.now();
- elapsed += finished - started;
- }
- },
- warnIfExceeded: function () {
- if (elapsed > maxDelay) {
- console.warn(fnName + " took " + elapsed + "ms, which is more than the warning threshold of " + maxDelay + "ms. \nIf 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.\nIt is disabled in production builds, so you don't need to worry about that.");
- }
- }
- };
- }
- var MiddlewareArray = /** @class */ (function (_super) {
- __extends(MiddlewareArray, _super);
- function MiddlewareArray() {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- var _this = _super.apply(this, args) || this;
- Object.setPrototypeOf(_this, MiddlewareArray.prototype);
- return _this;
- }
- Object.defineProperty(MiddlewareArray, Symbol.species, {
- get: function () {
- return MiddlewareArray;
- },
- enumerable: false,
- configurable: true
- });
- MiddlewareArray.prototype.concat = function () {
- var arr = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- arr[_i] = arguments[_i];
- }
- return _super.prototype.concat.apply(this, arr);
- };
- MiddlewareArray.prototype.prepend = function () {
- var arr = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- arr[_i] = arguments[_i];
- }
- if (arr.length === 1 && Array.isArray(arr[0])) {
- return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr[0].concat(this))))();
- }
- return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr.concat(this))))();
- };
- return MiddlewareArray;
- }(Array));
- var EnhancerArray = /** @class */ (function (_super) {
- __extends(EnhancerArray, _super);
- function EnhancerArray() {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- var _this = _super.apply(this, args) || this;
- Object.setPrototypeOf(_this, EnhancerArray.prototype);
- return _this;
- }
- Object.defineProperty(EnhancerArray, Symbol.species, {
- get: function () {
- return EnhancerArray;
- },
- enumerable: false,
- configurable: true
- });
- EnhancerArray.prototype.concat = function () {
- var arr = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- arr[_i] = arguments[_i];
- }
- return _super.prototype.concat.apply(this, arr);
- };
- EnhancerArray.prototype.prepend = function () {
- var arr = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- arr[_i] = arguments[_i];
- }
- if (arr.length === 1 && Array.isArray(arr[0])) {
- return new (EnhancerArray.bind.apply(EnhancerArray, __spreadArray([void 0], arr[0].concat(this))))();
- }
- return new (EnhancerArray.bind.apply(EnhancerArray, __spreadArray([void 0], arr.concat(this))))();
- };
- return EnhancerArray;
- }(Array));
- function freezeDraftable(val) {
- return (0, import_immer2.isDraftable)(val) ? (0, import_immer2.default)(val, function () {
- }) : val;
- }
- // src/immutableStateInvariantMiddleware.ts
- var isProduction = false;
- var prefix = "Invariant failed";
- function invariant(condition, message) {
- if (condition) {
- return;
- }
- if (isProduction) {
- throw new Error(prefix);
- }
- throw new Error(prefix + ": " + (message || ""));
- }
- function stringify(obj, serializer, indent, decycler) {
- return JSON.stringify(obj, getSerialize(serializer, decycler), indent);
- }
- function getSerialize(serializer, decycler) {
- var stack = [], keys = [];
- if (!decycler)
- decycler = function (_, value) {
- if (stack[0] === value)
- return "[Circular ~]";
- return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
- };
- return function (key, value) {
- if (stack.length > 0) {
- var thisPos = stack.indexOf(this);
- ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
- ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
- if (~stack.indexOf(value))
- value = decycler.call(this, key, value);
- }
- else
- stack.push(value);
- return serializer == null ? value : serializer.call(this, key, value);
- };
- }
- function isImmutableDefault(value) {
- return typeof value !== "object" || value == null || Object.isFrozen(value);
- }
- function trackForMutations(isImmutable, ignorePaths, obj) {
- var trackedProperties = trackProperties(isImmutable, ignorePaths, obj);
- return {
- detectMutations: function () {
- return detectMutations(isImmutable, ignorePaths, trackedProperties, obj);
- }
- };
- }
- function trackProperties(isImmutable, ignorePaths, obj, path, checkedObjects) {
- if (ignorePaths === void 0) { ignorePaths = []; }
- if (path === void 0) { path = ""; }
- if (checkedObjects === void 0) { checkedObjects = new Set(); }
- var tracked = { value: obj };
- if (!isImmutable(obj) && !checkedObjects.has(obj)) {
- checkedObjects.add(obj);
- tracked.children = {};
- for (var key in obj) {
- var childPath = path ? path + "." + key : key;
- if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
- continue;
- }
- tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
- }
- }
- return tracked;
- }
- function detectMutations(isImmutable, ignoredPaths, trackedProperty, obj, sameParentRef, path) {
- if (ignoredPaths === void 0) { ignoredPaths = []; }
- if (sameParentRef === void 0) { sameParentRef = false; }
- if (path === void 0) { path = ""; }
- var prevObj = trackedProperty ? trackedProperty.value : void 0;
- var sameRef = prevObj === obj;
- if (sameParentRef && !sameRef && !Number.isNaN(obj)) {
- return { wasMutated: true, path: path };
- }
- if (isImmutable(prevObj) || isImmutable(obj)) {
- return { wasMutated: false };
- }
- var keysToDetect = {};
- for (var key in trackedProperty.children) {
- keysToDetect[key] = true;
- }
- for (var key in obj) {
- keysToDetect[key] = true;
- }
- var hasIgnoredPaths = ignoredPaths.length > 0;
- var _loop_2 = function (key) {
- var nestedPath = path ? path + "." + key : key;
- if (hasIgnoredPaths) {
- var hasMatches = ignoredPaths.some(function (ignored) {
- if (ignored instanceof RegExp) {
- return ignored.test(nestedPath);
- }
- return nestedPath === ignored;
- });
- if (hasMatches) {
- return "continue";
- }
- }
- var result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath);
- if (result.wasMutated) {
- return { value: result };
- }
- };
- for (var key in keysToDetect) {
- var state_1 = _loop_2(key);
- if (typeof state_1 === "object")
- return state_1.value;
- }
- return { wasMutated: false };
- }
- function createImmutableStateInvariantMiddleware(options) {
- if (options === void 0) { options = {}; }
- if (false) {
- return function () { return function (next) { return function (action) { return next(action); }; }; };
- }
- var _c = options.isImmutable, isImmutable = _c === void 0 ? isImmutableDefault : _c, ignoredPaths = options.ignoredPaths, _d = options.warnAfter, warnAfter = _d === void 0 ? 32 : _d, ignore = options.ignore;
- ignoredPaths = ignoredPaths || ignore;
- var track = trackForMutations.bind(null, isImmutable, ignoredPaths);
- return function (_c) {
- var getState = _c.getState;
- var state = getState();
- var tracker = track(state);
- var result;
- return function (next) { return function (action) {
- var measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
- measureUtils.measureTime(function () {
- state = getState();
- result = tracker.detectMutations();
- tracker = track(state);
- invariant(!result.wasMutated, "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)");
- });
- var dispatchedAction = next(action);
- measureUtils.measureTime(function () {
- state = getState();
- result = tracker.detectMutations();
- tracker = track(state);
- result.wasMutated && invariant(!result.wasMutated, "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)");
- });
- measureUtils.warnIfExceeded();
- return dispatchedAction;
- }; };
- };
- }
- // src/serializableStateInvariantMiddleware.ts
- function isPlain(val) {
- var type = typeof val;
- return val == null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
- }
- function findNonSerializableValue(value, path, isSerializable, getEntries, ignoredPaths, cache) {
- if (path === void 0) { path = ""; }
- if (isSerializable === void 0) { isSerializable = isPlain; }
- if (ignoredPaths === void 0) { ignoredPaths = []; }
- var foundNestedSerializable;
- if (!isSerializable(value)) {
- return {
- keyPath: path || "<root>",
- value: value
- };
- }
- if (typeof value !== "object" || value === null) {
- return false;
- }
- if (cache == null ? void 0 : cache.has(value))
- return false;
- var entries = getEntries != null ? getEntries(value) : Object.entries(value);
- var hasIgnoredPaths = ignoredPaths.length > 0;
- var _loop_3 = function (key, nestedValue) {
- var nestedPath = path ? path + "." + key : key;
- if (hasIgnoredPaths) {
- var hasMatches = ignoredPaths.some(function (ignored) {
- if (ignored instanceof RegExp) {
- return ignored.test(nestedPath);
- }
- return nestedPath === ignored;
- });
- if (hasMatches) {
- return "continue";
- }
- }
- if (!isSerializable(nestedValue)) {
- return { value: {
- keyPath: nestedPath,
- value: nestedValue
- } };
- }
- if (typeof nestedValue === "object") {
- foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
- if (foundNestedSerializable) {
- return { value: foundNestedSerializable };
- }
- }
- };
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
- var _c = entries_1[_i], key = _c[0], nestedValue = _c[1];
- var state_2 = _loop_3(key, nestedValue);
- if (typeof state_2 === "object")
- return state_2.value;
- }
- if (cache && isNestedFrozen(value))
- cache.add(value);
- return false;
- }
- function isNestedFrozen(value) {
- if (!Object.isFrozen(value))
- return false;
- for (var _i = 0, _c = Object.values(value); _i < _c.length; _i++) {
- var nestedValue = _c[_i];
- if (typeof nestedValue !== "object" || nestedValue === null)
- continue;
- if (!isNestedFrozen(nestedValue))
- return false;
- }
- return true;
- }
- function createSerializableStateInvariantMiddleware(options) {
- if (options === void 0) { options = {}; }
- if (false) {
- return function () { return function (next) { return function (action) { return next(action); }; }; };
- }
- var _c = options.isSerializable, isSerializable = _c === void 0 ? isPlain : _c, getEntries = options.getEntries, _d = options.ignoredActions, ignoredActions = _d === void 0 ? [] : _d, _e = options.ignoredActionPaths, ignoredActionPaths = _e === void 0 ? ["meta.arg", "meta.baseQueryMeta"] : _e, _f = options.ignoredPaths, ignoredPaths = _f === void 0 ? [] : _f, _g = options.warnAfter, warnAfter = _g === void 0 ? 32 : _g, _h = options.ignoreState, ignoreState = _h === void 0 ? false : _h, _j = options.ignoreActions, ignoreActions = _j === void 0 ? false : _j, _k = options.disableCache, disableCache = _k === void 0 ? false : _k;
- var cache = !disableCache && WeakSet ? new WeakSet() : void 0;
- return function (storeAPI) { return function (next) { return function (action) {
- var result = next(action);
- var measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
- if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) {
- measureUtils.measureTime(function () {
- var foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
- if (foundActionNonSerializableValue) {
- var keyPath = foundActionNonSerializableValue.keyPath, value = foundActionNonSerializableValue.value;
- 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)");
- }
- });
- }
- if (!ignoreState) {
- measureUtils.measureTime(function () {
- var state = storeAPI.getState();
- var foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths, cache);
- if (foundStateNonSerializableValue) {
- var keyPath = foundStateNonSerializableValue.keyPath, value = foundStateNonSerializableValue.value;
- console.error("A non-serializable value was detected in the state, in the path: `" + keyPath + "`. Value:", value, "\nTake a look at the reducer(s) handling this action type: " + action.type + ".\n(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)");
- }
- });
- measureUtils.warnIfExceeded();
- }
- return result;
- }; }; };
- }
- // src/getDefaultMiddleware.ts
- function isBoolean(x) {
- return typeof x === "boolean";
- }
- function curryGetDefaultMiddleware() {
- return function curriedGetDefaultMiddleware(options) {
- return getDefaultMiddleware(options);
- };
- }
- function getDefaultMiddleware(options) {
- if (options === void 0) { options = {}; }
- var _c = options.thunk, thunk = _c === void 0 ? true : _c, _d = options.immutableCheck, immutableCheck = _d === void 0 ? true : _d, _e = options.serializableCheck, serializableCheck = _e === void 0 ? true : _e, _f = options.actionCreatorCheck, actionCreatorCheck = _f === void 0 ? true : _f;
- var middlewareArray = new MiddlewareArray();
- if (thunk) {
- if (isBoolean(thunk)) {
- middlewareArray.push(import_redux_thunk.default);
- }
- else {
- middlewareArray.push(import_redux_thunk.default.withExtraArgument(thunk.extraArgument));
- }
- }
- if (true) {
- if (immutableCheck) {
- var immutableOptions = {};
- if (!isBoolean(immutableCheck)) {
- immutableOptions = immutableCheck;
- }
- middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
- }
- if (serializableCheck) {
- var serializableOptions = {};
- if (!isBoolean(serializableCheck)) {
- serializableOptions = serializableCheck;
- }
- middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
- }
- if (actionCreatorCheck) {
- var actionCreatorOptions = {};
- if (!isBoolean(actionCreatorCheck)) {
- actionCreatorOptions = actionCreatorCheck;
- }
- middlewareArray.unshift(createActionCreatorInvariantMiddleware(actionCreatorOptions));
- }
- }
- return middlewareArray;
- }
- // src/configureStore.ts
- var IS_PRODUCTION = false;
- function configureStore(options) {
- var curriedGetDefaultMiddleware = curryGetDefaultMiddleware();
- var _c = options || {}, _d = _c.reducer, reducer = _d === void 0 ? void 0 : _d, _e = _c.middleware, middleware = _e === void 0 ? curriedGetDefaultMiddleware() : _e, _f = _c.devTools, devTools = _f === void 0 ? true : _f, _g = _c.preloadedState, preloadedState = _g === void 0 ? void 0 : _g, _h = _c.enhancers, enhancers = _h === void 0 ? void 0 : _h;
- var rootReducer;
- if (typeof reducer === "function") {
- rootReducer = reducer;
- }
- else if (isPlainObject(reducer)) {
- rootReducer = (0, import_redux2.combineReducers)(reducer);
- }
- else {
- throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');
- }
- var finalMiddleware = middleware;
- if (typeof finalMiddleware === "function") {
- finalMiddleware = finalMiddleware(curriedGetDefaultMiddleware);
- if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
- throw new Error("when using a middleware builder function, an array of middleware must be returned");
- }
- }
- if (!IS_PRODUCTION && finalMiddleware.some(function (item) { return typeof item !== "function"; })) {
- throw new Error("each middleware provided to configureStore must be a function");
- }
- var middlewareEnhancer = (0, import_redux2.applyMiddleware).apply(void 0, finalMiddleware);
- var finalCompose = import_redux2.compose;
- if (devTools) {
- finalCompose = composeWithDevTools(__spreadValues({
- trace: !IS_PRODUCTION
- }, typeof devTools === "object" && devTools));
- }
- var defaultEnhancers = new EnhancerArray(middlewareEnhancer);
- var storeEnhancers = defaultEnhancers;
- if (Array.isArray(enhancers)) {
- storeEnhancers = __spreadArray([middlewareEnhancer], enhancers);
- }
- else if (typeof enhancers === "function") {
- storeEnhancers = enhancers(defaultEnhancers);
- }
- var composedEnhancer = finalCompose.apply(void 0, storeEnhancers);
- return (0, import_redux2.createStore)(rootReducer, preloadedState, composedEnhancer);
- }
- // src/createReducer.ts
- var import_immer3 = __toModule(require("immer"));
- // src/mapBuilders.ts
- function executeReducerBuilderCallback(builderCallback) {
- var actionsMap = {};
- var actionMatchers = [];
- var defaultCaseReducer;
- var builder = {
- addCase: function (typeOrActionCreator, reducer) {
- if (true) {
- if (actionMatchers.length > 0) {
- throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");
- }
- if (defaultCaseReducer) {
- throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`");
- }
- }
- var type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
- if (!type) {
- throw new Error("`builder.addCase` cannot be called with an empty action type");
- }
- if (type in actionsMap) {
- throw new Error("`builder.addCase` cannot be called with two reducers for the same action type");
- }
- actionsMap[type] = reducer;
- return builder;
- },
- addMatcher: function (matcher, reducer) {
- if (true) {
- if (defaultCaseReducer) {
- throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
- }
- }
- actionMatchers.push({ matcher: matcher, reducer: reducer });
- return builder;
- },
- addDefaultCase: function (reducer) {
- if (true) {
- if (defaultCaseReducer) {
- throw new Error("`builder.addDefaultCase` can only be called once");
- }
- }
- defaultCaseReducer = reducer;
- return builder;
- }
- };
- builderCallback(builder);
- return [actionsMap, actionMatchers, defaultCaseReducer];
- }
- // src/createReducer.ts
- function isStateFunction(x) {
- return typeof x === "function";
- }
- var hasWarnedAboutObjectNotation = false;
- function createReducer(initialState, mapOrBuilderCallback, actionMatchers, defaultCaseReducer) {
- if (actionMatchers === void 0) { actionMatchers = []; }
- if (true) {
- if (typeof mapOrBuilderCallback === "object") {
- if (!hasWarnedAboutObjectNotation) {
- hasWarnedAboutObjectNotation = true;
- console.warn("The object notation for `createReducer` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
- }
- }
- }
- var _c = typeof mapOrBuilderCallback === "function" ? executeReducerBuilderCallback(mapOrBuilderCallback) : [mapOrBuilderCallback, actionMatchers, defaultCaseReducer], actionsMap = _c[0], finalActionMatchers = _c[1], finalDefaultCaseReducer = _c[2];
- var getInitialState;
- if (isStateFunction(initialState)) {
- getInitialState = function () { return freezeDraftable(initialState()); };
- }
- else {
- var frozenInitialState_1 = freezeDraftable(initialState);
- getInitialState = function () { return frozenInitialState_1; };
- }
- function reducer(state, action) {
- if (state === void 0) { state = getInitialState(); }
- var caseReducers = __spreadArray([
- actionsMap[action.type]
- ], finalActionMatchers.filter(function (_c) {
- var matcher = _c.matcher;
- return matcher(action);
- }).map(function (_c) {
- var reducer2 = _c.reducer;
- return reducer2;
- }));
- if (caseReducers.filter(function (cr) { return !!cr; }).length === 0) {
- caseReducers = [finalDefaultCaseReducer];
- }
- return caseReducers.reduce(function (previousState, caseReducer) {
- if (caseReducer) {
- if ((0, import_immer3.isDraft)(previousState)) {
- var draft = previousState;
- var result = caseReducer(draft, action);
- if (result === void 0) {
- return previousState;
- }
- return result;
- }
- else if (!(0, import_immer3.isDraftable)(previousState)) {
- var result = caseReducer(previousState, action);
- if (result === void 0) {
- if (previousState === null) {
- return previousState;
- }
- throw Error("A case reducer on a non-draftable value must not return undefined");
- }
- return result;
- }
- else {
- return (0, import_immer3.default)(previousState, function (draft) {
- return caseReducer(draft, action);
- });
- }
- }
- return previousState;
- }, state);
- }
- reducer.getInitialState = getInitialState;
- return reducer;
- }
- // src/createSlice.ts
- var hasWarnedAboutObjectNotation2 = false;
- function getType2(slice, actionKey) {
- return slice + "/" + actionKey;
- }
- function createSlice(options) {
- var name = options.name;
- if (!name) {
- throw new Error("`name` is a required option for createSlice");
- }
- if (typeof process !== "undefined" && true) {
- if (options.initialState === void 0) {
- console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
- }
- }
- var initialState = typeof options.initialState == "function" ? options.initialState : freezeDraftable(options.initialState);
- var reducers = options.reducers || {};
- var reducerNames = Object.keys(reducers);
- var sliceCaseReducersByName = {};
- var sliceCaseReducersByType = {};
- var actionCreators = {};
- reducerNames.forEach(function (reducerName) {
- var maybeReducerWithPrepare = reducers[reducerName];
- var type = getType2(name, reducerName);
- var caseReducer;
- var prepareCallback;
- if ("reducer" in maybeReducerWithPrepare) {
- caseReducer = maybeReducerWithPrepare.reducer;
- prepareCallback = maybeReducerWithPrepare.prepare;
- }
- else {
- caseReducer = maybeReducerWithPrepare;
- }
- sliceCaseReducersByName[reducerName] = caseReducer;
- sliceCaseReducersByType[type] = caseReducer;
- actionCreators[reducerName] = prepareCallback ? createAction(type, prepareCallback) : createAction(type);
- });
- function buildReducer() {
- if (true) {
- if (typeof options.extraReducers === "object") {
- if (!hasWarnedAboutObjectNotation2) {
- hasWarnedAboutObjectNotation2 = true;
- console.warn("The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
- }
- }
- }
- var _c = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers], _d = _c[0], extraReducers = _d === void 0 ? {} : _d, _e = _c[1], actionMatchers = _e === void 0 ? [] : _e, _f = _c[2], defaultCaseReducer = _f === void 0 ? void 0 : _f;
- var finalCaseReducers = __spreadValues(__spreadValues({}, extraReducers), sliceCaseReducersByType);
- return createReducer(initialState, function (builder) {
- for (var key in finalCaseReducers) {
- builder.addCase(key, finalCaseReducers[key]);
- }
- for (var _i = 0, actionMatchers_1 = actionMatchers; _i < actionMatchers_1.length; _i++) {
- var m = actionMatchers_1[_i];
- builder.addMatcher(m.matcher, m.reducer);
- }
- if (defaultCaseReducer) {
- builder.addDefaultCase(defaultCaseReducer);
- }
- });
- }
- var _reducer;
- return {
- name: name,
- reducer: function (state, action) {
- if (!_reducer)
- _reducer = buildReducer();
- return _reducer(state, action);
- },
- actions: actionCreators,
- caseReducers: sliceCaseReducersByName,
- getInitialState: function () {
- if (!_reducer)
- _reducer = buildReducer();
- return _reducer.getInitialState();
- }
- };
- }
- // src/entities/entity_state.ts
- function getInitialEntityState() {
- return {
- ids: [],
- entities: {}
- };
- }
- function createInitialStateFactory() {
- function getInitialState(additionalState) {
- if (additionalState === void 0) { additionalState = {}; }
- return Object.assign(getInitialEntityState(), additionalState);
- }
- return { getInitialState: getInitialState };
- }
- // src/entities/state_selectors.ts
- function createSelectorsFactory() {
- function getSelectors(selectState) {
- var selectIds = function (state) { return state.ids; };
- var selectEntities = function (state) { return state.entities; };
- var selectAll = createDraftSafeSelector(selectIds, selectEntities, function (ids, entities) { return ids.map(function (id) { return entities[id]; }); });
- var selectId = function (_, id) { return id; };
- var selectById = function (entities, id) { return entities[id]; };
- var selectTotal = createDraftSafeSelector(selectIds, function (ids) { return ids.length; });
- if (!selectState) {
- return {
- selectIds: selectIds,
- selectEntities: selectEntities,
- selectAll: selectAll,
- selectTotal: selectTotal,
- selectById: createDraftSafeSelector(selectEntities, selectId, selectById)
- };
- }
- var selectGlobalizedEntities = createDraftSafeSelector(selectState, selectEntities);
- return {
- selectIds: createDraftSafeSelector(selectState, selectIds),
- selectEntities: selectGlobalizedEntities,
- selectAll: createDraftSafeSelector(selectState, selectAll),
- selectTotal: createDraftSafeSelector(selectState, selectTotal),
- selectById: createDraftSafeSelector(selectGlobalizedEntities, selectId, selectById)
- };
- }
- return { getSelectors: getSelectors };
- }
- // src/entities/state_adapter.ts
- var import_immer4 = __toModule(require("immer"));
- function createSingleArgumentStateOperator(mutator) {
- var operator = createStateOperator(function (_, state) { return mutator(state); });
- return function operation(state) {
- return operator(state, void 0);
- };
- }
- function createStateOperator(mutator) {
- return function operation(state, arg) {
- function isPayloadActionArgument(arg2) {
- return isFSA(arg2);
- }
- var runMutator = function (draft) {
- if (isPayloadActionArgument(arg)) {
- mutator(arg.payload, draft);
- }
- else {
- mutator(arg, draft);
- }
- };
- if ((0, import_immer4.isDraft)(state)) {
- runMutator(state);
- return state;
- }
- else {
- return (0, import_immer4.default)(state, runMutator);
- }
- };
- }
- // src/entities/utils.ts
- function selectIdValue(entity, selectId) {
- var key = selectId(entity);
- if (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());
- }
- return key;
- }
- function ensureEntitiesArray(entities) {
- if (!Array.isArray(entities)) {
- entities = Object.values(entities);
- }
- return entities;
- }
- function splitAddedUpdatedEntities(newEntities, selectId, state) {
- newEntities = ensureEntitiesArray(newEntities);
- var added = [];
- var updated = [];
- for (var _i = 0, newEntities_1 = newEntities; _i < newEntities_1.length; _i++) {
- var entity = newEntities_1[_i];
- var id = selectIdValue(entity, selectId);
- if (id in state.entities) {
- updated.push({ id: id, changes: entity });
- }
- else {
- added.push(entity);
- }
- }
- return [added, updated];
- }
- // src/entities/unsorted_state_adapter.ts
- function createUnsortedStateAdapter(selectId) {
- function addOneMutably(entity, state) {
- var key = selectIdValue(entity, selectId);
- if (key in state.entities) {
- return;
- }
- state.ids.push(key);
- state.entities[key] = entity;
- }
- function addManyMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- for (var _i = 0, newEntities_2 = newEntities; _i < newEntities_2.length; _i++) {
- var entity = newEntities_2[_i];
- addOneMutably(entity, state);
- }
- }
- function setOneMutably(entity, state) {
- var key = selectIdValue(entity, selectId);
- if (!(key in state.entities)) {
- state.ids.push(key);
- }
- state.entities[key] = entity;
- }
- function setManyMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- for (var _i = 0, newEntities_3 = newEntities; _i < newEntities_3.length; _i++) {
- var entity = newEntities_3[_i];
- setOneMutably(entity, state);
- }
- }
- function setAllMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- state.ids = [];
- state.entities = {};
- addManyMutably(newEntities, state);
- }
- function removeOneMutably(key, state) {
- return removeManyMutably([key], state);
- }
- function removeManyMutably(keys, state) {
- var didMutate = false;
- keys.forEach(function (key) {
- if (key in state.entities) {
- delete state.entities[key];
- didMutate = true;
- }
- });
- if (didMutate) {
- state.ids = state.ids.filter(function (id) { return id in state.entities; });
- }
- }
- function removeAllMutably(state) {
- Object.assign(state, {
- ids: [],
- entities: {}
- });
- }
- function takeNewKey(keys, update, state) {
- var original2 = state.entities[update.id];
- var updated = Object.assign({}, original2, update.changes);
- var newKey = selectIdValue(updated, selectId);
- var hasNewKey = newKey !== update.id;
- if (hasNewKey) {
- keys[update.id] = newKey;
- delete state.entities[update.id];
- }
- state.entities[newKey] = updated;
- return hasNewKey;
- }
- function updateOneMutably(update, state) {
- return updateManyMutably([update], state);
- }
- function updateManyMutably(updates, state) {
- var newKeys = {};
- var updatesPerEntity = {};
- updates.forEach(function (update) {
- if (update.id in state.entities) {
- updatesPerEntity[update.id] = {
- id: update.id,
- changes: __spreadValues(__spreadValues({}, updatesPerEntity[update.id] ? updatesPerEntity[update.id].changes : null), update.changes)
- };
- }
- });
- updates = Object.values(updatesPerEntity);
- var didMutateEntities = updates.length > 0;
- if (didMutateEntities) {
- var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
- if (didMutateIds) {
- state.ids = Object.keys(state.entities);
- }
- }
- }
- function upsertOneMutably(entity, state) {
- return upsertManyMutably([entity], state);
- }
- function upsertManyMutably(newEntities, state) {
- var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
- updateManyMutably(updated, state);
- addManyMutably(added, state);
- }
- return {
- removeAll: createSingleArgumentStateOperator(removeAllMutably),
- addOne: createStateOperator(addOneMutably),
- addMany: createStateOperator(addManyMutably),
- setOne: createStateOperator(setOneMutably),
- setMany: createStateOperator(setManyMutably),
- setAll: createStateOperator(setAllMutably),
- updateOne: createStateOperator(updateOneMutably),
- updateMany: createStateOperator(updateManyMutably),
- upsertOne: createStateOperator(upsertOneMutably),
- upsertMany: createStateOperator(upsertManyMutably),
- removeOne: createStateOperator(removeOneMutably),
- removeMany: createStateOperator(removeManyMutably)
- };
- }
- // src/entities/sorted_state_adapter.ts
- function createSortedStateAdapter(selectId, sort) {
- var _c = createUnsortedStateAdapter(selectId), removeOne = _c.removeOne, removeMany = _c.removeMany, removeAll = _c.removeAll;
- function addOneMutably(entity, state) {
- return addManyMutably([entity], state);
- }
- function addManyMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- var models = newEntities.filter(function (model) { return !(selectIdValue(model, selectId) in state.entities); });
- if (models.length !== 0) {
- merge(models, state);
- }
- }
- function setOneMutably(entity, state) {
- return setManyMutably([entity], state);
- }
- function setManyMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- if (newEntities.length !== 0) {
- merge(newEntities, state);
- }
- }
- function setAllMutably(newEntities, state) {
- newEntities = ensureEntitiesArray(newEntities);
- state.entities = {};
- state.ids = [];
- addManyMutably(newEntities, state);
- }
- function updateOneMutably(update, state) {
- return updateManyMutably([update], state);
- }
- function updateManyMutably(updates, state) {
- var appliedUpdates = false;
- for (var _i = 0, updates_1 = updates; _i < updates_1.length; _i++) {
- var update = updates_1[_i];
- var entity = state.entities[update.id];
- if (!entity) {
- continue;
- }
- appliedUpdates = true;
- Object.assign(entity, update.changes);
- var newId = selectId(entity);
- if (update.id !== newId) {
- delete state.entities[update.id];
- state.entities[newId] = entity;
- }
- }
- if (appliedUpdates) {
- resortEntities(state);
- }
- }
- function upsertOneMutably(entity, state) {
- return upsertManyMutably([entity], state);
- }
- function upsertManyMutably(newEntities, state) {
- var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
- updateManyMutably(updated, state);
- addManyMutably(added, state);
- }
- function areArraysEqual(a, b) {
- if (a.length !== b.length) {
- return false;
- }
- for (var i = 0; i < a.length && i < b.length; i++) {
- if (a[i] === b[i]) {
- continue;
- }
- return false;
- }
- return true;
- }
- function merge(models, state) {
- models.forEach(function (model) {
- state.entities[selectId(model)] = model;
- });
- resortEntities(state);
- }
- function resortEntities(state) {
- var allEntities = Object.values(state.entities);
- allEntities.sort(sort);
- var newSortedIds = allEntities.map(selectId);
- var ids = state.ids;
- if (!areArraysEqual(ids, newSortedIds)) {
- state.ids = newSortedIds;
- }
- }
- return {
- removeOne: removeOne,
- removeMany: removeMany,
- removeAll: removeAll,
- addOne: createStateOperator(addOneMutably),
- updateOne: createStateOperator(updateOneMutably),
- upsertOne: createStateOperator(upsertOneMutably),
- setOne: createStateOperator(setOneMutably),
- setMany: createStateOperator(setManyMutably),
- setAll: createStateOperator(setAllMutably),
- addMany: createStateOperator(addManyMutably),
- updateMany: createStateOperator(updateManyMutably),
- upsertMany: createStateOperator(upsertManyMutably)
- };
- }
- // src/entities/create_adapter.ts
- function createEntityAdapter(options) {
- if (options === void 0) { options = {}; }
- var _c = __spreadValues({
- sortComparer: false,
- selectId: function (instance) { return instance.id; }
- }, options), selectId = _c.selectId, sortComparer = _c.sortComparer;
- var stateFactory = createInitialStateFactory();
- var selectorsFactory = createSelectorsFactory();
- var stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
- return __spreadValues(__spreadValues(__spreadValues({
- selectId: selectId,
- sortComparer: sortComparer
- }, stateFactory), selectorsFactory), stateAdapter);
- }
- // src/nanoid.ts
- var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
- var nanoid = function (size) {
- if (size === void 0) { size = 21; }
- var id = "";
- var i = size;
- while (i--) {
- id += urlAlphabet[Math.random() * 64 | 0];
- }
- return id;
- };
- // src/createAsyncThunk.ts
- var commonProperties = [
- "name",
- "message",
- "stack",
- "code"
- ];
- var RejectWithValue = /** @class */ (function () {
- function RejectWithValue(payload, meta) {
- this.payload = payload;
- this.meta = meta;
- }
- return RejectWithValue;
- }());
- var FulfillWithMeta = /** @class */ (function () {
- function FulfillWithMeta(payload, meta) {
- this.payload = payload;
- this.meta = meta;
- }
- return FulfillWithMeta;
- }());
- var miniSerializeError = function (value) {
- if (typeof value === "object" && value !== null) {
- var simpleError = {};
- for (var _i = 0, commonProperties_1 = commonProperties; _i < commonProperties_1.length; _i++) {
- var property = commonProperties_1[_i];
- if (typeof value[property] === "string") {
- simpleError[property] = value[property];
- }
- }
- return simpleError;
- }
- return { message: String(value) };
- };
- var createAsyncThunk = (function () {
- function createAsyncThunk2(typePrefix, payloadCreator, options) {
- var fulfilled = createAction(typePrefix + "/fulfilled", function (payload, requestId, arg, meta) { return ({
- payload: payload,
- meta: __spreadProps(__spreadValues({}, meta || {}), {
- arg: arg,
- requestId: requestId,
- requestStatus: "fulfilled"
- })
- }); });
- var pending = createAction(typePrefix + "/pending", function (requestId, arg, meta) { return ({
- payload: void 0,
- meta: __spreadProps(__spreadValues({}, meta || {}), {
- arg: arg,
- requestId: requestId,
- requestStatus: "pending"
- })
- }); });
- var rejected = createAction(typePrefix + "/rejected", function (error, requestId, arg, payload, meta) { return ({
- payload: payload,
- error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
- meta: __spreadProps(__spreadValues({}, meta || {}), {
- arg: arg,
- requestId: requestId,
- rejectedWithValue: !!payload,
- requestStatus: "rejected",
- aborted: (error == null ? void 0 : error.name) === "AbortError",
- condition: (error == null ? void 0 : error.name) === "ConditionError"
- })
- }); });
- var displayedWarning = false;
- var AC = typeof AbortController !== "undefined" ? AbortController : /** @class */ (function () {
- function class_1() {
- this.signal = {
- aborted: false,
- addEventListener: function () {
- },
- dispatchEvent: function () {
- return false;
- },
- onabort: function () {
- },
- removeEventListener: function () {
- },
- reason: void 0,
- throwIfAborted: function () {
- }
- };
- }
- class_1.prototype.abort = function () {
- if (true) {
- if (!displayedWarning) {
- displayedWarning = true;
- console.info("This platform does not implement AbortController. \nIf you want to use the AbortController to react to `abort` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.");
- }
- }
- };
- return class_1;
- }());
- function actionCreator(arg) {
- return function (dispatch, getState, extra) {
- var requestId = (options == null ? void 0 : options.idGenerator) ? options.idGenerator(arg) : nanoid();
- var abortController = new AC();
- var abortReason;
- var started = false;
- function abort(reason) {
- abortReason = reason;
- abortController.abort();
- }
- var promise2 = function () {
- return __async(this, null, function () {
- var _a, _b, finalAction, conditionResult, abortedPromise, err_1, skipDispatch;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- _c.trys.push([0, 4, , 5]);
- conditionResult = (_a = options == null ? void 0 : options.condition) == null ? void 0 : _a.call(options, arg, { getState: getState, extra: extra });
- if (!isThenable(conditionResult)) return [3 /*break*/, 2];
- return [4 /*yield*/, conditionResult];
- case 1:
- conditionResult = _c.sent();
- _c.label = 2;
- case 2:
- if (conditionResult === false || abortController.signal.aborted) {
- throw {
- name: "ConditionError",
- message: "Aborted due to condition callback returning false."
- };
- }
- started = true;
- abortedPromise = new Promise(function (_, reject) { return abortController.signal.addEventListener("abort", function () { return reject({
- name: "AbortError",
- message: abortReason || "Aborted"
- }); }); });
- dispatch(pending(requestId, arg, (_b = options == null ? void 0 : options.getPendingMeta) == null ? void 0 : _b.call(options, { requestId: requestId, arg: arg }, { getState: getState, extra: extra })));
- return [4 /*yield*/, Promise.race([
- abortedPromise,
- Promise.resolve(payloadCreator(arg, {
- dispatch: dispatch,
- getState: getState,
- extra: extra,
- requestId: requestId,
- signal: abortController.signal,
- abort: abort,
- rejectWithValue: function (value, meta) {
- return new RejectWithValue(value, meta);
- },
- fulfillWithValue: function (value, meta) {
- return new FulfillWithMeta(value, meta);
- }
- })).then(function (result) {
- if (result instanceof RejectWithValue) {
- throw result;
- }
- if (result instanceof FulfillWithMeta) {
- return fulfilled(result.payload, requestId, arg, result.meta);
- }
- return fulfilled(result, requestId, arg);
- })
- ])];
- case 3:
- finalAction = _c.sent();
- return [3 /*break*/, 5];
- case 4:
- err_1 = _c.sent();
- finalAction = err_1 instanceof RejectWithValue ? rejected(null, requestId, arg, err_1.payload, err_1.meta) : rejected(err_1, requestId, arg);
- return [3 /*break*/, 5];
- case 5:
- skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
- if (!skipDispatch) {
- dispatch(finalAction);
- }
- return [2 /*return*/, finalAction];
- }
- });
- });
- }();
- return Object.assign(promise2, {
- abort: abort,
- requestId: requestId,
- arg: arg,
- unwrap: function () {
- return promise2.then(unwrapResult);
- }
- });
- };
- }
- return Object.assign(actionCreator, {
- pending: pending,
- rejected: rejected,
- fulfilled: fulfilled,
- typePrefix: typePrefix
- });
- }
- createAsyncThunk2.withTypes = function () { return createAsyncThunk2; };
- return createAsyncThunk2;
- })();
- function unwrapResult(action) {
- if (action.meta && action.meta.rejectedWithValue) {
- throw action.payload;
- }
- if (action.error) {
- throw action.error;
- }
- return action.payload;
- }
- function isThenable(value) {
- return value !== null && typeof value === "object" && typeof value.then === "function";
- }
- // src/matchers.ts
- var matches = function (matcher, action) {
- if (hasMatchFunction(matcher)) {
- return matcher.match(action);
- }
- else {
- return matcher(action);
- }
- };
- function isAnyOf() {
- var matchers = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- matchers[_i] = arguments[_i];
- }
- return function (action) {
- return matchers.some(function (matcher) { return matches(matcher, action); });
- };
- }
- function isAllOf() {
- var matchers = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- matchers[_i] = arguments[_i];
- }
- return function (action) {
- return matchers.every(function (matcher) { return matches(matcher, action); });
- };
- }
- function hasExpectedRequestMetadata(action, validStatus) {
- if (!action || !action.meta)
- return false;
- var hasValidRequestId = typeof action.meta.requestId === "string";
- var hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
- return hasValidRequestId && hasValidRequestStatus;
- }
- function isAsyncThunkArray(a) {
- return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
- }
- function isPending() {
- var asyncThunks = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- asyncThunks[_i] = arguments[_i];
- }
- if (asyncThunks.length === 0) {
- return function (action) { return hasExpectedRequestMetadata(action, ["pending"]); };
- }
- if (!isAsyncThunkArray(asyncThunks)) {
- return isPending()(asyncThunks[0]);
- }
- return function (action) {
- var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.pending; });
- var combinedMatcher = isAnyOf.apply(void 0, matchers);
- return combinedMatcher(action);
- };
- }
- function isRejected() {
- var asyncThunks = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- asyncThunks[_i] = arguments[_i];
- }
- if (asyncThunks.length === 0) {
- return function (action) { return hasExpectedRequestMetadata(action, ["rejected"]); };
- }
- if (!isAsyncThunkArray(asyncThunks)) {
- return isRejected()(asyncThunks[0]);
- }
- return function (action) {
- var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.rejected; });
- var combinedMatcher = isAnyOf.apply(void 0, matchers);
- return combinedMatcher(action);
- };
- }
- function isRejectedWithValue() {
- var asyncThunks = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- asyncThunks[_i] = arguments[_i];
- }
- var hasFlag = function (action) {
- return action && action.meta && action.meta.rejectedWithValue;
- };
- if (asyncThunks.length === 0) {
- return function (action) {
- var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
- return combinedMatcher(action);
- };
- }
- if (!isAsyncThunkArray(asyncThunks)) {
- return isRejectedWithValue()(asyncThunks[0]);
- }
- return function (action) {
- var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
- return combinedMatcher(action);
- };
- }
- function isFulfilled() {
- var asyncThunks = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- asyncThunks[_i] = arguments[_i];
- }
- if (asyncThunks.length === 0) {
- return function (action) { return hasExpectedRequestMetadata(action, ["fulfilled"]); };
- }
- if (!isAsyncThunkArray(asyncThunks)) {
- return isFulfilled()(asyncThunks[0]);
- }
- return function (action) {
- var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.fulfilled; });
- var combinedMatcher = isAnyOf.apply(void 0, matchers);
- return combinedMatcher(action);
- };
- }
- function isAsyncThunkAction() {
- var asyncThunks = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- asyncThunks[_i] = arguments[_i];
- }
- if (asyncThunks.length === 0) {
- return function (action) { return hasExpectedRequestMetadata(action, ["pending", "fulfilled", "rejected"]); };
- }
- if (!isAsyncThunkArray(asyncThunks)) {
- return isAsyncThunkAction()(asyncThunks[0]);
- }
- return function (action) {
- var matchers = [];
- for (var _i = 0, asyncThunks_1 = asyncThunks; _i < asyncThunks_1.length; _i++) {
- var asyncThunk = asyncThunks_1[_i];
- matchers.push(asyncThunk.pending, asyncThunk.rejected, asyncThunk.fulfilled);
- }
- var combinedMatcher = isAnyOf.apply(void 0, matchers);
- return combinedMatcher(action);
- };
- }
- // src/listenerMiddleware/utils.ts
- var assertFunction = function (func, expected) {
- if (typeof func !== "function") {
- throw new TypeError(expected + " is not a function");
- }
- };
- var noop = function () {
- };
- var catchRejection = function (promise2, onError) {
- if (onError === void 0) { onError = noop; }
- promise2.catch(onError);
- return promise2;
- };
- var addAbortSignalListener = function (abortSignal, callback) {
- abortSignal.addEventListener("abort", callback, { once: true });
- return function () { return abortSignal.removeEventListener("abort", callback); };
- };
- var abortControllerWithReason = function (abortController, reason) {
- var signal = abortController.signal;
- if (signal.aborted) {
- return;
- }
- if (!("reason" in signal)) {
- Object.defineProperty(signal, "reason", {
- enumerable: true,
- value: reason,
- configurable: true,
- writable: true
- });
- }
- ;
- abortController.abort(reason);
- };
- // src/listenerMiddleware/exceptions.ts
- var task = "task";
- var listener = "listener";
- var completed = "completed";
- var cancelled = "cancelled";
- var taskCancelled = "task-" + cancelled;
- var taskCompleted = "task-" + completed;
- var listenerCancelled = listener + "-" + cancelled;
- var listenerCompleted = listener + "-" + completed;
- var TaskAbortError = /** @class */ (function () {
- function TaskAbortError(code) {
- this.code = code;
- this.name = "TaskAbortError";
- this.message = task + " " + cancelled + " (reason: " + code + ")";
- }
- return TaskAbortError;
- }());
- // src/listenerMiddleware/task.ts
- var validateActive = function (signal) {
- if (signal.aborted) {
- throw new TaskAbortError(signal.reason);
- }
- };
- function raceWithSignal(signal, promise2) {
- var cleanup = noop;
- return new Promise(function (resolve, reject) {
- var notifyRejection = function () { return reject(new TaskAbortError(signal.reason)); };
- if (signal.aborted) {
- notifyRejection();
- return;
- }
- cleanup = addAbortSignalListener(signal, notifyRejection);
- promise2.finally(function () { return cleanup(); }).then(resolve, reject);
- }).finally(function () {
- cleanup = noop;
- });
- }
- var runTask = function (task2, cleanUp) { return __async(void 0, null, function () {
- var value, error_1;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- _c.trys.push([0, 3, 4, 5]);
- return [4 /*yield*/, Promise.resolve()];
- case 1:
- _c.sent();
- return [4 /*yield*/, task2()];
- case 2:
- value = _c.sent();
- return [2 /*return*/, {
- status: "ok",
- value: value
- }];
- case 3:
- error_1 = _c.sent();
- return [2 /*return*/, {
- status: error_1 instanceof TaskAbortError ? "cancelled" : "rejected",
- error: error_1
- }];
- case 4:
- cleanUp == null ? void 0 : cleanUp();
- return [7 /*endfinally*/];
- case 5: return [2 /*return*/];
- }
- });
- }); };
- var createPause = function (signal) {
- return function (promise2) {
- return catchRejection(raceWithSignal(signal, promise2).then(function (output) {
- validateActive(signal);
- return output;
- }));
- };
- };
- var createDelay = function (signal) {
- var pause = createPause(signal);
- return function (timeoutMs) {
- return pause(new Promise(function (resolve) { return setTimeout(resolve, timeoutMs); }));
- };
- };
- // src/listenerMiddleware/index.ts
- var assign = Object.assign;
- var INTERNAL_NIL_TOKEN = {};
- var alm = "listenerMiddleware";
- var createFork = function (parentAbortSignal, parentBlockingPromises) {
- var linkControllers = function (controller) { return addAbortSignalListener(parentAbortSignal, function () { return abortControllerWithReason(controller, parentAbortSignal.reason); }); };
- return function (taskExecutor, opts) {
- assertFunction(taskExecutor, "taskExecutor");
- var childAbortController = new AbortController();
- linkControllers(childAbortController);
- var result = runTask(function () { return __async(void 0, null, function () {
- var result2;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- validateActive(parentAbortSignal);
- validateActive(childAbortController.signal);
- return [4 /*yield*/, taskExecutor({
- pause: createPause(childAbortController.signal),
- delay: createDelay(childAbortController.signal),
- signal: childAbortController.signal
- })];
- case 1:
- result2 = _c.sent();
- validateActive(childAbortController.signal);
- return [2 /*return*/, result2];
- }
- });
- }); }, function () { return abortControllerWithReason(childAbortController, taskCompleted); });
- if (opts == null ? void 0 : opts.autoJoin) {
- parentBlockingPromises.push(result);
- }
- return {
- result: createPause(parentAbortSignal)(result),
- cancel: function () {
- abortControllerWithReason(childAbortController, taskCancelled);
- }
- };
- };
- };
- var createTakePattern = function (startListening, signal) {
- var take = function (predicate, timeout) { return __async(void 0, null, function () {
- var unsubscribe, tuplePromise, promises, output;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- validateActive(signal);
- unsubscribe = function () {
- };
- tuplePromise = new Promise(function (resolve, reject) {
- var stopListening = startListening({
- predicate: predicate,
- effect: function (action, listenerApi) {
- listenerApi.unsubscribe();
- resolve([
- action,
- listenerApi.getState(),
- listenerApi.getOriginalState()
- ]);
- }
- });
- unsubscribe = function () {
- stopListening();
- reject();
- };
- });
- promises = [
- tuplePromise
- ];
- if (timeout != null) {
- promises.push(new Promise(function (resolve) { return setTimeout(resolve, timeout, null); }));
- }
- _c.label = 1;
- case 1:
- _c.trys.push([1, , 3, 4]);
- return [4 /*yield*/, raceWithSignal(signal, Promise.race(promises))];
- case 2:
- output = _c.sent();
- validateActive(signal);
- return [2 /*return*/, output];
- case 3:
- unsubscribe();
- return [7 /*endfinally*/];
- case 4: return [2 /*return*/];
- }
- });
- }); };
- return function (predicate, timeout) { return catchRejection(take(predicate, timeout)); };
- };
- var getListenerEntryPropsFrom = function (options) {
- var type = options.type, actionCreator = options.actionCreator, matcher = options.matcher, predicate = options.predicate, effect = options.effect;
- if (type) {
- predicate = createAction(type).match;
- }
- else if (actionCreator) {
- type = actionCreator.type;
- predicate = actionCreator.match;
- }
- else if (matcher) {
- predicate = matcher;
- }
- else if (predicate) {
- }
- else {
- throw new Error("Creating or removing a listener requires one of the known fields for matching an action");
- }
- assertFunction(effect, "options.listener");
- return { predicate: predicate, type: type, effect: effect };
- };
- var createListenerEntry = function (options) {
- var _c = getListenerEntryPropsFrom(options), type = _c.type, predicate = _c.predicate, effect = _c.effect;
- var id = nanoid();
- var entry = {
- id: id,
- effect: effect,
- type: type,
- predicate: predicate,
- pending: new Set(),
- unsubscribe: function () {
- throw new Error("Unsubscribe not initialized");
- }
- };
- return entry;
- };
- var cancelActiveListeners = function (entry) {
- entry.pending.forEach(function (controller) {
- abortControllerWithReason(controller, listenerCancelled);
- });
- };
- var createClearListenerMiddleware = function (listenerMap) {
- return function () {
- listenerMap.forEach(cancelActiveListeners);
- listenerMap.clear();
- };
- };
- var safelyNotifyError = function (errorHandler, errorToNotify, errorInfo) {
- try {
- errorHandler(errorToNotify, errorInfo);
- }
- catch (errorHandlerError) {
- setTimeout(function () {
- throw errorHandlerError;
- }, 0);
- }
- };
- var addListener = createAction(alm + "/add");
- var clearAllListeners = createAction(alm + "/removeAll");
- var removeListener = createAction(alm + "/remove");
- var defaultErrorHandler = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- console.error.apply(console, __spreadArray([alm + "/error"], args));
- };
- function createListenerMiddleware(middlewareOptions) {
- var _this = this;
- if (middlewareOptions === void 0) { middlewareOptions = {}; }
- var listenerMap = new Map();
- var extra = middlewareOptions.extra, _c = middlewareOptions.onError, onError = _c === void 0 ? defaultErrorHandler : _c;
- assertFunction(onError, "onError");
- var insertEntry = function (entry) {
- entry.unsubscribe = function () { return listenerMap.delete(entry.id); };
- listenerMap.set(entry.id, entry);
- return function (cancelOptions) {
- entry.unsubscribe();
- if (cancelOptions == null ? void 0 : cancelOptions.cancelActive) {
- cancelActiveListeners(entry);
- }
- };
- };
- var findListenerEntry = function (comparator) {
- for (var _i = 0, _c = Array.from(listenerMap.values()); _i < _c.length; _i++) {
- var entry = _c[_i];
- if (comparator(entry)) {
- return entry;
- }
- }
- return void 0;
- };
- var startListening = function (options) {
- var entry = findListenerEntry(function (existingEntry) { return existingEntry.effect === options.effect; });
- if (!entry) {
- entry = createListenerEntry(options);
- }
- return insertEntry(entry);
- };
- var stopListening = function (options) {
- var _c = getListenerEntryPropsFrom(options), type = _c.type, effect = _c.effect, predicate = _c.predicate;
- var entry = findListenerEntry(function (entry2) {
- var matchPredicateOrType = typeof type === "string" ? entry2.type === type : entry2.predicate === predicate;
- return matchPredicateOrType && entry2.effect === effect;
- });
- if (entry) {
- entry.unsubscribe();
- if (options.cancelActive) {
- cancelActiveListeners(entry);
- }
- }
- return !!entry;
- };
- var notifyListener = function (entry, action, api, getOriginalState) { return __async(_this, null, function () {
- var internalTaskController, take, autoJoinPromises, listenerError_1;
- return __generator(this, function (_c) {
- switch (_c.label) {
- case 0:
- internalTaskController = new AbortController();
- take = createTakePattern(startListening, internalTaskController.signal);
- autoJoinPromises = [];
- _c.label = 1;
- case 1:
- _c.trys.push([1, 3, 4, 6]);
- entry.pending.add(internalTaskController);
- return [4 /*yield*/, Promise.resolve(entry.effect(action, assign({}, api, {
- getOriginalState: getOriginalState,
- condition: function (predicate, timeout) { return take(predicate, timeout).then(Boolean); },
- take: take,
- delay: createDelay(internalTaskController.signal),
- pause: createPause(internalTaskController.signal),
- extra: extra,
- signal: internalTaskController.signal,
- fork: createFork(internalTaskController.signal, autoJoinPromises),
- unsubscribe: entry.unsubscribe,
- subscribe: function () {
- listenerMap.set(entry.id, entry);
- },
- cancelActiveListeners: function () {
- entry.pending.forEach(function (controller, _, set) {
- if (controller !== internalTaskController) {
- abortControllerWithReason(controller, listenerCancelled);
- set.delete(controller);
- }
- });
- }
- })))];
- case 2:
- _c.sent();
- return [3 /*break*/, 6];
- case 3:
- listenerError_1 = _c.sent();
- if (!(listenerError_1 instanceof TaskAbortError)) {
- safelyNotifyError(onError, listenerError_1, {
- raisedBy: "effect"
- });
- }
- return [3 /*break*/, 6];
- case 4: return [4 /*yield*/, Promise.allSettled(autoJoinPromises)];
- case 5:
- _c.sent();
- abortControllerWithReason(internalTaskController, listenerCompleted);
- entry.pending.delete(internalTaskController);
- return [7 /*endfinally*/];
- case 6: return [2 /*return*/];
- }
- });
- }); };
- var clearListenerMiddleware = createClearListenerMiddleware(listenerMap);
- var middleware = function (api) { return function (next) { return function (action) {
- if (!isAction(action)) {
- return next(action);
- }
- if (addListener.match(action)) {
- return startListening(action.payload);
- }
- if (clearAllListeners.match(action)) {
- clearListenerMiddleware();
- return;
- }
- if (removeListener.match(action)) {
- return stopListening(action.payload);
- }
- var originalState = api.getState();
- var getOriginalState = function () {
- if (originalState === INTERNAL_NIL_TOKEN) {
- throw new Error(alm + ": getOriginalState can only be called synchronously");
- }
- return originalState;
- };
- var result;
- try {
- result = next(action);
- if (listenerMap.size > 0) {
- var currentState = api.getState();
- var listenerEntries = Array.from(listenerMap.values());
- for (var _i = 0, listenerEntries_1 = listenerEntries; _i < listenerEntries_1.length; _i++) {
- var entry = listenerEntries_1[_i];
- var runListener = false;
- try {
- runListener = entry.predicate(action, currentState, originalState);
- }
- catch (predicateError) {
- runListener = false;
- safelyNotifyError(onError, predicateError, {
- raisedBy: "predicate"
- });
- }
- if (!runListener) {
- continue;
- }
- notifyListener(entry, action, api, getOriginalState);
- }
- }
- }
- finally {
- originalState = INTERNAL_NIL_TOKEN;
- }
- return result;
- }; }; };
- return {
- middleware: middleware,
- startListening: startListening,
- stopListening: stopListening,
- clearListeners: clearListenerMiddleware
- };
- }
- // src/autoBatchEnhancer.ts
- var SHOULD_AUTOBATCH = "RTK_autoBatch";
- var prepareAutoBatched = function () { return function (payload) {
- var _c;
- return ({
- payload: payload,
- meta: (_c = {}, _c[SHOULD_AUTOBATCH] = true, _c)
- });
- }; };
- var promise;
- var queueMicrotaskShim = typeof queueMicrotask === "function" ? queueMicrotask.bind(typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : globalThis) : function (cb) { return (promise || (promise = Promise.resolve())).then(cb).catch(function (err) { return setTimeout(function () {
- throw err;
- }, 0); }); };
- var createQueueWithTimer = function (timeout) {
- return function (notify) {
- setTimeout(notify, timeout);
- };
- };
- var rAF = typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame : createQueueWithTimer(10);
- var autoBatchEnhancer = function (options) {
- if (options === void 0) { options = { type: "raf" }; }
- return function (next) { return function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- var store = next.apply(void 0, args);
- var notifying = true;
- var shouldNotifyAtEndOfTick = false;
- var notificationQueued = false;
- var listeners = new Set();
- var queueCallback = options.type === "tick" ? queueMicrotaskShim : options.type === "raf" ? rAF : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
- var notifyListeners = function () {
- notificationQueued = false;
- if (shouldNotifyAtEndOfTick) {
- shouldNotifyAtEndOfTick = false;
- listeners.forEach(function (l) { return l(); });
- }
- };
- return Object.assign({}, store, {
- subscribe: function (listener2) {
- var wrappedListener = function () { return notifying && listener2(); };
- var unsubscribe = store.subscribe(wrappedListener);
- listeners.add(listener2);
- return function () {
- unsubscribe();
- listeners.delete(listener2);
- };
- },
- dispatch: function (action) {
- var _a;
- try {
- notifying = !((_a = action == null ? void 0 : action.meta) == null ? void 0 : _a[SHOULD_AUTOBATCH]);
- shouldNotifyAtEndOfTick = !notifying;
- if (shouldNotifyAtEndOfTick) {
- if (!notificationQueued) {
- notificationQueued = true;
- queueCallback(notifyListeners);
- }
- }
- return store.dispatch(action);
- }
- finally {
- notifying = true;
- }
- }
- });
- }; };
- };
- // src/index.ts
- (0, import_immer5.enableES5)();
- //# sourceMappingURL=redux-toolkit.cjs.development.js.map
|