UNPKG

@activejs/core

Version:

Pragmatic, Reactive State Management for JavaScript Apps

1,329 lines (1,316 loc) 189 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('rxjs/operators')) : typeof define === 'function' && define.amd ? define('@activejs/core', ['exports', 'rxjs', 'rxjs/operators'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.activejs = global.activejs || {}, global.activejs.core = {}), global.rxjs, global.rxjs.operators)); }(this, (function (exports, rxjs, operators) { 'use strict'; /* MIT License Copyright (c) 2020 Ankit Singh <dabalyan@hotmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This license applies to the complete mono-repo, unless specified otherwise. */ /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ 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); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); }; } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(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 __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p); } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } ; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } // ____________________________ Common Events ____________________________ // // _______________________________________________________________________ // /** * An event that gets emitted on successful replay by using the `replay` method. * @event * @category Common */ var EventReplay = /** @class */ (function () { /** * @param value The current value that got replayed. */ function EventReplay(value) { this.value = value; } return EventReplay; }()); // _________________________ Common Units Events _________________________ // // _______________________________________________________________________ // /** * An event that gets emitted on successful dispatch by using the Units' `dispatch` method. * @event * @category Common Units */ var EventUnitDispatch = /** @class */ (function () { /** * @param value The value that was passed to the dispatch method. * @param options The options that were passed to the dispatch method. */ function EventUnitDispatch(value, options) { this.value = value; this.options = options; } return EventUnitDispatch; }()); (function (DispatchFailReason) { /** * The first reason, if the Unit is frozen. */ DispatchFailReason["FROZEN_UNIT"] = "FROZEN_UNIT"; /** * The second reason, if the dispatched value is invalid. */ DispatchFailReason["INVALID_VALUE"] = "INVALID_VALUE"; /** * The third reason, if {@link UnitConfig.customDispatchCheck} returns a `falsy` value. */ DispatchFailReason["CUSTOM_DISPATCH_CHECK"] = "CUSTOM_DISPATCH_CHECK"; /** * The fourth reason, if {@link UnitConfig.distinctDispatchCheck} is not `false` and the dispatched value is same as current value. */ DispatchFailReason["DISTINCT_CHECK"] = "DISTINCT_CHECK"; })(exports.DispatchFailReason || (exports.DispatchFailReason = {})); /** * An event that gets emitted on failed dispatch using the Units' `dispatch` method. * @event * @category Common Units */ var EventUnitDispatchFail = /** @class */ (function () { /** * @param value The value that was passed to the dispatch method. * @param reason The reason for why the dispatch failed. * @param options The options that were passed to the dispatch method. */ function EventUnitDispatchFail(value, reason, options) { this.value = value; this.reason = reason; this.options = options; } return EventUnitDispatchFail; }()); /** * An event that gets emitted on successful unmute using the Units' `unmute` method. * @event * @category Common Units */ var EventUnitUnmute = /** @class */ (function () { function EventUnitUnmute() { } return EventUnitUnmute; }()); /** * An event that gets emitted when a Unit gets frozen. * @event * @category Common Units */ var EventUnitFreeze = /** @class */ (function () { function EventUnitFreeze() { } return EventUnitFreeze; }()); /** * An event that gets emitted when a Unit gets unfrozen after being frozen. * @event * @category Common Units */ var EventUnitUnfreeze = /** @class */ (function () { function EventUnitUnfreeze() { } return EventUnitUnfreeze; }()); /** * An event that gets emitted on successful cache-navigation, * using the Units' several cache-navigation methods like `goBack`, `goForward`, `jump`, etc. * @event * @category Common Units */ var EventUnitJump = /** @class */ (function () { /** * @param steps The number of steps jumped represented as a number, * positive for forward navigation and negative for backwards. * @param newCacheIndex The new `cacheIndex` of the emitted value. */ function EventUnitJump(steps, newCacheIndex) { this.steps = steps; this.newCacheIndex = newCacheIndex; } return EventUnitJump; }()); /** * An event that gets emitted on successful execution of Units' `clearCache` method. * @event * @category Common Units */ var EventUnitClearCache = /** @class */ (function () { /** * @param options The options that were directly or indirectly passed to the `clearCache` method. */ function EventUnitClearCache(options) { this.options = options; } return EventUnitClearCache; }()); /** * An event that gets emitted on successful execution of Units' `clearValue` method. * @event * @category Common Units */ var EventUnitClearValue = /** @class */ (function () { function EventUnitClearValue() { } return EventUnitClearValue; }()); /** * An event that gets emitted on successful execution of Units' `clear` method. * @event * @category Common Units */ var EventUnitClear = /** @class */ (function () { /** * @param options The options that were passed for the implicitly called `clearCache` method. */ function EventUnitClear(options) { this.options = options; } return EventUnitClear; }()); /** * An event that gets emitted on successful execution of Units' `resetValue` method. * @event * @category Common Units */ var EventUnitResetValue = /** @class */ (function () { function EventUnitResetValue() { } return EventUnitResetValue; }()); /** * An event that gets emitted on successful execution of Units' `reset` method. * @event * @category Common Units */ var EventUnitReset = /** @class */ (function () { /** * @param options The options that were passed for the implicitly called `clearCache` method. */ function EventUnitReset(options) { this.options = options; } return EventUnitReset; }()); /** * An event that gets emitted on successful execution of Units' `clearPersistentValue` method. * @event * @category Common Units */ var EventUnitClearPersistedValue = /** @class */ (function () { function EventUnitClearPersistedValue() { } return EventUnitClearPersistedValue; }()); // ____________________________ DictUnit Events ____________________________ // // _________________________________________________________________________ // /** * An event that gets emitted on successful execution of DictUnit's `set` method. * @event * @category DictUnit */ var EventDictUnitSet = /** @class */ (function () { /** * @param key The name of the property that was passed to the `set` method. * @param value The value of the property that was passed to the `set` method. */ function EventDictUnitSet(key, value) { this.key = key; this.value = value; } return EventDictUnitSet; }()); /** * An event that gets emitted on successful execution of DictUnit's `assign` method. * @event * @category DictUnit */ var EventDictUnitAssign = /** @class */ (function () { /** * @param sources The source objects that were passed to the `assign` method. * @param newProps The new properties that finally got added to the DictUnit's value. */ function EventDictUnitAssign(sources, newProps) { this.sources = sources; this.newProps = newProps; } return EventDictUnitAssign; }()); /** * An event that gets emitted on successful execution of DictUnit's `delete` or `deleteIf` method. * @event * @category DictUnit */ var EventDictUnitDelete = /** @class */ (function () { /** * @param deletedProps The properties that were deleted by the `delete` or `deleteIf` method. */ function EventDictUnitDelete(deletedProps) { this.deletedProps = deletedProps; } return EventDictUnitDelete; }()); // ____________________________ ListUnit Events ____________________________ // // _________________________________________________________________________ // /** * An event that gets emitted on successful execution of ListUnit's `set` method. * @event * @category ListUnit */ var EventListUnitSet = /** @class */ (function () { /** * @param index The index for the item passed to the `set` method. * @param item The item passed to the `set` method. */ function EventListUnitSet(index, item) { this.index = index; this.item = item; } return EventListUnitSet; }()); /** * An event that gets emitted on successful execution of ListUnit's `pop` method. * @event * @category ListUnit */ var EventListUnitPop = /** @class */ (function () { /** * @param item The item that got popped from the ListUnit's value. */ function EventListUnitPop(item) { this.item = item; } return EventListUnitPop; }()); /** * An event that gets emitted on successful execution of ListUnit's `push` method. * @event * @category ListUnit */ var EventListUnitPush = /** @class */ (function () { /** * @param items The items that were passed to the `push` method. */ function EventListUnitPush(items) { this.items = items; } return EventListUnitPush; }()); /** * An event that gets emitted on successful execution of ListUnit's `shift` method. * @event * @category ListUnit */ var EventListUnitShift = /** @class */ (function () { /** * @param item The item that got shifted out. */ function EventListUnitShift(item) { this.item = item; } return EventListUnitShift; }()); /** * An event that gets emitted on successful execution of ListUnit's `unshift` method. * @event * @category ListUnit */ var EventListUnitUnshift = /** @class */ (function () { /** * @param items The items that were passed to the `unshift` method. */ function EventListUnitUnshift(items) { this.items = items; } return EventListUnitUnshift; }()); /** * An event that gets emitted on successful execution of ListUnit's `delete` or `deleteIf` method. * @event * @category ListUnit */ var EventListUnitDelete = /** @class */ (function () { /** * @param indices The indices that were passed to the `delete` method explicitly, * or implicitly by `deleteIf` method. * @param deletedItems The items that got deleted from the ListUnit's value. */ function EventListUnitDelete(indices, deletedItems) { this.indices = indices; this.deletedItems = deletedItems; } return EventListUnitDelete; }()); /** * An event that gets emitted on successful execution of ListUnit's `remove` or `removeIf` method. * @event * @category ListUnit */ var EventListUnitRemove = /** @class */ (function () { /** * @param indices The indices that were passed to the `remove` method explicitly, * or implicitly by `removeIf` method. * @param removedItems The items that got removed from the ListUnit's value. */ function EventListUnitRemove(indices, removedItems) { this.indices = indices; this.removedItems = removedItems; } return EventListUnitRemove; }()); /** * An event that gets emitted on successful execution of ListUnit's `splice` or `insert` method. * @event * @category ListUnit */ var EventListUnitSplice = /** @class */ (function () { /** * @param start The zero-based location that was passed to the `splice` method. * @param deleteCount The number of items that were to be removed. * @param removedItems The items that got removed. * @param addedItems The items that were passed as `items` to be added. */ function EventListUnitSplice(start, deleteCount, removedItems, addedItems) { this.start = start; this.deleteCount = deleteCount; this.removedItems = removedItems; this.addedItems = addedItems; } return EventListUnitSplice; }()); /** * An event that gets emitted on successful execution of ListUnit's `fill` method. * @event * @category ListUnit */ var EventListUnitFill = /** @class */ (function () { /** * @param item The item that was passed to the `fill` method. * @param start The starting position where the filling started. * @param end The last position where the filling stopped. */ function EventListUnitFill(item, start, end) { this.item = item; this.start = start; this.end = end; } return EventListUnitFill; }()); /** * An event that gets emitted on successful execution of ListUnit's `copyWithin` method. * @event * @category ListUnit */ var EventListUnitCopyWithin = /** @class */ (function () { /** * @param target The target position from where the copied section starts replacing. * @param start The starting position of the copied section. * @param end The ending position of the copied section. */ function EventListUnitCopyWithin(target, start, end) { this.target = target; this.start = start; this.end = end; } return EventListUnitCopyWithin; }()); /** * An event that gets emitted on successful execution of ListUnit's `reverse` method. * @event * @category ListUnit */ var EventListUnitReverse = /** @class */ (function () { function EventListUnitReverse() { } return EventListUnitReverse; }()); /** * An event that gets emitted on successful execution of ListUnit's `sort` method. * @event * @category ListUnit */ var EventListUnitSort = /** @class */ (function () { function EventListUnitSort() { } return EventListUnitSort; }()); /** * @internal please do not use. */ var NOOP = function () { }; /** * @internal please do not use. */ var IteratorSymbol = (typeof Symbol === 'function' && Symbol.iterator) || /* istanbul ignore next */ '@@iterator'; /** * @internal please do not use. */ function isValidId(id) { return typeof id === 'string' && !!id.trim().length; } /** * @internal please do not use. */ function isDict(o) { return Object.prototype.toString.call(o) === '[object Object]'; } /** * @internal please do not use. */ function isObject(o) { return o != null && typeof o === 'object'; } /** * @internal please do not use. */ function isValidKey(key) { return typeof key === 'string' || typeof key === 'number'; } /** * @internal please do not use. */ function isValidIndex(i) { var a = []; a[i] = 1; return !!a.length && a[i] === 1; } /** * @internal please do not use. */ function normalizeIndex(index, arrLength) { return index < 0 ? (index < -arrLength ? 0 : arrLength + index) : index; } /** * @internal please do not use. */ function sanitizeIndices(indices, arrLength) { var sanitizedIndices = []; indices.forEach(function (index) { index = normalizeIndex(index, arrLength); if (index < arrLength && isValidIndex(index)) { sanitizedIndices.push(index); } }); return deDuplicate(sanitizedIndices); } /** * @internal please do not use. */ function isNumber(n) { return typeof n === 'number' && !isNaN(n); } /** * @internal please do not use. */ // tslint:disable-next-line:ban-types function isFunction(fn) { return typeof fn === 'function'; } /** * @internal please do not use. */ /*export function isNativeFn(fn: any): fn is () => any { return /{\s*?\[native code]\s*?}/.test('' + fn); }*/ /** * Creates a clone of the provided value.\ * All the primitives are returned as is, since they are immutable.\ * Non-primitives that this function can clone are array and object-literal.\ * Other non-primitives are returned as is. * * This function is also used internally by ActiveJS. * * @param o The value to be cloned. * @returns A clone of the provided value. * * @category Global */ function deepCopy(o) { if (o == null || typeof o !== 'object') { return o; } if (Array.isArray(o)) { return o.map(function (v) { return deepCopy(v); }); } if (isDict(o)) { return Object.keys(o).reduce(function (newO, k) { newO[k] = deepCopy(o[k]); return newO; }, {}); } return o; } /** * @internal please do not use. */ function deepFreeze(o) { if (!isObject(o)) { return o; } if (Array.isArray(o)) { o.forEach(function (v) { return deepFreeze(v); }); } else if (isDict(o)) { Object.keys(o).forEach(function (k) { return deepFreeze(o[k]); }); } try { return Object.freeze(o); } catch (e) { return o; } } /** * @internal please do not use. */ function deDuplicate(arr) { if (typeof Set === 'function') { return __spread(new Set(arr)); } else { return arr.filter(function (x, i) { return arr.indexOf(x) === i; }); } } /** * @internal please do not use. */ function isSerializable(o) { if (o == null || typeof o === 'string' || typeof o === 'boolean' || typeof o === 'number') { return [true]; } /*if (typeof o === 'number') { return o === Infinity || o === -Infinity ? [false, o] : [true]; }*/ if (Array.isArray(o)) { var foundPositive_1; o.find(function (v) { var testResult = isSerializable(v); if (testResult[0] === false) { foundPositive_1 = testResult; return true; } }); return foundPositive_1 || [true]; } else if (o.constructor === Object) { var foundPositive_2; Object.keys(o).find(function (k) { var testResult = isSerializable(o[k]); if (testResult[0] === false) { foundPositive_2 = testResult; return true; } }); return foundPositive_2 || [true]; } return [false, o]; } /** * @internal please do not use. */ function findIndex(array, predicate, fromIndex) { var i = isValidIndex(fromIndex) ? Math.max(0, Math.min(fromIndex, array.length - 1)) : 0; while (i < array.length) { if (predicate(array[i], i, array)) { return i; } ++i; } return -1; } /** * @internal please do not use. */ function findIndexBackwards(array, predicate, fromIndex) { var i = isValidIndex(fromIndex) ? Math.max(0, Math.min(fromIndex, array.length - 1)) : array.length - 1; while (i > -1) { if (predicate(array[i], i, array)) { return i; } --i; } return -1; } /** * @internal please do not use. */ function debounce(func, waitTime, callMode) { if (!isNumber(waitTime)) { waitTime = 200; } if (!['START', 'END', 'BOTH'].includes(callMode)) { callMode = 'END'; } var timeout; return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var context = this; var later = function () { timeout = null; if (callMode !== 'START') { return func.apply(context, args); } }; var callNow = callMode !== 'END' && !timeout; clearTimeout(timeout); timeout = setTimeout(later, waitTime); if (callNow) { return func.apply(context, args); } }; } /** * @internal please do not use. */ function makeNonEnumerable(o) { if (o == null || typeof o !== 'object') { return; } Object.keys(o).forEach(function (key) { Object.defineProperty(o, key, { enumerable: false, }); }); } /** * @internal please do not use. */ function generateAsyncSystemIds(systemId, queryConfig, dataConfig, errorConfig, pendingConfig) { var _a, _b, _c, _d; var ids = Object.assign(Object.assign(Object.assign(Object.assign({}, ((queryConfig === null || queryConfig === void 0 ? void 0 : queryConfig.hasOwnProperty('id')) && { queryUnitId: queryConfig.id })), ((dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.hasOwnProperty('id')) && { dataUnitId: dataConfig.id })), ((errorConfig === null || errorConfig === void 0 ? void 0 : errorConfig.hasOwnProperty('id')) && { errorUnitId: errorConfig.id })), ((pendingConfig === null || pendingConfig === void 0 ? void 0 : pendingConfig.hasOwnProperty('id')) && { pendingUnitId: pendingConfig.id })); if (isValidId(systemId)) { ids.queryUnitId = (_a = ids.queryUnitId) !== null && _a !== void 0 ? _a : systemId + '_QUERY'; ids.dataUnitId = (_b = ids.dataUnitId) !== null && _b !== void 0 ? _b : systemId + '_DATA'; ids.errorUnitId = (_c = ids.errorUnitId) !== null && _c !== void 0 ? _c : systemId + '_ERROR'; ids.pendingUnitId = (_d = ids.pendingUnitId) !== null && _d !== void 0 ? _d : systemId + '_PENDING'; } return ids; } /** * @internal please do not use. */ function plucker(o, path) { var length = Array.isArray(path) ? path.length : 0; for (var i = 0; i < length; i++) { if (o == null) { return undefined; } o = Object.prototype.hasOwnProperty.call(o, path[i]) ? o[path[i]] : undefined; } return o; } /** * @internal please do not use. */ function hashCode(str) { // tslint:disable:no-bitwise var hash = 0; var length = typeof str === 'string' ? str.length : 0; if (length === 0) { return String(hash); } for (var i = 0; i < length; i++) { hash = (hash << 5) - hash + str.charCodeAt(i); hash |= 0; // Convert to 32bit integer } hash = hash >>> 0; return Number(hash).toString(32).toUpperCase(); // tslint:enable:no-bitwise } /** * @internal please do not use. */ function stackTrace() { try { throw new Error(); } catch (error) { return error.stacktrace || error.stack; } } /** * @internal please do not use. */ function getLocationId(source) { if (source == null || typeof source !== 'object') { return ''; } source = source.constructor.name; var errorTrace = stackTrace(); var locationMatch = errorTrace.match(new RegExp( // get two lines beyond ActiveJS scope https://regexr.com/5eb9g "new " + source + "\\b.+\\n(?:[\\s\\S]+new (?:AsyncSystem|Cluster)\\b.+\\n)?((?:.+\\n?){1,2})")); return hashCode((locationMatch === null || locationMatch === void 0 ? void 0 : locationMatch[1]) || errorTrace); } /** * @internal please do not use. */ var UniqueIdsAndLocationIdMap = {}; /** * @internal please do not use. */ var FrozenObj = Object.freeze({}); /** * The Global configuration for all ActiveJS constructs, Units, Systems, Action and Cluster. * * See {@link https://docs.activejs.dev/guides/configuration} for more details. * * @category 4. Utility */ var Configuration = /** @class */ (function () { function Configuration() { } Object.defineProperty(Configuration, "storage", { // tslint:enable:variable-name /** * The default Storage API being used for storing the values of persistent Units. * * @default `localStorage` */ get: function () { return Configuration._storage || localStorage; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "ENVIRONMENT", { /** * Global ActiveJS environment configurations options. */ get: function () { if (this.isDevMode()) { return Configuration._ENVIRONMENT; } return Object.freeze({}); }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "ACTION", { /** * Configuration options applied to all the Actions. {@link Action} */ get: function () { return Configuration._ACTION; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "CLUSTER", { /** * Configuration options applied to all the Clusters. {@link Cluster} */ get: function () { return Configuration._CLUSTER; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "UNITS", { /** * Configuration options applied to all the Units. {@link Unit} */ get: function () { return Configuration._UNITS; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "BOOL_UNIT", { /** * Configuration options applied to all the BoolUnits. {@link BoolUnit} */ get: function () { return Configuration._BOOL_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "NUM_UNIT", { /** * Configuration options applied to all the NumUnits. {@link NumUnit} */ get: function () { return Configuration._NUM_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "STRING_UNIT", { /** * Configuration options applied to all the StringUnits. {@link StringUnit} */ get: function () { return Configuration._STRING_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "LIST_UNIT", { /** * Configuration options applied to all the ListUnits. {@link ListUnit} */ get: function () { return Configuration._LIST_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "DICT_UNIT", { /** * Configuration options applied to all the DictUnits. {@link DictUnit} */ get: function () { return Configuration._DICT_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "GENERIC_UNIT", { /** * Configuration options applied to all the GenericUnits. {@link GenericUnit} */ get: function () { return Configuration._GENERIC_UNIT; }, enumerable: false, configurable: true }); Object.defineProperty(Configuration, "ASYNC_SYSTEM", { /** * Configuration options applied to all the AsyncSystems. {@link AsyncSystem} */ get: function () { return Configuration._ASYNC_SYSTEM; }, enumerable: false, configurable: true }); /** * Sets and overrides default configurations. \ * These configurations can still be overridden at the time of instantiation. * * It should only be called once in the whole app. * Calling it second time doesn't merge the new configuration, * it simply rewrites it. * * However, the defaults are not affected by this behavior, \ * they have to be overridden specifically every time. * * @param config The configuration options. */ Configuration.set = function (config) { var _a = Object.assign({}, config), storage = _a.storage, ENVIRONMENT = _a.ENVIRONMENT, ACTION = _a.ACTION, UNITS = _a.UNITS, CLUSTER = _a.CLUSTER, BOOL_UNIT = _a.BOOL_UNIT, NUM_UNIT = _a.NUM_UNIT, STRING_UNIT = _a.STRING_UNIT, LIST_UNIT = _a.LIST_UNIT, DICT_UNIT = _a.DICT_UNIT, GENERIC_UNIT = _a.GENERIC_UNIT, ASYNC_SYSTEM = _a.ASYNC_SYSTEM; Configuration._storage = storage; Configuration._ENVIRONMENT = Object.freeze(Object.assign({}, ENVIRONMENT)); Configuration._ACTION = Object.freeze(Object.assign({}, ACTION)); Configuration._CLUSTER = Object.freeze(Object.assign({}, CLUSTER)); Configuration._UNITS = Object.freeze(Object.assign({}, UNITS)); Configuration._BOOL_UNIT = Object.freeze(Object.assign({}, BOOL_UNIT)); Configuration._NUM_UNIT = Object.freeze(Object.assign({}, NUM_UNIT)); Configuration._STRING_UNIT = Object.freeze(Object.assign({}, STRING_UNIT)); Configuration._LIST_UNIT = Object.freeze(Object.assign({}, LIST_UNIT)); Configuration._DICT_UNIT = Object.freeze(Object.assign({}, DICT_UNIT)); Configuration._GENERIC_UNIT = Object.freeze(Object.assign({}, GENERIC_UNIT)); Configuration._ASYNC_SYSTEM = Object.freeze(Object.assign(Object.assign({}, ASYNC_SYSTEM), { UNITS: Object.assign({}, ASYNC_SYSTEM === null || ASYNC_SYSTEM === void 0 ? void 0 : ASYNC_SYSTEM.UNITS), QUERY_UNIT: Object.assign({}, ASYNC_SYSTEM === null || ASYNC_SYSTEM === void 0 ? void 0 : ASYNC_SYSTEM.QUERY_UNIT), DATA_UNIT: Object.assign({}, ASYNC_SYSTEM === null || ASYNC_SYSTEM === void 0 ? void 0 : ASYNC_SYSTEM.DATA_UNIT), ERROR_UNIT: Object.assign({}, ASYNC_SYSTEM === null || ASYNC_SYSTEM === void 0 ? void 0 : ASYNC_SYSTEM.ERROR_UNIT), PENDING_UNIT: Object.assign({}, ASYNC_SYSTEM === null || ASYNC_SYSTEM === void 0 ? void 0 : ASYNC_SYSTEM.PENDING_UNIT) })); if (Configuration.ENVIRONMENT.checkUniqueId === true) { Object.keys(UniqueIdsAndLocationIdMap).forEach(function (k) { delete UniqueIdsAndLocationIdMap[k]; }); } }; /** * Resets all global configurations to their default/empty state. \ * It doesn't affect any currently existing instances, it's only applicable to the instances created after this. */ Configuration.reset = function () { Configuration.set(null); }; /** * It sets the {@link ENVIRONMENT} to it's default configuration, \ * i.e: it turns off all the checks declared in {@link ENVIRONMENT} and \ * also, disables the extra logs. */ Configuration.enableProdMode = function () { this._isDevMode = false; }; /** * To check whether the production mode has been enabled or not. */ Configuration.isDevMode = function () { return this._isDevMode; }; return Configuration; }()); // tslint:disable:variable-name /** * @internal please do not use. */ Configuration._isDevMode = true; /** * @internal please do not use. */ Configuration._ENVIRONMENT = FrozenObj; /** * @internal please do not use. */ Configuration._ACTION = FrozenObj; /** * @internal please do not use. */ Configuration._CLUSTER = FrozenObj; /** * @internal please do not use. */ Configuration._UNITS = FrozenObj; /** * @internal please do not use. */ Configuration._BOOL_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._NUM_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._STRING_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._LIST_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._DICT_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._GENERIC_UNIT = FrozenObj; /** * @internal please do not use. */ Configuration._ASYNC_SYSTEM = FrozenObj; /** * This is the most basic building block of ActiveJS. * * Base serves as the base for all fundamental ActiveJS constructs: Units, Systems, Actions and Clusters. * * This is an internal construct, normally you'd never have to use this class directly. * However, if you're just reading the documentation, or want to learn more about how ActiveJS works, * or want to extend this class to b