diff --git a/dist/amd/aurelia-store.d.ts b/dist/amd/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/amd/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/amd/aurelia-store.js b/dist/amd/aurelia-store.js deleted file mode 100644 index 877ef58..0000000 --- a/dist/amd/aurelia-store.js +++ /dev/null @@ -1,27 +0,0 @@ -define(["require", "exports", "./store", "./history", "./store", "./test-helpers", "./history", "./middleware", "./logging", "./decorator"], function (require, exports, store_1, history_1, store_2, test_helpers_1, history_2, middleware_1, logging_1, decorator_1) { - "use strict"; - function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; - } - Object.defineProperty(exports, "__esModule", { value: true }); - function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - var initState = options.initialState; - if (options && options.history && options.history.undoable && !history_1.isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(store_1.Store, new store_1.Store(initState, options)); - } - exports.configure = configure; - __export(store_2); - __export(test_helpers_1); - __export(history_2); - __export(middleware_1); - __export(logging_1); - __export(decorator_1); -}); -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/amd/aurelia-store.js.map b/dist/amd/aurelia-store.js.map deleted file mode 100644 index 143a11c..0000000 --- a/dist/amd/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":";;;;;;IAQA,SAAgB,SAAS,CACvB,OAA+B,EAC/B,OAAuC;QAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,wBAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;SACrE;QAED,OAAO,OAAO,CAAC,YAAY,CAAC;QAE5B,OAAO,CAAC,SAAS;aACd,gBAAgB,CAAC,aAAK,EAAE,IAAI,aAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAjBD,8BAiBC;IAED,kBAAwB;IACxB,yBAA+B;IAC/B,oBAA0B;IAC1B,uBAA6B;IAC7B,oBAA0B;IAC1B,sBAA4B"} \ No newline at end of file diff --git a/dist/amd/decorator.d.ts b/dist/amd/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/amd/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/amd/decorator.js b/dist/amd/decorator.js deleted file mode 100644 index 881cdb1..0000000 --- a/dist/amd/decorator.js +++ /dev/null @@ -1,102 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(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); -}; -define(["require", "exports", "aurelia-dependency-injection", "rxjs", "./store"], function (require, exports, aurelia_dependency_injection_1, rxjs_1, store_1) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - var defaultSelector = function (store) { return store.state; }; - function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - var store = aurelia_dependency_injection_1.Container.instance.get(store_1.Store); - var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - var source = selector(store); - if (source instanceof rxjs_1.Observable) { - return source; - } - return store.state; - } - function createSelectors() { - var _a; - var isSelectorObj = typeof _settings.selector === "object"; - var fallbackSelector = (_a = {}, - _a[_settings.target || "state"] = _settings.selector || defaultSelector, - _a); - return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { - var target = _a[0], selector = _a[1]; - var _b; - return ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector: selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: (_b = {}, - _b[_settings.onChanged || ""] = 1, - _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, - _b["propertyChanged"] = 0, - _b) - }); - }); - } - return function (target) { - var originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - var originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - var _this = this; - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { - var lastTargetIdx = s.targets.length - 1; - var oldState = s.targets.reduce(function (accu, curr) { - if (accu === void 0) { accu = {}; } - return accu[curr]; - }, _this); - Object.entries(s.changeHandlers).forEach(function (_a) { - var handlerName = _a[0], args = _a[1]; - if (handlerName in _this) { - _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce(function (accu, curr, idx) { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, _this); - }); }); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach(function (sub) { - if (sub instanceof rxjs_1.Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; - } - exports.connectTo = connectTo; -}); -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/amd/decorator.js.map b/dist/amd/decorator.js.map deleted file mode 100644 index 175a196..0000000 --- a/dist/amd/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;IAiBA,IAAM,eAAe,GAAG,UAAI,KAAe,IAAK,OAAA,KAAK,CAAC,KAAK,EAAX,CAAW,CAAC;IAE5D,SAAgB,SAAS,CAAa,QAAyE;QAC7G,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,+LAA+L,CAAC,CAAA;SACjN;QAED,IAAM,KAAK,GAAG,wCAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAK,CAAa,CAAC;QACxD,IAAM,SAAS,cACb,QAAQ,EAAE,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,C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OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;iBAChD;YACH,CAAC,CAAA;QACH,CAAC,CAAA;IACH,CAAC;IA5FD,8BA4FC"} \ No newline at end of file diff --git a/dist/amd/devtools.d.ts b/dist/amd/devtools.d.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/amd/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/amd/devtools.js b/dist/amd/devtools.js deleted file mode 100644 index 72702da..0000000 --- a/dist/amd/devtools.js +++ /dev/null @@ -1,5 +0,0 @@ -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); -}); -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/amd/devtools.js.map b/dist/amd/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/amd/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/amd/history.d.ts b/dist/amd/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/amd/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/amd/history.js b/dist/amd/history.js deleted file mode 100644 index 16ff0fa..0000000 --- a/dist/amd/history.js +++ /dev/null @@ -1,64 +0,0 @@ -define(["require", "exports"], function (require, exports) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; - } - exports.jump = jump; - function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.concat([present], future.slice(0, index)); - var newPresent = future[index]; - var newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; - } - function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.slice(0, index); - var newFuture = past.slice(index + 1).concat([present], future); - var newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; - } - function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: presentStateHistory.past.concat([presentStateHistory.present]), - present: nextPresent, - future: [] - }); - } - exports.nextStateHistory = nextStateHistory; - function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; - } - exports.applyLimits = applyLimits; - function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); - } - exports.isStateHistory = isStateHistory; -}); -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/amd/history.js.map b/dist/amd/history.js.map deleted file mode 100644 index f7057e1..0000000 --- a/dist/amd/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":";;;IAWA,SAAgB,IAAI,CAAI,KAAQ,EAAE,CAAS;QACzC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YAC1B,OAAO,KAAK,CAAC;SACd;QAED,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;QAC5C,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CA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oC,EAAE,WAAc;QACtF,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,mBAAmB,EACnB;YACE,IAAI,EAAM,mBAAmB,CAAC,IAAI,SAAE,mBAAmB,CAAC,OAAO,EAAC;YAChE,OAAO,EAAE,WAAW;YACpB,MAAM,EAAE,EAAE;SACX,CACF,CAAC;IACJ,CAAC;IAVD,4CAUC;IAED,SAAgB,WAAW,CAAI,KAAQ,EAAE,KAAa;QACpD,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE;YACzB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE;gBAC7B,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;aAC1D;YAED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE;gBAC/B,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;aAC7C;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAZD,kCAYC;IAED,SAAgB,cAAc,CAAC,OAAY;QACzC,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,WAAW;YAC3C,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW;YACrC,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW;YACnC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;YAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAND,wCAMC"} \ No newline at end of file diff --git a/dist/amd/index.js b/dist/amd/index.js new file mode 100644 index 0000000..aeb2e7c --- /dev/null +++ b/dist/amd/index.js @@ -0,0 +1,619 @@ +define('aurelia-store', ['exports', 'aurelia-pal', 'aurelia-logging', 'rxjs', 'aurelia-dependency-injection', 'rxjs/operators'], function (exports, aureliaPal, aureliaLogging, rxjs, aureliaDependencyInjection, operators) { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use + this file except in compliance with the License. You may obtain a copy of the + License at http://www.apache.org/licenses/LICENSE-2.0 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + /* 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 (b.hasOwnProperty(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 __awaiter(thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(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 }; + } + } + + function jump(state, n) { + if (!isStateHistory(state)) { + return state; + } + if (n > 0) + return jumpToFuture(state, n - 1); + if (n < 0) + return jumpToPast(state, state.past.length + n); + return state; + } + function jumpToFuture(state, index) { + if (index < 0 || index >= state.future.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.concat([present], future.slice(0, index)); + var newPresent = future[index]; + var newFuture = future.slice(index + 1); + return { past: newPast, present: newPresent, future: newFuture }; + } + function jumpToPast(state, index) { + if (index < 0 || index >= state.past.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.slice(0, index); + var newFuture = past.slice(index + 1).concat([present], future); + var newPresent = past[index]; + return { past: newPast, present: newPresent, future: newFuture }; + } + function nextStateHistory(presentStateHistory, nextPresent) { + return Object.assign({}, presentStateHistory, { + past: presentStateHistory.past.concat([presentStateHistory.present]), + present: nextPresent, + future: [] + }); + } + function applyLimits(state, limit) { + if (isStateHistory(state)) { + if (state.past.length > limit) { + state.past = state.past.slice(state.past.length - limit); + } + if (state.future.length > limit) { + state.future = state.future.slice(0, limit); + } + } + return state; + } + function isStateHistory(history) { + return typeof history.present !== "undefined" && + typeof history.future !== "undefined" && + typeof history.past !== "undefined" && + Array.isArray(history.future) && + Array.isArray(history.past); + } + + (function (MiddlewarePlacement) { + MiddlewarePlacement["Before"] = "before"; + MiddlewarePlacement["After"] = "after"; + })(exports.MiddlewarePlacement || (exports.MiddlewarePlacement = {})); + function logMiddleware(state, _, settings) { + if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { + console[settings.logType]("New state: ", state); + } + else { + console.log("New state: ", state); + } + } + function localStorageMiddleware(state, _, settings) { + if (aureliaPal.PLATFORM.global.localStorage) { + var key = settings && settings.key && typeof settings.key === "string" + ? settings.key + : "aurelia-store-state"; + aureliaPal.PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); + } + } + function rehydrateFromLocalStorage(state, key) { + if (!aureliaPal.PLATFORM.global.localStorage) { + return state; + } + var storedState = aureliaPal.PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); + if (!storedState) { + return state; + } + try { + return JSON.parse(storedState); + } + catch (e) { } + return state; + } + + (function (LogLevel) { + LogLevel["trace"] = "trace"; + LogLevel["debug"] = "debug"; + LogLevel["info"] = "info"; + LogLevel["log"] = "log"; + LogLevel["warn"] = "warn"; + LogLevel["error"] = "error"; + })(exports.LogLevel || (exports.LogLevel = {})); + var LoggerIndexed = /** @class */ (function (_super) { + __extends(LoggerIndexed, _super); + function LoggerIndexed() { + return _super !== null && _super.apply(this, arguments) || this; + } + return LoggerIndexed; + }(aureliaLogging.Logger)); + function getLogType(options, definition, defaultLevel) { + if (definition && + options.logDefinitions && + options.logDefinitions.hasOwnProperty(definition) && + options.logDefinitions[definition] && + Object.values(exports.LogLevel).includes(options.logDefinitions[definition])) { + return options.logDefinitions[definition]; + } + return defaultLevel; + } + + (function (PerformanceMeasurement) { + PerformanceMeasurement["StartEnd"] = "startEnd"; + PerformanceMeasurement["All"] = "all"; + })(exports.PerformanceMeasurement || (exports.PerformanceMeasurement = {})); + var Store = /** @class */ (function () { + function Store(initialState, options) { + this.initialState = initialState; + this.logger = aureliaLogging.getLogger("aurelia-store"); + this.devToolsAvailable = false; + this.actions = new Map(); + this.middlewares = new Map(); + this.dispatchQueue = []; + this.options = options || {}; + var isUndoable = this.options.history && this.options.history.undoable === true; + this._state = new rxjs.BehaviorSubject(initialState); + this.state = this._state.asObservable(); + if (!this.options.devToolsOptions || this.options.devToolsOptions.disable !== true) { + this.setupDevTools(); + } + if (isUndoable) { + this.registerHistoryMethods(); + } + } + Store.prototype.registerMiddleware = function (reducer, placement, settings) { + this.middlewares.set(reducer, { placement: placement, settings: settings }); + }; + Store.prototype.unregisterMiddleware = function (reducer) { + if (this.middlewares.has(reducer)) { + this.middlewares.delete(reducer); + } + }; + Store.prototype.isMiddlewareRegistered = function (middleware) { + return this.middlewares.has(middleware); + }; + Store.prototype.registerAction = function (name, reducer) { + if (reducer.length === 0) { + throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); + } + this.actions.set(reducer, { type: name }); + }; + Store.prototype.unregisterAction = function (reducer) { + if (this.actions.has(reducer)) { + this.actions.delete(reducer); + } + }; + Store.prototype.isActionRegistered = function (reducer) { + if (typeof reducer === "string") { + return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; + } + return this.actions.has(reducer); + }; + Store.prototype.resetToState = function (state) { + this._state.next(state); + }; + Store.prototype.dispatch = function (reducer) { + var _this = this; + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + var action; + if (typeof reducer === "string") { + var result = Array.from(this.actions) + .find(function (val) { return val[1].type === reducer; }); + if (result) { + action = result[0]; + } + } + else { + action = reducer; + } + return new Promise(function (resolve, reject) { + _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); + if (_this.dispatchQueue.length === 1) { + _this.handleQueue(); + } + }); + }; + Store.prototype.handleQueue = function () { + return __awaiter(this, void 0, void 0, function () { + var queueItem, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; + queueItem = this.dispatchQueue[0]; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; + case 2: + _a.sent(); + queueItem.resolve(); + return [3 /*break*/, 4]; + case 3: + e_1 = _a.sent(); + queueItem.reject(e_1); + return [3 /*break*/, 4]; + case 4: + this.dispatchQueue.shift(); + this.handleQueue(); + _a.label = 5; + case 5: return [2 /*return*/]; + } + }); + }); + }; + Store.prototype.internalDispatch = function (reducer) { + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.actions.has(reducer)) { + throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); + } + aureliaPal.PLATFORM.performance.mark("dispatch-start"); + action = __assign({}, this.actions.get(reducer), { params: params }); + if (this.options.logDispatchedActions) { + this.logger[getLogType(this.options, "dispatchedActions", exports.LogLevel.info)]("Dispatching: " + action.type); + } + return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), exports.MiddlewarePlacement.Before, { + name: action.type, + params: params + })]; + case 1: + beforeMiddleswaresResult = _a.sent(); + if (beforeMiddleswaresResult === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; + case 2: + result = _a.sent(); + if (result === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + aureliaPal.PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); + if (!result && typeof result !== "object") { + throw new Error("The reducer has to return a new state"); + } + return [4 /*yield*/, this.executeMiddlewares(result, exports.MiddlewarePlacement.After, { + name: action.type, + params: params + })]; + case 3: + resultingState = _a.sent(); + if (resultingState === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + if (isStateHistory(resultingState) && + this.options.history && + this.options.history.limit) { + resultingState = applyLimits(resultingState, this.options.history.limit); + } + this._state.next(resultingState); + aureliaPal.PLATFORM.performance.mark("dispatch-end"); + if (this.options.measurePerformance === exports.PerformanceMeasurement.StartEnd) { + aureliaPal.PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); + measures = aureliaPal.PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); + this.logger[getLogType(this.options, "performanceLog", exports.LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); + } + else if (this.options.measurePerformance === exports.PerformanceMeasurement.All) { + marks = aureliaPal.PLATFORM.performance.getEntriesByType("mark"); + totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; + this.logger[getLogType(this.options, "performanceLog", exports.LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); + } + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + this.updateDevToolsState(action, resultingState); + return [2 /*return*/]; + } + }); + }); + }; + Store.prototype.executeMiddlewares = function (state, placement, action) { + var _this = this; + return Array.from(this.middlewares) + .filter(function (middleware) { return middleware[1].placement === placement; }) + .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { + var result, _a, _b, _c, e_2; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _d.trys.push([0, 5, 7, 8]); + _b = (_a = curr)[0]; + return [4 /*yield*/, prev]; + case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; + case 2: + result = _d.sent(); + if (result === false) { + _arr = []; + return [2 /*return*/, false]; + } + _c = result; + if (_c) return [3 /*break*/, 4]; + return [4 /*yield*/, prev]; + case 3: + _c = (_d.sent()); + _d.label = 4; + case 4: return [2 /*return*/, _c]; + case 5: + e_2 = _d.sent(); + if (this.options.propagateError) { + _arr = []; + throw e_2; + } + return [4 /*yield*/, prev]; + case 6: return [2 /*return*/, _d.sent()]; + case 7: + aureliaPal.PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); + return [7 /*endfinally*/]; + case 8: return [2 /*return*/]; + } + }); + }); }, state); + }; + Store.prototype.setupDevTools = function () { + var _this = this; + if (aureliaPal.PLATFORM.global.devToolsExtension) { + this.logger[getLogType(this.options, "devToolsStatus", exports.LogLevel.debug)]("DevTools are available"); + this.devToolsAvailable = true; + this.devTools = aureliaPal.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); + this.devTools.init(this.initialState); + this.devTools.subscribe(function (message) { + _this.logger[getLogType(_this.options, "devToolsStatus", exports.LogLevel.debug)]("DevTools sent change " + message.type); + if (message.type === "DISPATCH") { + _this._state.next(JSON.parse(message.state)); + } + }); + } + }; + Store.prototype.updateDevToolsState = function (action, state) { + if (this.devToolsAvailable) { + this.devTools.send(action, state); + } + }; + Store.prototype.registerHistoryMethods = function () { + this.registerAction("jump", jump); + }; + return Store; + }()); + function dispatchify(action) { + var store = aureliaDependencyInjection.Container.instance.get(Store); + return function () { + var params = []; + for (var _i = 0; _i < arguments.length; _i++) { + params[_i] = arguments[_i]; + } + return store.dispatch.apply(store, [action].concat(params)); + }; + } + + function executeSteps(store, shouldLogResults) { + var steps = []; + for (var _i = 2; _i < arguments.length; _i++) { + steps[_i - 2] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var logStep, tryStep, lastStep; + return __generator(this, function (_a) { + logStep = function (step, stepIdx) { return function (res) { + if (shouldLogResults) { + console.group("Step " + stepIdx); + console.log(res); + console.groupEnd(); + } + step(res); + }; }; + tryStep = function (step, reject) { + return function (res) { + try { + step(res); + } + catch (err) { + reject(err); + } + }; + }; + lastStep = function (step, resolve) { + return function (res) { + step(res); + resolve(); + }; + }; + return [2 /*return*/, new Promise(function (resolve, reject) { + var currentStep = 0; + steps.slice(0, -1).forEach(function (step) { + store.state.pipe(operators.skip(currentStep), operators.take(1), operators.delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); + currentStep++; + }); + store.state.pipe(operators.skip(currentStep), operators.take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); + })]; + }); + }); + } + + var defaultSelector = function (store) { return store.state; }; + function connectTo(settings) { + if (!Object.entries) { + throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); + } + var store = aureliaDependencyInjection.Container.instance.get(Store); + var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); + function getSource(selector) { + var source = selector(store); + if (source instanceof rxjs.Observable) { + return source; + } + return store.state; + } + function createSelectors() { + var _a; + var isSelectorObj = typeof _settings.selector === "object"; + var fallbackSelector = (_a = {}, + _a[_settings.target || "state"] = _settings.selector || defaultSelector, + _a); + return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { + var target = _a[0], selector = _a[1]; + var _b; + return ({ + targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], + selector: selector, + // numbers are the starting index to slice all the change handling args, + // which are prop name, new state and old state + changeHandlers: (_b = {}, + _b[_settings.onChanged || ""] = 1, + _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, + _b["propertyChanged"] = 0, + _b) + }); + }); + } + return function (target) { + var originalSetup = typeof settings === "object" && settings.setup + ? target.prototype[settings.setup] + : target.prototype.bind; + var originalTeardown = typeof settings === "object" && settings.teardown + ? target.prototype[settings.teardown] + : target.prototype.unbind; + target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { + var _this = this; + if (typeof settings == "object" && + typeof settings.onChanged === "string" && + !(settings.onChanged in this)) { + throw new Error("Provided onChanged handler does not exist on target VM"); + } + this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { + var lastTargetIdx = s.targets.length - 1; + var oldState = s.targets.reduce(function (accu, curr) { + if (accu === void 0) { accu = {}; } + return accu[curr]; + }, _this); + Object.entries(s.changeHandlers).forEach(function (_a) { + var handlerName = _a[0], args = _a[1]; + if (handlerName in _this) { + _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); + } + }); + s.targets.reduce(function (accu, curr, idx) { + accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; + return accu[curr]; + }, _this); + }); }); + if (originalSetup) { + return originalSetup.apply(this, arguments); + } + }; + target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { + if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { + this._stateSubscriptions.forEach(function (sub) { + if (sub instanceof rxjs.Subscription && sub.closed === false) { + sub.unsubscribe(); + } + }); + } + if (originalTeardown) { + return originalTeardown.apply(this, arguments); + } + }; + }; + } + + function configure(aurelia, options) { + if (!options || !options.initialState) { + throw new Error("initialState must be provided via options"); + } + var initState = options.initialState; + if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { + initState = { past: [], present: options.initialState, future: [] }; + } + delete options.initialState; + aurelia.container + .registerInstance(Store, new Store(initState, options)); + } + + exports.configure = configure; + exports.Store = Store; + exports.dispatchify = dispatchify; + exports.executeSteps = executeSteps; + exports.jump = jump; + exports.nextStateHistory = nextStateHistory; + exports.applyLimits = applyLimits; + exports.isStateHistory = isStateHistory; + exports.logMiddleware = logMiddleware; + exports.localStorageMiddleware = localStorageMiddleware; + exports.rehydrateFromLocalStorage = rehydrateFromLocalStorage; + exports.LoggerIndexed = LoggerIndexed; + exports.getLogType = getLogType; + exports.connectTo = connectTo; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}); diff --git a/dist/amd/logging.d.ts b/dist/amd/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/amd/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/amd/logging.js b/dist/amd/logging.js deleted file mode 100644 index 49ef6e0..0000000 --- a/dist/amd/logging.js +++ /dev/null @@ -1,46 +0,0 @@ -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 (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -define(["require", "exports", "aurelia-logging"], function (require, exports, aurelia_logging_1) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - var LogLevel; - (function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; - })(LogLevel = exports.LogLevel || (exports.LogLevel = {})); - var LoggerIndexed = /** @class */ (function (_super) { - __extends(LoggerIndexed, _super); - function LoggerIndexed() { - return _super !== null && _super.apply(this, arguments) || this; - } - return LoggerIndexed; - }(aurelia_logging_1.Logger)); - exports.LoggerIndexed = LoggerIndexed; - function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; - } - exports.getLogType = getLogType; -}); -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/amd/logging.js.map b/dist/amd/logging.js.map deleted file mode 100644 index fab9141..0000000 --- a/dist/amd/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;IAGA,IAAY,QAOX;IAPD,WAAY,QAAQ;QAClB,2BAAe,CAAA;QACf,2BAAe,CAAA;QACf,yBAAa,CAAA;QACb,uBAAW,CAAA;QACX,yBAAa,CAAA;QACb,2BAAe,CAAA;IACjB,CAAC,EAPW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAOnB;IAED;QAAmC,iCAAM;QAAzC;;QAEA,CAAC;QAAD,oBAAC;IAAD,CAAC,AAFD,CAAmC,wBAAM,GAExC;IAFY,sCAAa;IAU1B,SAAgB,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;QAEtB,IAAI,UAAU;YACZ,OAAO,CAAC,cAAc;YACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;YACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;YACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;SAC5C;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAdD,gCAcC"} \ No newline at end of file diff --git a/dist/amd/middleware.d.ts b/dist/amd/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/amd/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/amd/middleware.js b/dist/amd/middleware.js deleted file mode 100644 index baedcbe..0000000 --- a/dist/amd/middleware.js +++ /dev/null @@ -1,43 +0,0 @@ -define(["require", "exports", "aurelia-pal"], function (require, exports, aurelia_pal_1) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - var MiddlewarePlacement; - (function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; - })(MiddlewarePlacement = exports.MiddlewarePlacement || (exports.MiddlewarePlacement = {})); - function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } - } - exports.logMiddleware = logMiddleware; - function localStorageMiddleware(state, _, settings) { - if (aurelia_pal_1.PLATFORM.global.localStorage) { - var key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - aurelia_pal_1.PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } - } - exports.localStorageMiddleware = localStorageMiddleware; - function rehydrateFromLocalStorage(state, key) { - if (!aurelia_pal_1.PLATFORM.global.localStorage) { - return state; - } - var storedState = aurelia_pal_1.PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; - } - exports.rehydrateFromLocalStorage = rehydrateFromLocalStorage; -}); -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/amd/middleware.js.map b/dist/amd/middleware.js.map deleted file mode 100644 index 3f0f551..0000000 --- a/dist/amd/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":";;;IAQA,IAAY,mBAGX;IAHD,WAAY,mBAAmB;QAC7B,wCAAiB,CAAA;QACjB,sCAAe,CAAA;IACjB,CAAC,EAHW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAG9B;IAED,SAAgB,aAAa,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;QAC7D,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3E,OAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SAC1D;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAND,sCAMC;IAED,SAAgB,sBAAsB,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;QACtE,IAAI,sBAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;YAChC,IAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;gBACtE,CAAC,CAAC,QAAQ,CAAC,GAAG;gBACd,CAAC,CAAC,qBAAqB,CAAC;YAE1B,sBAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;SAClE;IACH,CAAC;IARD,wDAQC;IAED,SAAgB,yBAAyB,CAAI,KAAQ,EAAE,GAAY;QACjE,IAAI,CAAC,sBAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;YACjC,OAAO,KAAK,CAAC;SACd;QAED,IAAM,WAAW,GAAG,sBAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;QACvF,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QAED,IAAI;YACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAY,CAAC,CAAC;SACjC;QAAC,OAAO,CAAC,EAAE,GAAG;QAEf,OAAO,KAAK,CAAC;IACf,CAAC;IAfD,8DAeC"} \ No newline at end of file diff --git a/dist/amd/store.d.ts b/dist/amd/store.d.ts deleted file mode 100644 index 01189ea..0000000 --- a/dist/amd/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/commonjs/store.js b/dist/commonjs/store.js deleted file mode 100644 index 7e1f8fe..0000000 --- a/dist/commonjs/store.js +++ /dev/null @@ -1,307 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var rxjs_1 = require("rxjs"); -var aurelia_dependency_injection_1 = require("aurelia-dependency-injection"); -var aurelia_logging_1 = require("aurelia-logging"); -var aurelia_pal_1 = require("aurelia-pal"); -var history_1 = require("./history"); -var middleware_1 = require("./middleware"); -var logging_1 = require("./logging"); -var PerformanceMeasurement; -(function (PerformanceMeasurement) { - PerformanceMeasurement["StartEnd"] = "startEnd"; - PerformanceMeasurement["All"] = "all"; -})(PerformanceMeasurement = exports.PerformanceMeasurement || (exports.PerformanceMeasurement = {})); -var Store = /** @class */ (function () { - function Store(initialState, options) { - this.initialState = initialState; - this.logger = aurelia_logging_1.getLogger("aurelia-store"); - this.devToolsAvailable = false; - this.actions = new Map(); - this.middlewares = new Map(); - this.dispatchQueue = []; - this.options = options || {}; - var isUndoable = this.options.history && this.options.history.undoable === true; - this._state = new rxjs_1.BehaviorSubject(initialState); - this.state = this._state.asObservable(); - this.setupDevTools(); - if (isUndoable) { - this.registerHistoryMethods(); - } - } - Store.prototype.registerMiddleware = function (reducer, placement, settings) { - this.middlewares.set(reducer, { placement: placement, settings: settings }); - }; - Store.prototype.unregisterMiddleware = function (reducer) { - if (this.middlewares.has(reducer)) { - this.middlewares.delete(reducer); - } - }; - Store.prototype.isMiddlewareRegistered = function (middleware) { - return this.middlewares.has(middleware); - }; - Store.prototype.registerAction = function (name, reducer) { - if (reducer.length === 0) { - throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); - } - this.actions.set(reducer, { type: name }); - }; - Store.prototype.unregisterAction = function (reducer) { - if (this.actions.has(reducer)) { - this.actions.delete(reducer); - } - }; - Store.prototype.isActionRegistered = function (reducer) { - if (typeof reducer === "string") { - return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; - } - return this.actions.has(reducer); - }; - Store.prototype.resetToState = function (state) { - this._state.next(state); - }; - Store.prototype.dispatch = function (reducer) { - var _this = this; - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - var action; - if (typeof reducer === "string") { - var result = Array.from(this.actions) - .find(function (val) { return val[1].type === reducer; }); - if (result) { - action = result[0]; - } - } - else { - action = reducer; - } - return new Promise(function (resolve, reject) { - _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); - if (_this.dispatchQueue.length === 1) { - _this.handleQueue(); - } - }); - }; - Store.prototype.handleQueue = function () { - return __awaiter(this, void 0, void 0, function () { - var queueItem, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; - queueItem = this.dispatchQueue[0]; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; - case 2: - _a.sent(); - queueItem.resolve(); - return [3 /*break*/, 4]; - case 3: - e_1 = _a.sent(); - queueItem.reject(e_1); - return [3 /*break*/, 4]; - case 4: - this.dispatchQueue.shift(); - this.handleQueue(); - _a.label = 5; - case 5: return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.internalDispatch = function (reducer) { - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.actions.has(reducer)) { - throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-start"); - action = this.actions.get(reducer); - if (this.options.logDispatchedActions) { - this.logger[logging_1.getLogType(this.options, "dispatchedActions", logging_1.LogLevel.info)]("Dispatching: " + action.type); - } - return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), middleware_1.MiddlewarePlacement.Before, { - name: action.type, - params: params - })]; - case 1: - beforeMiddleswaresResult = _a.sent(); - if (beforeMiddleswaresResult === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; - case 2: - result = _a.sent(); - if (result === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); - if (!result && typeof result !== "object") { - throw new Error("The reducer has to return a new state"); - } - return [4 /*yield*/, this.executeMiddlewares(result, middleware_1.MiddlewarePlacement.After, { - name: action.type, - params: params - })]; - case 3: - resultingState = _a.sent(); - if (resultingState === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - if (history_1.isStateHistory(resultingState) && - this.options.history && - this.options.history.limit) { - resultingState = history_1.applyLimits(resultingState, this.options.history.limit); - } - this._state.next(resultingState); - aurelia_pal_1.PLATFORM.performance.mark("dispatch-end"); - if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { - aurelia_pal_1.PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); - measures = aurelia_pal_1.PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); - } - else if (this.options.measurePerformance === PerformanceMeasurement.All) { - marks = aurelia_pal_1.PLATFORM.performance.getEntriesByType("mark"); - totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); - } - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - this.updateDevToolsState(action, resultingState); - return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.executeMiddlewares = function (state, placement, action) { - var _this = this; - return Array.from(this.middlewares) - .filter(function (middleware) { return middleware[1].placement === placement; }) - .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { - var result, _a, _b, _c, e_2; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _d.trys.push([0, 5, 7, 8]); - _b = (_a = curr)[0]; - return [4 /*yield*/, prev]; - case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; - case 2: - result = _d.sent(); - if (result === false) { - _arr = []; - return [2 /*return*/, false]; - } - _c = result; - if (_c) return [3 /*break*/, 4]; - return [4 /*yield*/, prev]; - case 3: - _c = (_d.sent()); - _d.label = 4; - case 4: return [2 /*return*/, _c]; - case 5: - e_2 = _d.sent(); - if (this.options.propagateError) { - _arr = []; - throw e_2; - } - return [4 /*yield*/, prev]; - case 6: return [2 /*return*/, _d.sent()]; - case 7: - aurelia_pal_1.PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); - return [7 /*endfinally*/]; - case 8: return [2 /*return*/]; - } - }); - }); }, state); - }; - Store.prototype.setupDevTools = function () { - var _this = this; - if (aurelia_pal_1.PLATFORM.global.devToolsExtension) { - this.logger[logging_1.getLogType(this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools are available"); - this.devToolsAvailable = true; - this.devTools = aurelia_pal_1.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); - this.devTools.init(this.initialState); - this.devTools.subscribe(function (message) { - _this.logger[logging_1.getLogType(_this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools sent change " + message.type); - if (message.type === "DISPATCH") { - _this._state.next(JSON.parse(message.state)); - } - }); - } - }; - Store.prototype.updateDevToolsState = function (action, state) { - if (this.devToolsAvailable) { - this.devTools.send(action, state); - } - }; - Store.prototype.registerHistoryMethods = function () { - this.registerAction("jump", history_1.jump); - }; - return Store; -}()); -exports.Store = Store; -function dispatchify(action) { - var store = aurelia_dependency_injection_1.Container.instance.get(Store); - return function () { - var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - return store.dispatch.apply(store, [action].concat(params)); - }; -} -exports.dispatchify = dispatchify; -//# sourceMappingURL=store.js.map \ No newline at end of file diff --git a/dist/commonjs/store.js.map b/dist/commonjs/store.js.map deleted file mode 100644 index b6d476e..0000000 --- a/dist/commonjs/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAmD;AAEnD,6EAAwD;AACxD,mDAA2C;AAC3C,2CAAuC;AAEvC,qCAA8E;AAC9E,2CAA8E;AAC9E,qCAAgF;AAKhF,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,+CAAqB,CAAA;IACrB,qCAAW,CAAA;AACb,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC;AAkBD;IAaE,eAAoB,YAAe,EAAE,OAA+B;QAAhD,iBAAY,GAAZ,YAAY,CAAG;QAV3B,WAAM,GAAG,2BAAS,CAAC,eAAe,CAAkB,CAAC;QACrD,sBAAiB,GAAY,KAAK,CAAC;QAEnC,YAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;QACrD,gBAAW,GAA2E,IAAI,GAAG,EAAE,CAAC;QAIhG,kBAAa,GAA2B,EAAE,CAAC;QAGjD,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAC7B,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,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CAAC,CAAC;IACzD,CAAC;IACH,YAAC;AAAD,CAAC,AA1PD,IA0PC;AA1PY,sBAAK;AA4PlB,SAAgB,WAAW,CAAqB,MAA8B;IAC5E,IAAM,KAAK,GAAG,wCAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAE5C,OAAO;QAAU,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;QAC3B,OAAO,KAAK,CAAC,QAAQ,OAAd,KAAK,GAAU,MAAM,SAAK,MAAM,EAAkB,CAAC;IAC5D,CAAC,CAAA;AACH,CAAC;AAND,kCAMC"} \ No newline at end of file diff --git a/dist/commonjs/test-helpers.d.ts b/dist/commonjs/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/commonjs/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/commonjs/test-helpers.js b/dist/commonjs/test-helpers.js deleted file mode 100644 index 3e749ff..0000000 --- a/dist/commonjs/test-helpers.js +++ /dev/null @@ -1,83 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var operators_1 = require("rxjs/operators"); -function executeSteps(store, shouldLogResults) { - var steps = []; - for (var _i = 2; _i < arguments.length; _i++) { - steps[_i - 2] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var logStep, tryStep, lastStep; - return __generator(this, function (_a) { - logStep = function (step, stepIdx) { return function (res) { - if (shouldLogResults) { - console.group("Step " + stepIdx); - console.log(res); - console.groupEnd(); - } - step(res); - }; }; - tryStep = function (step, reject) { - return function (res) { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - }; - lastStep = function (step, resolve) { - return function (res) { - step(res); - resolve(); - }; - }; - return [2 /*return*/, new Promise(function (resolve, reject) { - var currentStep = 0; - steps.slice(0, -1).forEach(function (step) { - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1), operators_1.delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - })]; - }); - }); -} -exports.executeSteps = executeSteps; -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/commonjs/test-helpers.js.map b/dist/commonjs/test-helpers.js.map deleted file mode 100644 index 6376684..0000000 --- a/dist/commonjs/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmD;AAOnD,SAAsB,YAAY,CAAI,KAAe,EAAE,gBAAyB;IAAE,eAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,8BAAqB;;;;;YAC/F,OAAO,GAAG,UAAC,IAAe,EAAE,OAAe,IAAK,OAAA,UAAC,GAAM;gBAC3D,IAAI,gBAAgB,EAAE;oBACpB,OAAO,CAAC,KAAK,CAAC,UAAQ,OAAS,CAAC,CAAA;oBAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBACjB,OAAO,CAAC,QAAQ,EAAE,CAAC;iBACpB;gBACD,IAAI,CAAC,GAAG,CAAC,CAAC;YACZ,CAAC,EAPqD,CAOrD,CAAC;YAGI,OAAO,GAAG,UAAC,IAAe,EAAE,MAA8B;gBAC9D,OAAA,UAAC,GAAM;oBACL,IAAI;wBACF,IAAI,CAAC,GAAG,CAAC,CAAC;qBACX;oBAAC,OAAO,GAAG,EAAE;wBACZ,MAAM,CAAC,GAAG,CAAC,CAAC;qBACb;gBACH,CAAC;YAND,CAMC,CAAC;YAEE,QAAQ,GAAG,UAAC,IAAe,EAAE,OAAmB;gBACpD,OAAA,UAAC,GAAM;oBACL,IAAI,CAAC,GAAG,CAAC,CAAC;oBACV,OAAO,EAAE,CAAC;gBACZ,CAAC;YAHD,CAGC,CAAC;YAEJ,sBAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;oBACjC,IAAI,WAAW,GAAG,CAAC,CAAC;oBAEpB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAC,IAAI;wBAC9B,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,EACP,iBAAK,CAAC,CAAC,CAAC,CACT,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;wBACzD,WAAW,EAAE,CAAC;oBAChB,CAAC,CAAC,CAAC;oBAEH,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,CACR,CAAC,SAAS,CACT,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;gBACvF,CAAC,CAAC,EAAC;;;CACJ;AA5CD,oCA4CC"} \ No newline at end of file diff --git a/dist/es2015/aurelia-store.d.ts b/dist/es2015/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/es2015/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/es2015/aurelia-store.js b/dist/es2015/aurelia-store.js deleted file mode 100644 index d58660a..0000000 --- a/dist/es2015/aurelia-store.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Store } from "./store"; -import { isStateHistory } from "./history"; -export function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - var initState = options.initialState; - if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(Store, new Store(initState, options)); -} -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/es2015/aurelia-store.js.map b/dist/es2015/aurelia-store.js.map deleted file mode 100644 index 5e7cc9b..0000000 --- a/dist/es2015/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM3C,MAAM,UAAU,SAAS,CACvB,OAA+B,EAC/B,OAAuC;IAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;KACrE;IAED,OAAO,OAAO,CAAC,YAAY,CAAC;IAE5B,OAAO,CAAC,SAAS;SACd,gBAAgB,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"} \ No newline at end of file diff --git a/dist/es2015/decorator.d.ts b/dist/es2015/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/es2015/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/es2015/decorator.js b/dist/es2015/decorator.js deleted file mode 100644 index bfbb898..0000000 --- a/dist/es2015/decorator.js +++ /dev/null @@ -1,100 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(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); -}; -import { Container } from "aurelia-dependency-injection"; -import { Observable, Subscription } from "rxjs"; -import { Store } from "./store"; -var defaultSelector = function (store) { return store.state; }; -export function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - var store = Container.instance.get(Store); - var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - var source = selector(store); - if (source instanceof Observable) { - return source; - } - return store.state; - } - function createSelectors() { - var _a; - var isSelectorObj = typeof _settings.selector === "object"; - var fallbackSelector = (_a = {}, - _a[_settings.target || "state"] = _settings.selector || defaultSelector, - _a); - return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { - var target = _a[0], selector = _a[1]; - var _b; - return ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector: selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: (_b = {}, - _b[_settings.onChanged || ""] = 1, - _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, - _b["propertyChanged"] = 0, - _b) - }); - }); - } - return function (target) { - var originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - var originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - var _this = this; - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { - var lastTargetIdx = s.targets.length - 1; - var oldState = s.targets.reduce(function (accu, curr) { - if (accu === void 0) { accu = {}; } - return accu[curr]; - }, _this); - Object.entries(s.changeHandlers).forEach(function (_a) { - var handlerName = _a[0], args = _a[1]; - if (handlerName in _this) { - _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce(function (accu, curr, idx) { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, _this); - }); }); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach(function (sub) { - if (sub instanceof Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; -} -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/es2015/decorator.js.map b/dist/es2015/decorator.js.map deleted file mode 100644 index 90fb621..0000000 --- a/dist/es2015/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAchC,IAAM,eAAe,GAAG,UAAI,KAAe,IAAK,OAAA,KAAK,CAAC,KAAK,EAAX,CAAW,CAAC;AAE5D,MAAM,UAAU,SAAS,CAAa,QAAyE;IAC7G,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,+LAA+L,CAAC,CAAA;KACjN;IAED,IAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAa,CAAC;IACxD,IAAM,SAAS,cACb,QAAQ,EAAE,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,IAClE,QAAQ,CACZ,CAAC;IAEF,SAAS,SAAS,CAAC,QAAgD;QACjE,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE7B,IAAI,MAAM,YAAY,UAAU,EAAE;YAChC,OAAO,MAAM,CAAC;SACf;QAEH,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,SAAS,eAAe;;QACtB,IAAM,aAAa,GAAG,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAC7D,IAAM,gBAAgB;YACpB,GAAC,SAAS,CAAC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K,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;oBAC9D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC,EAAE,KAAI,CAAC,CAAC;YACX,CAAC,CAAC,EAdoD,CAcpD,CAAC,CAAC;YAEJ,IAAI,aAAa,EAAE;gBACjB,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAC7C;QACH,CAAC,CAAA;QAED,MAAM,CAAC,SAAS,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG;YACnG,IAAI,IAAI,CAAC,mBAAmB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBACvE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAC,GAAiB;oBACjD,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;wBACvD,GAAG,CAAC,WAAW,EAAE,CAAC;qBACnB;gBACH,CAAC,CAAC,CAAC;aACJ;YAED,IAAI,gBAAgB,EAAE;gBACpB,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAChD;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/dist/es2015/devtools.d.ts b/dist/es2015/devtools.d.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/es2015/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/es2015/devtools.js b/dist/es2015/devtools.js deleted file mode 100644 index 947dd8e..0000000 --- a/dist/es2015/devtools.js +++ /dev/null @@ -1 +0,0 @@ -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/es2015/devtools.js.map b/dist/es2015/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/es2015/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/es2015/history.d.ts b/dist/es2015/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/es2015/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/es2015/history.js b/dist/es2015/history.js deleted file mode 100644 index a612bd7..0000000 --- a/dist/es2015/history.js +++ /dev/null @@ -1,56 +0,0 @@ -export function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; -} -function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.concat([present], future.slice(0, index)); - var newPresent = future[index]; - var newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; -} -function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.slice(0, index); - var newFuture = past.slice(index + 1).concat([present], future); - var newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; -} -export function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: presentStateHistory.past.concat([presentStateHistory.present]), - present: nextPresent, - future: [] - }); -} -export function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; -} -export function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); -} -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/es2015/history.js.map b/dist/es2015/history.js.map deleted file mode 100644 index fa91533..0000000 --- a/dist/es2015/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,IAAI,CAAI,KAAQ,EAAE,CAAS;IACzC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAI,KAAsB,EAAE,KAAa;IAC5D,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAEO,IAAA,iBAAI,EAAE,qBAAM,EAAE,uBAAO,CAAW;IAExC,IAAM,OAAO,GAAO,IAAI,SAAE,OAAO,GAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9D,IAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAE1C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAA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CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAY;IACzC,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,WAAW;QAC3C,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW;QACrC,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW;QACnC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"} \ No newline at end of file diff --git a/dist/es2015/index.js b/dist/es2015/index.js new file mode 100644 index 0000000..b44fe67 --- /dev/null +++ b/dist/es2015/index.js @@ -0,0 +1,472 @@ +import { PLATFORM } from 'aurelia-pal'; +import { Logger, getLogger } from 'aurelia-logging'; +import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { Container } from 'aurelia-dependency-injection'; +import { delay, skip, take } from 'rxjs/operators'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +function __awaiter(thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function jump(state, n) { + if (!isStateHistory(state)) { + return state; + } + if (n > 0) + return jumpToFuture(state, n - 1); + if (n < 0) + return jumpToPast(state, state.past.length + n); + return state; +} +function jumpToFuture(state, index) { + if (index < 0 || index >= state.future.length) { + return state; + } + const { past, future, present } = state; + const newPast = [...past, present, ...future.slice(0, index)]; + const newPresent = future[index]; + const newFuture = future.slice(index + 1); + return { past: newPast, present: newPresent, future: newFuture }; +} +function jumpToPast(state, index) { + if (index < 0 || index >= state.past.length) { + return state; + } + const { past, future, present } = state; + const newPast = past.slice(0, index); + const newFuture = [...past.slice(index + 1), present, ...future]; + const newPresent = past[index]; + return { past: newPast, present: newPresent, future: newFuture }; +} +function nextStateHistory(presentStateHistory, nextPresent) { + return Object.assign({}, presentStateHistory, { + past: [...presentStateHistory.past, presentStateHistory.present], + present: nextPresent, + future: [] + }); +} +function applyLimits(state, limit) { + if (isStateHistory(state)) { + if (state.past.length > limit) { + state.past = state.past.slice(state.past.length - limit); + } + if (state.future.length > limit) { + state.future = state.future.slice(0, limit); + } + } + return state; +} +function isStateHistory(history) { + return typeof history.present !== "undefined" && + typeof history.future !== "undefined" && + typeof history.past !== "undefined" && + Array.isArray(history.future) && + Array.isArray(history.past); +} + +var MiddlewarePlacement; +(function (MiddlewarePlacement) { + MiddlewarePlacement["Before"] = "before"; + MiddlewarePlacement["After"] = "after"; +})(MiddlewarePlacement || (MiddlewarePlacement = {})); +function logMiddleware(state, _, settings) { + if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { + console[settings.logType]("New state: ", state); + } + else { + console.log("New state: ", state); + } +} +function localStorageMiddleware(state, _, settings) { + if (PLATFORM.global.localStorage) { + const key = settings && settings.key && typeof settings.key === "string" + ? settings.key + : "aurelia-store-state"; + PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); + } +} +function rehydrateFromLocalStorage(state, key) { + if (!PLATFORM.global.localStorage) { + return state; + } + const storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); + if (!storedState) { + return state; + } + try { + return JSON.parse(storedState); + } + catch (e) { } + return state; +} + +var LogLevel; +(function (LogLevel) { + LogLevel["trace"] = "trace"; + LogLevel["debug"] = "debug"; + LogLevel["info"] = "info"; + LogLevel["log"] = "log"; + LogLevel["warn"] = "warn"; + LogLevel["error"] = "error"; +})(LogLevel || (LogLevel = {})); +class LoggerIndexed extends Logger { +} +function getLogType(options, definition, defaultLevel) { + if (definition && + options.logDefinitions && + options.logDefinitions.hasOwnProperty(definition) && + options.logDefinitions[definition] && + Object.values(LogLevel).includes(options.logDefinitions[definition])) { + return options.logDefinitions[definition]; + } + return defaultLevel; +} + +var PerformanceMeasurement; +(function (PerformanceMeasurement) { + PerformanceMeasurement["StartEnd"] = "startEnd"; + PerformanceMeasurement["All"] = "all"; +})(PerformanceMeasurement || (PerformanceMeasurement = {})); +class Store { + constructor(initialState, options) { + this.initialState = initialState; + this.logger = getLogger("aurelia-store"); + this.devToolsAvailable = false; + this.actions = new Map(); + this.middlewares = new Map(); + this.dispatchQueue = []; + this.options = options || {}; + const isUndoable = this.options.history && this.options.history.undoable === true; + this._state = new BehaviorSubject(initialState); + this.state = this._state.asObservable(); + if (!this.options.devToolsOptions || this.options.devToolsOptions.disable !== true) { + this.setupDevTools(); + } + if (isUndoable) { + this.registerHistoryMethods(); + } + } + registerMiddleware(reducer, placement, settings) { + this.middlewares.set(reducer, { placement, settings }); + } + unregisterMiddleware(reducer) { + if (this.middlewares.has(reducer)) { + this.middlewares.delete(reducer); + } + } + isMiddlewareRegistered(middleware) { + return this.middlewares.has(middleware); + } + registerAction(name, reducer) { + if (reducer.length === 0) { + throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); + } + this.actions.set(reducer, { type: name }); + } + unregisterAction(reducer) { + if (this.actions.has(reducer)) { + this.actions.delete(reducer); + } + } + isActionRegistered(reducer) { + if (typeof reducer === "string") { + return Array.from(this.actions).find((action) => action[1].type === reducer) !== undefined; + } + return this.actions.has(reducer); + } + resetToState(state) { + this._state.next(state); + } + dispatch(reducer, ...params) { + let action; + if (typeof reducer === "string") { + const result = Array.from(this.actions) + .find((val) => val[1].type === reducer); + if (result) { + action = result[0]; + } + } + else { + action = reducer; + } + return new Promise((resolve, reject) => { + this.dispatchQueue.push({ reducer: action, params, resolve, reject }); + if (this.dispatchQueue.length === 1) { + this.handleQueue(); + } + }); + } + handleQueue() { + return __awaiter(this, void 0, void 0, function* () { + if (this.dispatchQueue.length > 0) { + const queueItem = this.dispatchQueue[0]; + try { + yield this.internalDispatch(queueItem.reducer, ...queueItem.params); + queueItem.resolve(); + } + catch (e) { + queueItem.reject(e); + } + this.dispatchQueue.shift(); + this.handleQueue(); + } + }); + } + internalDispatch(reducer, ...params) { + return __awaiter(this, void 0, void 0, function* () { + if (!this.actions.has(reducer)) { + throw new Error(`Tried to dispatch an unregistered action${reducer ? " " + reducer.name : ""}`); + } + PLATFORM.performance.mark("dispatch-start"); + const action = Object.assign({}, this.actions.get(reducer), { params }); + if (this.options.logDispatchedActions) { + this.logger[getLogType(this.options, "dispatchedActions", LogLevel.info)](`Dispatching: ${action.type}`); + } + const beforeMiddleswaresResult = yield this.executeMiddlewares(this._state.getValue(), MiddlewarePlacement.Before, { + name: action.type, + params + }); + if (beforeMiddleswaresResult === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + const result = yield reducer(beforeMiddleswaresResult, ...params); + if (result === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); + if (!result && typeof result !== "object") { + throw new Error("The reducer has to return a new state"); + } + let resultingState = yield this.executeMiddlewares(result, MiddlewarePlacement.After, { + name: action.type, + params + }); + if (resultingState === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + if (isStateHistory(resultingState) && + this.options.history && + this.options.history.limit) { + resultingState = applyLimits(resultingState, this.options.history.limit); + } + this._state.next(resultingState); + PLATFORM.performance.mark("dispatch-end"); + if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { + PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); + const measures = PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); + this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${measures[0].duration} of dispatched action ${action.type}:`, measures); + } + else if (this.options.measurePerformance === PerformanceMeasurement.All) { + const marks = PLATFORM.performance.getEntriesByType("mark"); + const totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; + this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${totalDuration} of dispatched action ${action.type}:`, marks); + } + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + this.updateDevToolsState(action, resultingState); + }); + } + executeMiddlewares(state, placement, action) { + return Array.from(this.middlewares) + .filter((middleware) => middleware[1].placement === placement) + .reduce((prev, curr, _, _arr) => __awaiter(this, void 0, void 0, function* () { + try { + const result = yield curr[0](yield prev, this._state.getValue(), curr[1].settings, action); + if (result === false) { + _arr = []; + return false; + } + return result || (yield prev); + } + catch (e) { + if (this.options.propagateError) { + _arr = []; + throw e; + } + return yield prev; + } + finally { + PLATFORM.performance.mark(`dispatch-${placement}-${curr[0].name}`); + } + }), state); + } + setupDevTools() { + if (PLATFORM.global.devToolsExtension) { + this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)]("DevTools are available"); + this.devToolsAvailable = true; + this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); + this.devTools.init(this.initialState); + this.devTools.subscribe((message) => { + this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)](`DevTools sent change ${message.type}`); + if (message.type === "DISPATCH") { + this._state.next(JSON.parse(message.state)); + } + }); + } + } + updateDevToolsState(action, state) { + if (this.devToolsAvailable) { + this.devTools.send(action, state); + } + } + registerHistoryMethods() { + this.registerAction("jump", jump); + } +} +function dispatchify(action) { + const store = Container.instance.get(Store); + return function (...params) { + return store.dispatch(action, ...params); + }; +} + +function executeSteps(store, shouldLogResults, ...steps) { + return __awaiter(this, void 0, void 0, function* () { + const logStep = (step, stepIdx) => (res) => { + if (shouldLogResults) { + console.group(`Step ${stepIdx}`); + console.log(res); + console.groupEnd(); + } + step(res); + }; + // tslint:disable-next-line:no-any + const tryStep = (step, reject) => (res) => { + try { + step(res); + } + catch (err) { + reject(err); + } + }; + const lastStep = (step, resolve) => (res) => { + step(res); + resolve(); + }; + return new Promise((resolve, reject) => { + let currentStep = 0; + steps.slice(0, -1).forEach((step) => { + store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); + currentStep++; + }); + store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); + }); + }); +} + +const defaultSelector = (store) => store.state; +function connectTo(settings) { + if (!Object.entries) { + throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); + } + const store = Container.instance.get(Store); + const _settings = Object.assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); + function getSource(selector) { + const source = selector(store); + if (source instanceof Observable) { + return source; + } + return store.state; + } + function createSelectors() { + const isSelectorObj = typeof _settings.selector === "object"; + const fallbackSelector = { + [_settings.target || "state"]: _settings.selector || defaultSelector + }; + return Object.entries(Object.assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(([target, selector]) => ({ + targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], + selector, + // numbers are the starting index to slice all the change handling args, + // which are prop name, new state and old state + changeHandlers: { + [_settings.onChanged || ""]: 1, + [`${_settings.target || target}Changed`]: _settings.target ? 0 : 1, + ["propertyChanged"]: 0 + } + })); + } + return function (target) { + const originalSetup = typeof settings === "object" && settings.setup + ? target.prototype[settings.setup] + : target.prototype.bind; + const originalTeardown = typeof settings === "object" && settings.teardown + ? target.prototype[settings.teardown] + : target.prototype.unbind; + target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { + if (typeof settings == "object" && + typeof settings.onChanged === "string" && + !(settings.onChanged in this)) { + throw new Error("Provided onChanged handler does not exist on target VM"); + } + this._stateSubscriptions = createSelectors().map(s => getSource(s.selector).subscribe((state) => { + const lastTargetIdx = s.targets.length - 1; + const oldState = s.targets.reduce((accu = {}, curr) => accu[curr], this); + Object.entries(s.changeHandlers).forEach(([handlerName, args]) => { + if (handlerName in this) { + this[handlerName](...[s.targets[lastTargetIdx], state, oldState].slice(args, 3)); + } + }); + s.targets.reduce((accu, curr, idx) => { + accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; + return accu[curr]; + }, this); + })); + if (originalSetup) { + return originalSetup.apply(this, arguments); + } + }; + target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { + if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { + this._stateSubscriptions.forEach((sub) => { + if (sub instanceof Subscription && sub.closed === false) { + sub.unsubscribe(); + } + }); + } + if (originalTeardown) { + return originalTeardown.apply(this, arguments); + } + }; + }; +} + +function configure(aurelia, options) { + if (!options || !options.initialState) { + throw new Error("initialState must be provided via options"); + } + let initState = options.initialState; + if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { + initState = { past: [], present: options.initialState, future: [] }; + } + delete options.initialState; + aurelia.container + .registerInstance(Store, new Store(initState, options)); +} + +export { configure, PerformanceMeasurement, Store, dispatchify, executeSteps, jump, nextStateHistory, applyLimits, isStateHistory, MiddlewarePlacement, logMiddleware, localStorageMiddleware, rehydrateFromLocalStorage, LogLevel, LoggerIndexed, getLogType, connectTo }; diff --git a/dist/es2015/logging.d.ts b/dist/es2015/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/es2015/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/es2015/logging.js b/dist/es2015/logging.js deleted file mode 100644 index 9bcc9fc..0000000 --- a/dist/es2015/logging.js +++ /dev/null @@ -1,42 +0,0 @@ -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 (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -import { Logger } from "aurelia-logging"; -export var LogLevel; -(function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; -})(LogLevel || (LogLevel = {})); -var LoggerIndexed = /** @class */ (function (_super) { - __extends(LoggerIndexed, _super); - function LoggerIndexed() { - return _super !== null && _super.apply(this, arguments) || this; - } - return LoggerIndexed; -}(Logger)); -export { LoggerIndexed }; -export function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; -} -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/es2015/logging.js.map b/dist/es2015/logging.js.map deleted file mode 100644 index f82279a..0000000 --- a/dist/es2015/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED;IAAmC,iCAAM;IAAzC;;IAEA,CAAC;IAAD,oBAAC;AAAD,CAAC,AAFD,CAAmC,MAAM,GAExC;;AAQD,MAAM,UAAU,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;IAEtB,IAAI,UAAU;QACZ,OAAO,CAAC,cAAc;QACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;QACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;QACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;KAC5C;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/dist/es2015/middleware.d.ts b/dist/es2015/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/es2015/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/es2015/middleware.js b/dist/es2015/middleware.js deleted file mode 100644 index 672913f..0000000 --- a/dist/es2015/middleware.js +++ /dev/null @@ -1,37 +0,0 @@ -import { PLATFORM } from "aurelia-pal"; -export var MiddlewarePlacement; -(function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; -})(MiddlewarePlacement || (MiddlewarePlacement = {})); -export function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } -} -export function localStorageMiddleware(state, _, settings) { - if (PLATFORM.global.localStorage) { - var key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } -} -export function rehydrateFromLocalStorage(state, key) { - if (!PLATFORM.global.localStorage) { - return state; - } - var storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; -} -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/es2015/middleware.js.map b/dist/es2015/middleware.js.map deleted file mode 100644 index 415b10b..0000000 --- a/dist/es2015/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,sCAAe,CAAA;AACjB,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B;AAED,MAAM,UAAU,aAAa,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;IAC7D,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC3E,OAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;KAC1D;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;KACnC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;IACtE,IAAI,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;QAChC,IAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;YACtE,CAAC,CAAC,QAAQ,CAAC,GAAG;YACd,CAAC,CAAC,qBAAqB,CAAC;QAE1B,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;KAClE;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAI,KAAQ,EAAE,GAAY;IACjE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;QACjC,OAAO,KAAK,CAAC;KACd;IAED,IAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;IACvF,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAY,CAAC,CAAC;KACjC;IAAC,OAAO,CAAC,EAAE,GAAG;IAEf,OAAO,KAAK,CAAC;AACf,CAAC"} \ No newline at end of file diff --git a/dist/es2015/store.d.ts b/dist/es2015/store.d.ts deleted file mode 100644 index 01189ea..0000000 --- a/dist/es2015/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/es2015/store.js.map b/dist/es2015/store.js.map deleted file mode 100644 index d2c7d2a..0000000 --- a/dist/es2015/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAkB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC9E,OA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Q,CAAC,SAAS,CAAC,UAAC,OAAY;gBACnC,KAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,0BAAwB,OAAO,CAAC,IAAM,CAAC,CAAC;gBAEhH,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;oBAC/B,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;iBAC7C;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEO,mCAAmB,GAA3B,UAA4B,MAAsB,EAAE,KAAQ;QAC1D,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAEO,sCAAsB,GAA9B;QACE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAyB,CAAC,CAAC;IACzD,CAAC;IACH,YAAC;AAAD,CAAC,AA1PD,IA0PC;;AAED,MAAM,UAAU,WAAW,CAAqB,MAA8B;IAC5E,IAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAE5C,OAAO;QAAU,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;QAC3B,OAAO,KAAK,CAAC,QAAQ,OAAd,KAAK,GAAU,MAAM,SAAK,MAAM,EAAkB,CAAC;IAC5D,CAAC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/dist/es2015/test-helpers.d.ts b/dist/es2015/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/es2015/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/es2015/test-helpers.js b/dist/es2015/test-helpers.js deleted file mode 100644 index 7f9c480..0000000 --- a/dist/es2015/test-helpers.js +++ /dev/null @@ -1,80 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -import { delay, skip, take } from "rxjs/operators"; -export function executeSteps(store, shouldLogResults) { - var steps = []; - for (var _i = 2; _i < arguments.length; _i++) { - steps[_i - 2] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var logStep, tryStep, lastStep; - return __generator(this, function (_a) { - logStep = function (step, stepIdx) { return function (res) { - if (shouldLogResults) { - console.group("Step " + stepIdx); - console.log(res); - console.groupEnd(); - } - step(res); - }; }; - tryStep = function (step, reject) { - return function (res) { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - }; - lastStep = function (step, resolve) { - return function (res) { - step(res); - resolve(); - }; - }; - return [2 /*return*/, new Promise(function (resolve, reject) { - var currentStep = 0; - steps.slice(0, -1).forEach(function (step) { - store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - })]; - }); - }); -} -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/es2015/test-helpers.js.map b/dist/es2015/test-helpers.js.map deleted file mode 100644 index 2ba69c5..0000000 --- a/dist/es2015/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAOnD,MAAM,UAAgB,YAAY,CAAI,KAAe,EAAE,gBAAyB;IAAE,eAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,8BAAqB;;;;;YAC/F,OAAO,GAAG,UAAC,IAAe,EAAE,OAAe,IAAK,OAAA,UAAC,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,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;gBACvF,CAAC,CAAC,EAAC;;;CACJ"} \ No newline at end of file diff --git a/dist/es2017/aurelia-store.d.ts b/dist/es2017/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/es2017/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/es2017/aurelia-store.js b/dist/es2017/aurelia-store.js deleted file mode 100644 index 2e1ae57..0000000 --- a/dist/es2017/aurelia-store.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Store } from "./store"; -import { isStateHistory } from "./history"; -export function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - let initState = options.initialState; - if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(Store, new Store(initState, options)); -} -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/es2017/aurelia-store.js.map b/dist/es2017/aurelia-store.js.map deleted file mode 100644 index 5e7cc9b..0000000 --- a/dist/es2017/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM3C,MAAM,UAAU,SAAS,CACvB,OAA+B,EAC/B,OAAuC;IAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;KACrE;IAED,OAAO,OAAO,CAAC,YAAY,CAAC;IAE5B,OAAO,CAAC,SAAS;SACd,gBAAgB,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"} \ No newline at end of file diff --git a/dist/es2017/decorator.d.ts b/dist/es2017/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/es2017/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/es2017/decorator.js b/dist/es2017/decorator.js deleted file mode 100644 index 0a6e1b9..0000000 --- a/dist/es2017/decorator.js +++ /dev/null @@ -1,79 +0,0 @@ -import { Container } from "aurelia-dependency-injection"; -import { Observable, Subscription } from "rxjs"; -import { Store } from "./store"; -const defaultSelector = (store) => store.state; -export function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - const store = Container.instance.get(Store); - const _settings = Object.assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - const source = selector(store); - if (source instanceof Observable) { - return source; - } - return store.state; - } - function createSelectors() { - const isSelectorObj = typeof _settings.selector === "object"; - const fallbackSelector = { - [_settings.target || "state"]: _settings.selector || defaultSelector - }; - return Object.entries(Object.assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(([target, selector]) => ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: { - [_settings.onChanged || ""]: 1, - [`${_settings.target || target}Changed`]: _settings.target ? 0 : 1, - ["propertyChanged"]: 0 - } - })); - } - return function (target) { - const originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - const originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(s => getSource(s.selector).subscribe((state) => { - const lastTargetIdx = s.targets.length - 1; - const oldState = s.targets.reduce((accu = {}, curr) => accu[curr], this); - Object.entries(s.changeHandlers).forEach(([handlerName, args]) => { - if (handlerName in this) { - this[handlerName](...[s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce((accu, curr, idx) => { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, this); - })); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach((sub) => { - if (sub instanceof Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; -} -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/es2017/decorator.js.map b/dist/es2017/decorator.js.map deleted file mode 100644 index 7b3141b..0000000 --- a/dist/es2017/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAchC,MAAM,eAAe,GAAG,CAAI,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;AAE5D,MAAM,UAAU,SAAS,CAAa,QAAyE;IAC7G,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,+LAA+L,CAAC,CAAA;KACjN;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAa,CAAC;IACxD,MAAM,SAAS,mBACb,QAAQ,EAAE,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,IAClE,QAAQ,CACZ,CAAC;IAEF,SAAS,SAAS,CAAC,QAAgD;QACjE,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;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.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/es2017/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/es2017/devtools.js b/dist/es2017/devtools.js deleted file mode 100644 index 947dd8e..0000000 --- a/dist/es2017/devtools.js +++ /dev/null @@ -1 +0,0 @@ -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/es2017/devtools.js.map b/dist/es2017/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/es2017/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/es2017/history.d.ts b/dist/es2017/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/es2017/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/es2017/history.js b/dist/es2017/history.js deleted file mode 100644 index 47706a7..0000000 --- a/dist/es2017/history.js +++ /dev/null @@ -1,56 +0,0 @@ -export function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; -} -function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - const { past, future, present } = state; - const newPast = [...past, present, ...future.slice(0, index)]; - const newPresent = future[index]; - const newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; -} -function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - const { past, future, present } = state; - const newPast = past.slice(0, index); - const newFuture = [...past.slice(index + 1), present, ...future]; - const newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; -} -export function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: [...presentStateHistory.past, presentStateHistory.present], - present: nextPresent, - future: [] - }); -} -export function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; -} -export function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); -} -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/es2017/history.js.map b/dist/es2017/history.js.map deleted file mode 100644 index d6fa2ee..0000000 --- a/dist/es2017/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,IAAI,CAAI,KAAQ,EAAE,CAAS;IACzC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAI,KAAsB,EAAE,KAAa;IAC5D,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAExC,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,KA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K,CAAC,EAAE;QACzB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE;YAC7B,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;SAC1D;QAED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE;YAC/B,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAY;IACzC,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,WAAW;QAC3C,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW;QACrC,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW;QACnC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"} \ No newline at end of file diff --git a/dist/es2017/index.js b/dist/es2017/index.js new file mode 100644 index 0000000..d53a950 --- /dev/null +++ b/dist/es2017/index.js @@ -0,0 +1,442 @@ +import { PLATFORM } from 'aurelia-pal'; +import { Logger, getLogger } from 'aurelia-logging'; +import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { Container } from 'aurelia-dependency-injection'; +import { delay, skip, take } from 'rxjs/operators'; + +function jump(state, n) { + if (!isStateHistory(state)) { + return state; + } + if (n > 0) + return jumpToFuture(state, n - 1); + if (n < 0) + return jumpToPast(state, state.past.length + n); + return state; +} +function jumpToFuture(state, index) { + if (index < 0 || index >= state.future.length) { + return state; + } + const { past, future, present } = state; + const newPast = [...past, present, ...future.slice(0, index)]; + const newPresent = future[index]; + const newFuture = future.slice(index + 1); + return { past: newPast, present: newPresent, future: newFuture }; +} +function jumpToPast(state, index) { + if (index < 0 || index >= state.past.length) { + return state; + } + const { past, future, present } = state; + const newPast = past.slice(0, index); + const newFuture = [...past.slice(index + 1), present, ...future]; + const newPresent = past[index]; + return { past: newPast, present: newPresent, future: newFuture }; +} +function nextStateHistory(presentStateHistory, nextPresent) { + return Object.assign({}, presentStateHistory, { + past: [...presentStateHistory.past, presentStateHistory.present], + present: nextPresent, + future: [] + }); +} +function applyLimits(state, limit) { + if (isStateHistory(state)) { + if (state.past.length > limit) { + state.past = state.past.slice(state.past.length - limit); + } + if (state.future.length > limit) { + state.future = state.future.slice(0, limit); + } + } + return state; +} +function isStateHistory(history) { + return typeof history.present !== "undefined" && + typeof history.future !== "undefined" && + typeof history.past !== "undefined" && + Array.isArray(history.future) && + Array.isArray(history.past); +} + +var MiddlewarePlacement; +(function (MiddlewarePlacement) { + MiddlewarePlacement["Before"] = "before"; + MiddlewarePlacement["After"] = "after"; +})(MiddlewarePlacement || (MiddlewarePlacement = {})); +function logMiddleware(state, _, settings) { + if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { + console[settings.logType]("New state: ", state); + } + else { + console.log("New state: ", state); + } +} +function localStorageMiddleware(state, _, settings) { + if (PLATFORM.global.localStorage) { + const key = settings && settings.key && typeof settings.key === "string" + ? settings.key + : "aurelia-store-state"; + PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); + } +} +function rehydrateFromLocalStorage(state, key) { + if (!PLATFORM.global.localStorage) { + return state; + } + const storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); + if (!storedState) { + return state; + } + try { + return JSON.parse(storedState); + } + catch (e) { } + return state; +} + +var LogLevel; +(function (LogLevel) { + LogLevel["trace"] = "trace"; + LogLevel["debug"] = "debug"; + LogLevel["info"] = "info"; + LogLevel["log"] = "log"; + LogLevel["warn"] = "warn"; + LogLevel["error"] = "error"; +})(LogLevel || (LogLevel = {})); +class LoggerIndexed extends Logger { +} +function getLogType(options, definition, defaultLevel) { + if (definition && + options.logDefinitions && + options.logDefinitions.hasOwnProperty(definition) && + options.logDefinitions[definition] && + Object.values(LogLevel).includes(options.logDefinitions[definition])) { + return options.logDefinitions[definition]; + } + return defaultLevel; +} + +var PerformanceMeasurement; +(function (PerformanceMeasurement) { + PerformanceMeasurement["StartEnd"] = "startEnd"; + PerformanceMeasurement["All"] = "all"; +})(PerformanceMeasurement || (PerformanceMeasurement = {})); +class Store { + constructor(initialState, options) { + this.initialState = initialState; + this.logger = getLogger("aurelia-store"); + this.devToolsAvailable = false; + this.actions = new Map(); + this.middlewares = new Map(); + this.dispatchQueue = []; + this.options = options || {}; + const isUndoable = this.options.history && this.options.history.undoable === true; + this._state = new BehaviorSubject(initialState); + this.state = this._state.asObservable(); + if (!this.options.devToolsOptions || this.options.devToolsOptions.disable !== true) { + this.setupDevTools(); + } + if (isUndoable) { + this.registerHistoryMethods(); + } + } + registerMiddleware(reducer, placement, settings) { + this.middlewares.set(reducer, { placement, settings }); + } + unregisterMiddleware(reducer) { + if (this.middlewares.has(reducer)) { + this.middlewares.delete(reducer); + } + } + isMiddlewareRegistered(middleware) { + return this.middlewares.has(middleware); + } + registerAction(name, reducer) { + if (reducer.length === 0) { + throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); + } + this.actions.set(reducer, { type: name }); + } + unregisterAction(reducer) { + if (this.actions.has(reducer)) { + this.actions.delete(reducer); + } + } + isActionRegistered(reducer) { + if (typeof reducer === "string") { + return Array.from(this.actions).find((action) => action[1].type === reducer) !== undefined; + } + return this.actions.has(reducer); + } + resetToState(state) { + this._state.next(state); + } + dispatch(reducer, ...params) { + let action; + if (typeof reducer === "string") { + const result = Array.from(this.actions) + .find((val) => val[1].type === reducer); + if (result) { + action = result[0]; + } + } + else { + action = reducer; + } + return new Promise((resolve, reject) => { + this.dispatchQueue.push({ reducer: action, params, resolve, reject }); + if (this.dispatchQueue.length === 1) { + this.handleQueue(); + } + }); + } + async handleQueue() { + if (this.dispatchQueue.length > 0) { + const queueItem = this.dispatchQueue[0]; + try { + await this.internalDispatch(queueItem.reducer, ...queueItem.params); + queueItem.resolve(); + } + catch (e) { + queueItem.reject(e); + } + this.dispatchQueue.shift(); + this.handleQueue(); + } + } + async internalDispatch(reducer, ...params) { + if (!this.actions.has(reducer)) { + throw new Error(`Tried to dispatch an unregistered action${reducer ? " " + reducer.name : ""}`); + } + PLATFORM.performance.mark("dispatch-start"); + const action = Object.assign({}, this.actions.get(reducer), { params }); + if (this.options.logDispatchedActions) { + this.logger[getLogType(this.options, "dispatchedActions", LogLevel.info)](`Dispatching: ${action.type}`); + } + const beforeMiddleswaresResult = await this.executeMiddlewares(this._state.getValue(), MiddlewarePlacement.Before, { + name: action.type, + params + }); + if (beforeMiddleswaresResult === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + const result = await reducer(beforeMiddleswaresResult, ...params); + if (result === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); + if (!result && typeof result !== "object") { + throw new Error("The reducer has to return a new state"); + } + let resultingState = await this.executeMiddlewares(result, MiddlewarePlacement.After, { + name: action.type, + params + }); + if (resultingState === false) { + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + return; + } + if (isStateHistory(resultingState) && + this.options.history && + this.options.history.limit) { + resultingState = applyLimits(resultingState, this.options.history.limit); + } + this._state.next(resultingState); + PLATFORM.performance.mark("dispatch-end"); + if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { + PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); + const measures = PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); + this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${measures[0].duration} of dispatched action ${action.type}:`, measures); + } + else if (this.options.measurePerformance === PerformanceMeasurement.All) { + const marks = PLATFORM.performance.getEntriesByType("mark"); + const totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; + this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${totalDuration} of dispatched action ${action.type}:`, marks); + } + PLATFORM.performance.clearMarks(); + PLATFORM.performance.clearMeasures(); + this.updateDevToolsState(action, resultingState); + } + executeMiddlewares(state, placement, action) { + return Array.from(this.middlewares) + .filter((middleware) => middleware[1].placement === placement) + .reduce(async (prev, curr, _, _arr) => { + try { + const result = await curr[0](await prev, this._state.getValue(), curr[1].settings, action); + if (result === false) { + _arr = []; + return false; + } + return result || await prev; + } + catch (e) { + if (this.options.propagateError) { + _arr = []; + throw e; + } + return await prev; + } + finally { + PLATFORM.performance.mark(`dispatch-${placement}-${curr[0].name}`); + } + }, state); + } + setupDevTools() { + if (PLATFORM.global.devToolsExtension) { + this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)]("DevTools are available"); + this.devToolsAvailable = true; + this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); + this.devTools.init(this.initialState); + this.devTools.subscribe((message) => { + this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)](`DevTools sent change ${message.type}`); + if (message.type === "DISPATCH") { + this._state.next(JSON.parse(message.state)); + } + }); + } + } + updateDevToolsState(action, state) { + if (this.devToolsAvailable) { + this.devTools.send(action, state); + } + } + registerHistoryMethods() { + this.registerAction("jump", jump); + } +} +function dispatchify(action) { + const store = Container.instance.get(Store); + return function (...params) { + return store.dispatch(action, ...params); + }; +} + +async function executeSteps(store, shouldLogResults, ...steps) { + const logStep = (step, stepIdx) => (res) => { + if (shouldLogResults) { + console.group(`Step ${stepIdx}`); + console.log(res); + console.groupEnd(); + } + step(res); + }; + // tslint:disable-next-line:no-any + const tryStep = (step, reject) => (res) => { + try { + step(res); + } + catch (err) { + reject(err); + } + }; + const lastStep = (step, resolve) => (res) => { + step(res); + resolve(); + }; + return new Promise((resolve, reject) => { + let currentStep = 0; + steps.slice(0, -1).forEach((step) => { + store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); + currentStep++; + }); + store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); + }); +} + +const defaultSelector = (store) => store.state; +function connectTo(settings) { + if (!Object.entries) { + throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); + } + const store = Container.instance.get(Store); + const _settings = Object.assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); + function getSource(selector) { + const source = selector(store); + if (source instanceof Observable) { + return source; + } + return store.state; + } + function createSelectors() { + const isSelectorObj = typeof _settings.selector === "object"; + const fallbackSelector = { + [_settings.target || "state"]: _settings.selector || defaultSelector + }; + return Object.entries(Object.assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(([target, selector]) => ({ + targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], + selector, + // numbers are the starting index to slice all the change handling args, + // which are prop name, new state and old state + changeHandlers: { + [_settings.onChanged || ""]: 1, + [`${_settings.target || target}Changed`]: _settings.target ? 0 : 1, + ["propertyChanged"]: 0 + } + })); + } + return function (target) { + const originalSetup = typeof settings === "object" && settings.setup + ? target.prototype[settings.setup] + : target.prototype.bind; + const originalTeardown = typeof settings === "object" && settings.teardown + ? target.prototype[settings.teardown] + : target.prototype.unbind; + target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { + if (typeof settings == "object" && + typeof settings.onChanged === "string" && + !(settings.onChanged in this)) { + throw new Error("Provided onChanged handler does not exist on target VM"); + } + this._stateSubscriptions = createSelectors().map(s => getSource(s.selector).subscribe((state) => { + const lastTargetIdx = s.targets.length - 1; + const oldState = s.targets.reduce((accu = {}, curr) => accu[curr], this); + Object.entries(s.changeHandlers).forEach(([handlerName, args]) => { + if (handlerName in this) { + this[handlerName](...[s.targets[lastTargetIdx], state, oldState].slice(args, 3)); + } + }); + s.targets.reduce((accu, curr, idx) => { + accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; + return accu[curr]; + }, this); + })); + if (originalSetup) { + return originalSetup.apply(this, arguments); + } + }; + target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { + if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { + this._stateSubscriptions.forEach((sub) => { + if (sub instanceof Subscription && sub.closed === false) { + sub.unsubscribe(); + } + }); + } + if (originalTeardown) { + return originalTeardown.apply(this, arguments); + } + }; + }; +} + +function configure(aurelia, options) { + if (!options || !options.initialState) { + throw new Error("initialState must be provided via options"); + } + let initState = options.initialState; + if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { + initState = { past: [], present: options.initialState, future: [] }; + } + delete options.initialState; + aurelia.container + .registerInstance(Store, new Store(initState, options)); +} + +export { configure, PerformanceMeasurement, Store, dispatchify, executeSteps, jump, nextStateHistory, applyLimits, isStateHistory, MiddlewarePlacement, logMiddleware, localStorageMiddleware, rehydrateFromLocalStorage, LogLevel, LoggerIndexed, getLogType, connectTo }; diff --git a/dist/es2017/logging.d.ts b/dist/es2017/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/es2017/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/es2017/logging.js b/dist/es2017/logging.js deleted file mode 100644 index 9b7314f..0000000 --- a/dist/es2017/logging.js +++ /dev/null @@ -1,23 +0,0 @@ -import { Logger } from "aurelia-logging"; -export var LogLevel; -(function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; -})(LogLevel || (LogLevel = {})); -export class LoggerIndexed extends Logger { -} -export function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; -} -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/es2017/logging.js.map b/dist/es2017/logging.js.map deleted file mode 100644 index a728598..0000000 --- a/dist/es2017/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED,MAAM,OAAO,aAAc,SAAQ,MAAM;CAExC;AAQD,MAAM,UAAU,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;IAEtB,IAAI,UAAU;QACZ,OAAO,CAAC,cAAc;QACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;QACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;QACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;KAC5C;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/dist/es2017/middleware.d.ts b/dist/es2017/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/es2017/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/es2017/middleware.js b/dist/es2017/middleware.js deleted file mode 100644 index 9a3de36..0000000 --- a/dist/es2017/middleware.js +++ /dev/null @@ -1,37 +0,0 @@ -import { PLATFORM } from "aurelia-pal"; -export var MiddlewarePlacement; -(function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; -})(MiddlewarePlacement || (MiddlewarePlacement = {})); -export function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } -} -export function localStorageMiddleware(state, _, settings) { - if (PLATFORM.global.localStorage) { - const key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } -} -export function rehydrateFromLocalStorage(state, key) { - if (!PLATFORM.global.localStorage) { - return state; - } - const storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; -} -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/es2017/middleware.js.map b/dist/es2017/middleware.js.map deleted file mode 100644 index 5530acd..0000000 --- a/dist/es2017/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA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;KACd;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAY,CAAC,CAAC;KACjC;IAAC,OAAO,CAAC,EAAE,GAAG;IAEf,OAAO,KAAK,CAAC;AACf,CAAC"} \ No newline at end of file diff --git a/dist/es2017/store.d.ts b/dist/es2017/store.d.ts deleted file mode 100644 index 01189ea..0000000 --- a/dist/es2017/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/es2017/store.js b/dist/es2017/store.js deleted file mode 100644 index 3804e47..0000000 --- a/dist/es2017/store.js +++ /dev/null @@ -1,205 +0,0 @@ -import { BehaviorSubject } from "rxjs"; -import { Container } from "aurelia-dependency-injection"; -import { getLogger } from "aurelia-logging"; -import { PLATFORM } from "aurelia-pal"; -import { jump, applyLimits, isStateHistory } from "./history"; -import { MiddlewarePlacement } from "./middleware"; -import { LogLevel, getLogType } from "./logging"; -export var PerformanceMeasurement; -(function (PerformanceMeasurement) { - PerformanceMeasurement["StartEnd"] = "startEnd"; - PerformanceMeasurement["All"] = "all"; -})(PerformanceMeasurement || (PerformanceMeasurement = {})); -export class Store { - constructor(initialState, options) { - this.initialState = initialState; - this.logger = getLogger("aurelia-store"); - this.devToolsAvailable = false; - this.actions = new Map(); - this.middlewares = new Map(); - this.dispatchQueue = []; - this.options = options || {}; - const isUndoable = this.options.history && this.options.history.undoable === true; - this._state = new BehaviorSubject(initialState); - this.state = this._state.asObservable(); - this.setupDevTools(); - if (isUndoable) { - this.registerHistoryMethods(); - } - } - registerMiddleware(reducer, placement, settings) { - this.middlewares.set(reducer, { placement, settings }); - } - unregisterMiddleware(reducer) { - if (this.middlewares.has(reducer)) { - this.middlewares.delete(reducer); - } - } - isMiddlewareRegistered(middleware) { - return this.middlewares.has(middleware); - } - registerAction(name, reducer) { - if (reducer.length === 0) { - throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); - } - this.actions.set(reducer, { type: name }); - } - unregisterAction(reducer) { - if (this.actions.has(reducer)) { - this.actions.delete(reducer); - } - } - isActionRegistered(reducer) { - if (typeof reducer === "string") { - return Array.from(this.actions).find((action) => action[1].type === reducer) !== undefined; - } - return this.actions.has(reducer); - } - resetToState(state) { - this._state.next(state); - } - dispatch(reducer, ...params) { - let action; - if (typeof reducer === "string") { - const result = Array.from(this.actions) - .find((val) => val[1].type === reducer); - if (result) { - action = result[0]; - } - } - else { - action = reducer; - } - return new Promise((resolve, reject) => { - this.dispatchQueue.push({ reducer: action, params, resolve, reject }); - if (this.dispatchQueue.length === 1) { - this.handleQueue(); - } - }); - } - async handleQueue() { - if (this.dispatchQueue.length > 0) { - const queueItem = this.dispatchQueue[0]; - try { - await this.internalDispatch(queueItem.reducer, ...queueItem.params); - queueItem.resolve(); - } - catch (e) { - queueItem.reject(e); - } - this.dispatchQueue.shift(); - this.handleQueue(); - } - } - async internalDispatch(reducer, ...params) { - if (!this.actions.has(reducer)) { - throw new Error(`Tried to dispatch an unregistered action${reducer ? " " + reducer.name : ""}`); - } - PLATFORM.performance.mark("dispatch-start"); - const action = this.actions.get(reducer); - if (this.options.logDispatchedActions) { - this.logger[getLogType(this.options, "dispatchedActions", LogLevel.info)](`Dispatching: ${action.type}`); - } - const beforeMiddleswaresResult = await this.executeMiddlewares(this._state.getValue(), MiddlewarePlacement.Before, { - name: action.type, - params - }); - if (beforeMiddleswaresResult === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return; - } - const result = await reducer(beforeMiddleswaresResult, ...params); - if (result === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return; - } - PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); - if (!result && typeof result !== "object") { - throw new Error("The reducer has to return a new state"); - } - let resultingState = await this.executeMiddlewares(result, MiddlewarePlacement.After, { - name: action.type, - params - }); - if (resultingState === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return; - } - if (isStateHistory(resultingState) && - this.options.history && - this.options.history.limit) { - resultingState = applyLimits(resultingState, this.options.history.limit); - } - this._state.next(resultingState); - PLATFORM.performance.mark("dispatch-end"); - if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { - PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); - const measures = PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); - this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${measures[0].duration} of dispatched action ${action.type}:`, measures); - } - else if (this.options.measurePerformance === PerformanceMeasurement.All) { - const marks = PLATFORM.performance.getEntriesByType("mark"); - const totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; - this.logger[getLogType(this.options, "performanceLog", LogLevel.info)](`Total duration ${totalDuration} of dispatched action ${action.type}:`, marks); - } - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - this.updateDevToolsState(action, resultingState); - } - executeMiddlewares(state, placement, action) { - return Array.from(this.middlewares) - .filter((middleware) => middleware[1].placement === placement) - .reduce(async (prev, curr, _, _arr) => { - try { - const result = await curr[0](await prev, this._state.getValue(), curr[1].settings, action); - if (result === false) { - _arr = []; - return false; - } - return result || await prev; - } - catch (e) { - if (this.options.propagateError) { - _arr = []; - throw e; - } - return await prev; - } - finally { - PLATFORM.performance.mark(`dispatch-${placement}-${curr[0].name}`); - } - }, state); - } - setupDevTools() { - if (PLATFORM.global.devToolsExtension) { - this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)]("DevTools are available"); - this.devToolsAvailable = true; - this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); - this.devTools.init(this.initialState); - this.devTools.subscribe((message) => { - this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)](`DevTools sent change ${message.type}`); - if (message.type === "DISPATCH") { - this._state.next(JSON.parse(message.state)); - } - }); - } - } - updateDevToolsState(action, state) { - if (this.devToolsAvailable) { - this.devTools.send(action, state); - } - } - registerHistoryMethods() { - this.registerAction("jump", jump); - } -} -export function dispatchify(action) { - const store = Container.instance.get(Store); - return function (...params) { - return store.dispatch(action, ...params); - }; -} -//# sourceMappingURL=store.js.map \ No newline at end of file diff --git a/dist/es2017/store.js.map b/dist/es2017/store.js.map deleted file mode 100644 index 35ce4b8..0000000 --- a/dist/es2017/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE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AC,CAAC,CAAC;iBAC7C;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEO,mBAAmB,CAAC,MAAsB,EAAE,KAAQ;QAC1D,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAEO,sBAAsB;QAC5B,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAyB,CAAC,CAAC;IACzD,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAqB,MAA8B;IAC5E,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAE5C,OAAO,UAAU,GAAG,MAAS;QAC3B,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,MAAM,CAAkB,CAAC;IAC5D,CAAC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/dist/es2017/test-helpers.d.ts b/dist/es2017/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/es2017/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/es2017/test-helpers.js b/dist/es2017/test-helpers.js deleted file mode 100644 index 74fee47..0000000 --- a/dist/es2017/test-helpers.js +++ /dev/null @@ -1,33 +0,0 @@ -import { delay, skip, take } from "rxjs/operators"; -export async function executeSteps(store, shouldLogResults, ...steps) { - const logStep = (step, stepIdx) => (res) => { - if (shouldLogResults) { - console.group(`Step ${stepIdx}`); - console.log(res); - console.groupEnd(); - } - step(res); - }; - // tslint:disable-next-line:no-any - const tryStep = (step, reject) => (res) => { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - const lastStep = (step, resolve) => (res) => { - step(res); - resolve(); - }; - return new Promise((resolve, reject) => { - let currentStep = 0; - steps.slice(0, -1).forEach((step) => { - store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - }); -} -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/es2017/test-helpers.js.map b/dist/es2017/test-helpers.js.map deleted file mode 100644 index 9ef5965..0000000 --- a/dist/es2017/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAOnD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,KAAe,EAAE,gBAAyB,EAAE,GAAG,KAAkB;IACrG,MAAM,OAAO,GAAG,CAAC,IAAe,EAAE,OAAe,EAAE,EAAE,CAAC,CAAC,GAAM,EAAE,EAAE;QAC/D,IAAI,gBAAgB,EAAE;YACpB,OAAO,CAAC,KAAK,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAA;YAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,CAAC,QAAQ,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC,CAAC;IAEF,kCAAkC;IAClC,MAAM,OAAO,GAAG,CAAC,IAAe,EAAE,MAA8B,EAAE,EAAE,CAClE,CAAC,GAAM,EAAE,EAAE;QACT,IAAI;YACF,IAAI,CAAC,GAAG,CAAC,CAAC;SACX;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,CAAC;SACb;IACH,CAAC,CAAC;IAEJ,MAAM,QAAQ,GAAG,CAAC,IAAe,EAAE,OAAmB,EAAE,EAAE,CACxD,CAAC,GAAM,EAAE,EAAE;QACT,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IAEJ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAClC,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,IAAI,CAAC,WAAW,CAAC,EACjB,IAAI,CAAC,CAAC,CAAC,EACP,KAAK,CAAC,CAAC,CAAC,CACT,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACzD,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,IAAI,CAAC,WAAW,CAAC,EACjB,IAAI,CAAC,CAAC,CAAC,CACR,CAAC,SAAS,CACT,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;AACL,CAAC"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..d81f4cd --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,273 @@ +import { FrameworkConfiguration } from 'aurelia-framework'; +import { Logger } from 'aurelia-logging'; +import { Observable } from 'rxjs'; + +export interface StateHistory { + past: T[]; + present: T; + future: T[]; +} +export interface HistoryOptions { + undoable: boolean; + limit?: number; +} +export declare function jump(state: T, n: number): T | StateHistory; +export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; +export declare function applyLimits(state: T, limit: number): T; +export declare function isStateHistory(history: any): history is StateHistory; +export interface CallingAction { + name: string; + params?: any[]; +} +export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; +export declare enum MiddlewarePlacement { + Before = "before", + After = "after" +} +export declare function logMiddleware(state: T, _: T, settings?: any): void; +export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; +export declare function rehydrateFromLocalStorage(state: T, key?: string): any; +export declare enum LogLevel { + trace = "trace", + debug = "debug", + info = "info", + log = "log", + warn = "warn", + error = "error" +} +export declare class LoggerIndexed extends Logger { + [key: string]: any; +} +export interface LogDefinitions { + performanceLog?: LogLevel; + dispatchedActions?: LogLevel; + devToolsStatus?: LogLevel; +} +export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; +export interface Action { + type: T; + params?: any[]; +} +export interface ActionCreator { + (...args: any[]): T; +} +export interface DevToolsOptions { + /** + * If disable is true, devtools monitoring + * will be disabled in the browser (disallowing a user to see your state using Redux Dev Tools) + */ + disable?: boolean; + /** + * the instance name to be showed on the monitor page. Default value is `document.title`. + * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. + */ + name?: string; + /** + * action creators functions to be available in the Dispatcher. + */ + actionCreators?: ActionCreator[] | { + [key: string]: ActionCreator; + }; + /** + * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. + * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. + * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). + * + * @default 500 ms. + */ + latency?: number; + /** + * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. + * + * @default 50 + */ + maxAge?: number; + /** + * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). + * - `false` - will handle also circular references. + * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. + * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. + * For each of them you can indicate if to include (by setting as `true`). + * For `function` key you can also specify a custom function which handles serialization. + * See [`jsan`](https://github.com/kolodny/jsan) for more details. + */ + serialize?: boolean | { + date?: boolean; + regex?: boolean; + undefined?: boolean; + error?: boolean; + symbol?: boolean; + map?: boolean; + set?: boolean; + function?: boolean | Function; + }; + /** + * function which takes `action` object and id number as arguments, and should return `action` object back. + */ + actionSanitizer?: (action: A, id: number) => A; + /** + * function which takes `state` object and index as arguments, and should return `state` object back. + */ + stateSanitizer?: (state: S, index: number) => S; + /** + * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). + * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. + */ + actionsBlacklist?: string[]; + /** + * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). + * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. + */ + actionsWhitelist?: string[]; + /** + * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. + * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. + */ + predicate?: (state: S, action: A) => boolean; + /** + * if specified as `false`, it will not record the changes till clicking on `Start recording` button. + * Available only for Redux enhancer, for others use `autoPause`. + * + * @default true + */ + shouldRecordChanges?: boolean; + /** + * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. + * If not specified, will commit when paused. Available only for Redux enhancer. + * + * @default "@@PAUSED"" + */ + pauseActionType?: string; + /** + * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. + * Not available for Redux enhancer (as it already does it but storing the data to be sent). + * + * @default false + */ + autoPause?: boolean; + /** + * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. + * Available only for Redux enhancer. + * + * @default false + */ + shouldStartLocked?: boolean; + /** + * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. + * + * @default true + */ + shouldHotReload?: boolean; + /** + * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. + * + * @default false + */ + shouldCatchErrors?: boolean; + /** + * If you want to restrict the extension, specify the features you allow. + * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. + * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. + * Otherwise, you'll get/set the data right from the monitor part. + */ + features?: { + /** + * start/pause recording of dispatched actions + */ + pause?: boolean; + /** + * lock/unlock dispatching actions and side effects + */ + lock?: boolean; + /** + * persist states on page reloading + */ + persist?: boolean; + /** + * export history of actions in a file + */ + export?: boolean | "custom"; + /** + * import history of actions from a file + */ + import?: boolean | "custom"; + /** + * jump back and forth (time travelling) + */ + jump?: boolean; + /** + * skip (cancel) actions + */ + skip?: boolean; + /** + * drag and drop actions in the history list + */ + reorder?: boolean; + /** + * dispatch custom actions or action creators + */ + dispatch?: boolean; + /** + * generate tests for the selected actions + */ + test?: boolean; + }; +} +export declare type Reducer = (state: T, ...params: P) => T | false | Promise; +export declare enum PerformanceMeasurement { + StartEnd = "startEnd", + All = "all" +} +export interface StoreOptions { + history?: Partial; + logDispatchedActions?: boolean; + measurePerformance?: PerformanceMeasurement; + propagateError?: boolean; + logDefinitions?: LogDefinitions; + devToolsOptions?: DevToolsOptions; +} +export declare class Store { + private initialState; + readonly state: Observable; + private logger; + private devToolsAvailable; + private devTools; + private actions; + private middlewares; + private _state; + private options; + private dispatchQueue; + constructor(initialState: T, options?: Partial); + registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; + unregisterMiddleware(reducer: Middleware): void; + isMiddlewareRegistered(middleware: Middleware): boolean; + registerAction(name: string, reducer: Reducer): void; + unregisterAction(reducer: Reducer): void; + isActionRegistered(reducer: Reducer | string): boolean; + resetToState(state: T): void; + dispatch

(reducer: Reducer | string, ...params: P): Promise; + private handleQueue; + private internalDispatch; + private executeMiddlewares; + private setupDevTools; + private updateDevToolsState; + private registerHistoryMethods; +} +export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; +export declare type StepFn = (res: T) => void; +export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; +export interface ConnectToSettings { + onChanged?: string; + selector: ((store: Store) => Observable) | MultipleSelector; + setup?: string; + target?: string; + teardown?: string; +} +export interface MultipleSelector { + [key: string]: ((store: Store) => Observable); +} +export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; +export interface StorePluginOptions extends StoreOptions { + initialState: T; +} +export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; \ No newline at end of file diff --git a/dist/native-modules/aurelia-store.d.ts b/dist/native-modules/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/native-modules/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/native-modules/aurelia-store.js b/dist/native-modules/aurelia-store.js deleted file mode 100644 index d58660a..0000000 --- a/dist/native-modules/aurelia-store.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Store } from "./store"; -import { isStateHistory } from "./history"; -export function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - var initState = options.initialState; - if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(Store, new Store(initState, options)); -} -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/native-modules/aurelia-store.js.map b/dist/native-modules/aurelia-store.js.map deleted file mode 100644 index 5e7cc9b..0000000 --- a/dist/native-modules/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAM3C,MAAM,UAAU,SAAS,CACvB,OAA+B,EAC/B,OAAuC;IAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;KACrE;IAED,OAAO,OAAO,CAAC,YAAY,CAAC;IAE5B,OAAO,CAAC,SAAS;SACd,gBAAgB,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"} \ No newline at end of file diff --git a/dist/native-modules/decorator.d.ts b/dist/native-modules/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/native-modules/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/native-modules/decorator.js b/dist/native-modules/decorator.js deleted file mode 100644 index bfbb898..0000000 --- a/dist/native-modules/decorator.js +++ /dev/null @@ -1,100 +0,0 @@ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(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); -}; -import { Container } from "aurelia-dependency-injection"; -import { Observable, Subscription } from "rxjs"; -import { Store } from "./store"; -var defaultSelector = function (store) { return store.state; }; -export function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - var store = Container.instance.get(Store); - var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - var source = selector(store); - if (source instanceof Observable) { - return source; - } - return store.state; - } - function createSelectors() { - var _a; - var isSelectorObj = typeof _settings.selector === "object"; - var fallbackSelector = (_a = {}, - _a[_settings.target || "state"] = _settings.selector || defaultSelector, - _a); - return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { - var target = _a[0], selector = _a[1]; - var _b; - return ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector: selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: (_b = {}, - _b[_settings.onChanged || ""] = 1, - _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, - _b["propertyChanged"] = 0, - _b) - }); - }); - } - return function (target) { - var originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - var originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - var _this = this; - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { - var lastTargetIdx = s.targets.length - 1; - var oldState = s.targets.reduce(function (accu, curr) { - if (accu === void 0) { accu = {}; } - return accu[curr]; - }, _this); - Object.entries(s.changeHandlers).forEach(function (_a) { - var handlerName = _a[0], args = _a[1]; - if (handlerName in _this) { - _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce(function (accu, curr, idx) { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, _this); - }); }); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach(function (sub) { - if (sub instanceof Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; -} -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/native-modules/decorator.js.map b/dist/native-modules/decorator.js.map deleted file mode 100644 index 90fb621..0000000 --- a/dist/native-modules/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAchC,IAAM,eAAe,GAAG,UAAI,KAAe,IAAK,O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AI,CAAC,mBAAmB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBACvE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAC,GAAiB;oBACjD,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;wBACvD,GAAG,CAAC,WAAW,EAAE,CAAC;qBACnB;gBACH,CAAC,CAAC,CAAC;aACJ;YAED,IAAI,gBAAgB,EAAE;gBACpB,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAChD;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/dist/native-modules/devtools.d.ts b/dist/native-modules/devtools.d.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/native-modules/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/native-modules/devtools.js b/dist/native-modules/devtools.js deleted file mode 100644 index 947dd8e..0000000 --- a/dist/native-modules/devtools.js +++ /dev/null @@ -1 +0,0 @@ -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/native-modules/devtools.js.map b/dist/native-modules/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/native-modules/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/native-modules/history.d.ts b/dist/native-modules/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/native-modules/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/native-modules/history.js b/dist/native-modules/history.js deleted file mode 100644 index a612bd7..0000000 --- a/dist/native-modules/history.js +++ /dev/null @@ -1,56 +0,0 @@ -export function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; -} -function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.concat([present], future.slice(0, index)); - var newPresent = future[index]; - var newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; -} -function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.slice(0, index); - var newFuture = past.slice(index + 1).concat([present], future); - var newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; -} -export function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: presentStateHistory.past.concat([presentStateHistory.present]), - present: nextPresent, - future: [] - }); -} -export function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; -} -export function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); -} -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/native-modules/history.js.map b/dist/native-modules/history.js.map deleted file mode 100644 index fa91533..0000000 --- a/dist/native-modules/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,IAAI,CAAI,KAAQ,EAAE,CAAS;IACzC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO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AAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAI,mBAAoC,EAAE,WAAc;IACtF,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,mBAAmB,EACnB;QACE,IAAI,EAAM,mBAAmB,CAAC,IAAI,SAAE,mBAAmB,CAAC,OAAO,EAAC;QAChE,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,EAAE;KACX,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAI,KAAQ,EAAE,KAAa;IACpD,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE;QACzB,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE;YAC7B,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;SAC1D;QAED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE;YAC/B,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAY;IACzC,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,WAAW;QAC3C,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW;QACrC,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW;QACnC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"} \ No newline at end of file diff --git a/dist/es2015/store.js b/dist/native-modules/index.js similarity index 52% rename from dist/es2015/store.js rename to dist/native-modules/index.js index 55da686..a0753a6 100644 --- a/dist/es2015/store.js +++ b/dist/native-modules/index.js @@ -1,46 +1,206 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); +import { PLATFORM } from 'aurelia-pal'; +import { Logger, getLogger } from 'aurelia-logging'; +import { BehaviorSubject, Observable, Subscription } from 'rxjs'; +import { Container } from 'aurelia-dependency-injection'; +import { delay, skip, take } from 'rxjs/operators'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/* 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 (b.hasOwnProperty(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 __awaiter(thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(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 }; + } +} + +function jump(state, n) { + if (!isStateHistory(state)) { + return state; + } + if (n > 0) + return jumpToFuture(state, n - 1); + if (n < 0) + return jumpToPast(state, state.past.length + n); + return state; +} +function jumpToFuture(state, index) { + if (index < 0 || index >= state.future.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.concat([present], future.slice(0, index)); + var newPresent = future[index]; + var newFuture = future.slice(index + 1); + return { past: newPast, present: newPresent, future: newFuture }; +} +function jumpToPast(state, index) { + if (index < 0 || index >= state.past.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.slice(0, index); + var newFuture = past.slice(index + 1).concat([present], future); + var newPresent = past[index]; + return { past: newPast, present: newPresent, future: newFuture }; +} +function nextStateHistory(presentStateHistory, nextPresent) { + return Object.assign({}, presentStateHistory, { + past: presentStateHistory.past.concat([presentStateHistory.present]), + present: nextPresent, + future: [] }); -}; -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 }; +} +function applyLimits(state, limit) { + if (isStateHistory(state)) { + if (state.past.length > limit) { + state.past = state.past.slice(state.past.length - limit); + } + if (state.future.length > limit) { + state.future = state.future.slice(0, limit); + } + } + return state; +} +function isStateHistory(history) { + return typeof history.present !== "undefined" && + typeof history.future !== "undefined" && + typeof history.past !== "undefined" && + Array.isArray(history.future) && + Array.isArray(history.past); +} + +var MiddlewarePlacement; +(function (MiddlewarePlacement) { + MiddlewarePlacement["Before"] = "before"; + MiddlewarePlacement["After"] = "after"; +})(MiddlewarePlacement || (MiddlewarePlacement = {})); +function logMiddleware(state, _, settings) { + if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { + console[settings.logType]("New state: ", state); + } + else { + console.log("New state: ", state); + } +} +function localStorageMiddleware(state, _, settings) { + if (PLATFORM.global.localStorage) { + var key = settings && settings.key && typeof settings.key === "string" + ? settings.key + : "aurelia-store-state"; + PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); + } +} +function rehydrateFromLocalStorage(state, key) { + if (!PLATFORM.global.localStorage) { + return state; + } + var storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); + if (!storedState) { + return state; + } + try { + return JSON.parse(storedState); + } + catch (e) { } + return state; +} + +var LogLevel; +(function (LogLevel) { + LogLevel["trace"] = "trace"; + LogLevel["debug"] = "debug"; + LogLevel["info"] = "info"; + LogLevel["log"] = "log"; + LogLevel["warn"] = "warn"; + LogLevel["error"] = "error"; +})(LogLevel || (LogLevel = {})); +var LoggerIndexed = /** @class */ (function (_super) { + __extends(LoggerIndexed, _super); + function LoggerIndexed() { + return _super !== null && _super.apply(this, arguments) || this; + } + return LoggerIndexed; +}(Logger)); +function getLogType(options, definition, defaultLevel) { + if (definition && + options.logDefinitions && + options.logDefinitions.hasOwnProperty(definition) && + options.logDefinitions[definition] && + Object.values(LogLevel).includes(options.logDefinitions[definition])) { + return options.logDefinitions[definition]; } -}; -import { BehaviorSubject } from "rxjs"; -import { Container } from "aurelia-dependency-injection"; -import { getLogger } from "aurelia-logging"; -import { PLATFORM } from "aurelia-pal"; -import { jump, applyLimits, isStateHistory } from "./history"; -import { MiddlewarePlacement } from "./middleware"; -import { LogLevel, getLogType } from "./logging"; -export var PerformanceMeasurement; + return defaultLevel; +} + +var PerformanceMeasurement; (function (PerformanceMeasurement) { PerformanceMeasurement["StartEnd"] = "startEnd"; PerformanceMeasurement["All"] = "all"; @@ -57,7 +217,9 @@ var Store = /** @class */ (function () { var isUndoable = this.options.history && this.options.history.undoable === true; this._state = new BehaviorSubject(initialState); this.state = this._state.asObservable(); - this.setupDevTools(); + if (!this.options.devToolsOptions || this.options.devToolsOptions.disable !== true) { + this.setupDevTools(); + } if (isUndoable) { this.registerHistoryMethods(); } @@ -160,7 +322,7 @@ var Store = /** @class */ (function () { throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); } PLATFORM.performance.mark("dispatch-start"); - action = this.actions.get(reducer); + action = __assign({}, this.actions.get(reducer), { params: params }); if (this.options.logDispatchedActions) { this.logger[getLogType(this.options, "dispatchedActions", LogLevel.info)]("Dispatching: " + action.type); } @@ -290,8 +452,7 @@ var Store = /** @class */ (function () { }; return Store; }()); -export { Store }; -export function dispatchify(action) { +function dispatchify(action) { var store = Container.instance.get(Store); return function () { var params = []; @@ -301,4 +462,148 @@ export function dispatchify(action) { return store.dispatch.apply(store, [action].concat(params)); }; } -//# sourceMappingURL=store.js.map \ No newline at end of file + +function executeSteps(store, shouldLogResults) { + var steps = []; + for (var _i = 2; _i < arguments.length; _i++) { + steps[_i - 2] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var logStep, tryStep, lastStep; + return __generator(this, function (_a) { + logStep = function (step, stepIdx) { return function (res) { + if (shouldLogResults) { + console.group("Step " + stepIdx); + console.log(res); + console.groupEnd(); + } + step(res); + }; }; + tryStep = function (step, reject) { + return function (res) { + try { + step(res); + } + catch (err) { + reject(err); + } + }; + }; + lastStep = function (step, resolve) { + return function (res) { + step(res); + resolve(); + }; + }; + return [2 /*return*/, new Promise(function (resolve, reject) { + var currentStep = 0; + steps.slice(0, -1).forEach(function (step) { + store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); + currentStep++; + }); + store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); + })]; + }); + }); +} + +var defaultSelector = function (store) { return store.state; }; +function connectTo(settings) { + if (!Object.entries) { + throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); + } + var store = Container.instance.get(Store); + var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); + function getSource(selector) { + var source = selector(store); + if (source instanceof Observable) { + return source; + } + return store.state; + } + function createSelectors() { + var _a; + var isSelectorObj = typeof _settings.selector === "object"; + var fallbackSelector = (_a = {}, + _a[_settings.target || "state"] = _settings.selector || defaultSelector, + _a); + return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { + var target = _a[0], selector = _a[1]; + var _b; + return ({ + targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], + selector: selector, + // numbers are the starting index to slice all the change handling args, + // which are prop name, new state and old state + changeHandlers: (_b = {}, + _b[_settings.onChanged || ""] = 1, + _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, + _b["propertyChanged"] = 0, + _b) + }); + }); + } + return function (target) { + var originalSetup = typeof settings === "object" && settings.setup + ? target.prototype[settings.setup] + : target.prototype.bind; + var originalTeardown = typeof settings === "object" && settings.teardown + ? target.prototype[settings.teardown] + : target.prototype.unbind; + target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { + var _this = this; + if (typeof settings == "object" && + typeof settings.onChanged === "string" && + !(settings.onChanged in this)) { + throw new Error("Provided onChanged handler does not exist on target VM"); + } + this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { + var lastTargetIdx = s.targets.length - 1; + var oldState = s.targets.reduce(function (accu, curr) { + if (accu === void 0) { accu = {}; } + return accu[curr]; + }, _this); + Object.entries(s.changeHandlers).forEach(function (_a) { + var handlerName = _a[0], args = _a[1]; + if (handlerName in _this) { + _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); + } + }); + s.targets.reduce(function (accu, curr, idx) { + accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; + return accu[curr]; + }, _this); + }); }); + if (originalSetup) { + return originalSetup.apply(this, arguments); + } + }; + target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { + if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { + this._stateSubscriptions.forEach(function (sub) { + if (sub instanceof Subscription && sub.closed === false) { + sub.unsubscribe(); + } + }); + } + if (originalTeardown) { + return originalTeardown.apply(this, arguments); + } + }; + }; +} + +function configure(aurelia, options) { + if (!options || !options.initialState) { + throw new Error("initialState must be provided via options"); + } + var initState = options.initialState; + if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { + initState = { past: [], present: options.initialState, future: [] }; + } + delete options.initialState; + aurelia.container + .registerInstance(Store, new Store(initState, options)); +} + +export { configure, PerformanceMeasurement, Store, dispatchify, executeSteps, jump, nextStateHistory, applyLimits, isStateHistory, MiddlewarePlacement, logMiddleware, localStorageMiddleware, rehydrateFromLocalStorage, LogLevel, LoggerIndexed, getLogType, connectTo }; diff --git a/dist/native-modules/logging.d.ts b/dist/native-modules/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/native-modules/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/native-modules/logging.js b/dist/native-modules/logging.js deleted file mode 100644 index 9bcc9fc..0000000 --- a/dist/native-modules/logging.js +++ /dev/null @@ -1,42 +0,0 @@ -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 (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -import { Logger } from "aurelia-logging"; -export var LogLevel; -(function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; -})(LogLevel || (LogLevel = {})); -var LoggerIndexed = /** @class */ (function (_super) { - __extends(LoggerIndexed, _super); - function LoggerIndexed() { - return _super !== null && _super.apply(this, arguments) || this; - } - return LoggerIndexed; -}(Logger)); -export { LoggerIndexed }; -export function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; -} -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/native-modules/logging.js.map b/dist/native-modules/logging.js.map deleted file mode 100644 index f82279a..0000000 --- a/dist/native-modules/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;AAED;IAAmC,iCAAM;IAAzC;;IAEA,CAAC;IAAD,oBAAC;AAAD,CAAC,AAFD,CAAmC,MAAM,GAExC;;AAQD,MAAM,UAAU,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;IAEtB,IAAI,UAAU;QACZ,OAAO,CAAC,cAAc;QACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;QACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;QACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;KAC5C;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/dist/native-modules/middleware.d.ts b/dist/native-modules/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/native-modules/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/native-modules/middleware.js b/dist/native-modules/middleware.js deleted file mode 100644 index 672913f..0000000 --- a/dist/native-modules/middleware.js +++ /dev/null @@ -1,37 +0,0 @@ -import { PLATFORM } from "aurelia-pal"; -export var MiddlewarePlacement; -(function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; -})(MiddlewarePlacement || (MiddlewarePlacement = {})); -export function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } -} -export function localStorageMiddleware(state, _, settings) { - if (PLATFORM.global.localStorage) { - var key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } -} -export function rehydrateFromLocalStorage(state, key) { - if (!PLATFORM.global.localStorage) { - return state; - } - var storedState = PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; -} -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/native-modules/middleware.js.map b/dist/native-modules/middleware.js.map deleted file mode 100644 index 415b10b..0000000 --- a/dist/native-modules/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,sCAAe,CAAA;AACjB,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B;AAED,MAAM,UAAU,aAAa,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;IAC7D,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QAC3E,OAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;KAC1D;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;KACnC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;IACtE,IAAI,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;QAChC,IAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;YACtE,CAAC,CAAC,QAAQ,CAAC,GAAG;YACd,CAAC,CAAC,qBAAqB,CAAC;QAE1B,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;KAClE;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAI,KAAQ,EAAE,GAAY;IACjE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;QACjC,OAAO,KAAK,CAAC;KACd;IAED,IAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;IACvF,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAY,CAAC,CAAC;KACjC;IAAC,OAAO,CAAC,EAAE,GAAG;IAEf,OAAO,KAAK,CAAC;AACf,CAAC"} \ No newline at end of file diff --git a/dist/native-modules/store.d.ts b/dist/native-modules/store.d.ts deleted file mode 100644 index 01189ea..0000000 --- a/dist/native-modules/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/native-modules/store.js b/dist/native-modules/store.js deleted file mode 100644 index 55da686..0000000 --- a/dist/native-modules/store.js +++ /dev/null @@ -1,304 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -import { BehaviorSubject } from "rxjs"; -import { Container } from "aurelia-dependency-injection"; -import { getLogger } from "aurelia-logging"; -import { PLATFORM } from "aurelia-pal"; -import { jump, applyLimits, isStateHistory } from "./history"; -import { MiddlewarePlacement } from "./middleware"; -import { LogLevel, getLogType } from "./logging"; -export var PerformanceMeasurement; -(function (PerformanceMeasurement) { - PerformanceMeasurement["StartEnd"] = "startEnd"; - PerformanceMeasurement["All"] = "all"; -})(PerformanceMeasurement || (PerformanceMeasurement = {})); -var Store = /** @class */ (function () { - function Store(initialState, options) { - this.initialState = initialState; - this.logger = getLogger("aurelia-store"); - this.devToolsAvailable = false; - this.actions = new Map(); - this.middlewares = new Map(); - this.dispatchQueue = []; - this.options = options || {}; - var isUndoable = this.options.history && this.options.history.undoable === true; - this._state = new BehaviorSubject(initialState); - this.state = this._state.asObservable(); - this.setupDevTools(); - if (isUndoable) { - this.registerHistoryMethods(); - } - } - Store.prototype.registerMiddleware = function (reducer, placement, settings) { - this.middlewares.set(reducer, { placement: placement, settings: settings }); - }; - Store.prototype.unregisterMiddleware = function (reducer) { - if (this.middlewares.has(reducer)) { - this.middlewares.delete(reducer); - } - }; - Store.prototype.isMiddlewareRegistered = function (middleware) { - return this.middlewares.has(middleware); - }; - Store.prototype.registerAction = function (name, reducer) { - if (reducer.length === 0) { - throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); - } - this.actions.set(reducer, { type: name }); - }; - Store.prototype.unregisterAction = function (reducer) { - if (this.actions.has(reducer)) { - this.actions.delete(reducer); - } - }; - Store.prototype.isActionRegistered = function (reducer) { - if (typeof reducer === "string") { - return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; - } - return this.actions.has(reducer); - }; - Store.prototype.resetToState = function (state) { - this._state.next(state); - }; - Store.prototype.dispatch = function (reducer) { - var _this = this; - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - var action; - if (typeof reducer === "string") { - var result = Array.from(this.actions) - .find(function (val) { return val[1].type === reducer; }); - if (result) { - action = result[0]; - } - } - else { - action = reducer; - } - return new Promise(function (resolve, reject) { - _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); - if (_this.dispatchQueue.length === 1) { - _this.handleQueue(); - } - }); - }; - Store.prototype.handleQueue = function () { - return __awaiter(this, void 0, void 0, function () { - var queueItem, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; - queueItem = this.dispatchQueue[0]; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; - case 2: - _a.sent(); - queueItem.resolve(); - return [3 /*break*/, 4]; - case 3: - e_1 = _a.sent(); - queueItem.reject(e_1); - return [3 /*break*/, 4]; - case 4: - this.dispatchQueue.shift(); - this.handleQueue(); - _a.label = 5; - case 5: return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.internalDispatch = function (reducer) { - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.actions.has(reducer)) { - throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); - } - PLATFORM.performance.mark("dispatch-start"); - action = this.actions.get(reducer); - if (this.options.logDispatchedActions) { - this.logger[getLogType(this.options, "dispatchedActions", LogLevel.info)]("Dispatching: " + action.type); - } - return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), MiddlewarePlacement.Before, { - name: action.type, - params: params - })]; - case 1: - beforeMiddleswaresResult = _a.sent(); - if (beforeMiddleswaresResult === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; - case 2: - result = _a.sent(); - if (result === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); - if (!result && typeof result !== "object") { - throw new Error("The reducer has to return a new state"); - } - return [4 /*yield*/, this.executeMiddlewares(result, MiddlewarePlacement.After, { - name: action.type, - params: params - })]; - case 3: - resultingState = _a.sent(); - if (resultingState === false) { - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - if (isStateHistory(resultingState) && - this.options.history && - this.options.history.limit) { - resultingState = applyLimits(resultingState, this.options.history.limit); - } - this._state.next(resultingState); - PLATFORM.performance.mark("dispatch-end"); - if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { - PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); - measures = PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); - this.logger[getLogType(this.options, "performanceLog", LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); - } - else if (this.options.measurePerformance === PerformanceMeasurement.All) { - marks = PLATFORM.performance.getEntriesByType("mark"); - totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; - this.logger[getLogType(this.options, "performanceLog", LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); - } - PLATFORM.performance.clearMarks(); - PLATFORM.performance.clearMeasures(); - this.updateDevToolsState(action, resultingState); - return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.executeMiddlewares = function (state, placement, action) { - var _this = this; - return Array.from(this.middlewares) - .filter(function (middleware) { return middleware[1].placement === placement; }) - .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { - var result, _a, _b, _c, e_2; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _d.trys.push([0, 5, 7, 8]); - _b = (_a = curr)[0]; - return [4 /*yield*/, prev]; - case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; - case 2: - result = _d.sent(); - if (result === false) { - _arr = []; - return [2 /*return*/, false]; - } - _c = result; - if (_c) return [3 /*break*/, 4]; - return [4 /*yield*/, prev]; - case 3: - _c = (_d.sent()); - _d.label = 4; - case 4: return [2 /*return*/, _c]; - case 5: - e_2 = _d.sent(); - if (this.options.propagateError) { - _arr = []; - throw e_2; - } - return [4 /*yield*/, prev]; - case 6: return [2 /*return*/, _d.sent()]; - case 7: - PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); - return [7 /*endfinally*/]; - case 8: return [2 /*return*/]; - } - }); - }); }, state); - }; - Store.prototype.setupDevTools = function () { - var _this = this; - if (PLATFORM.global.devToolsExtension) { - this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)]("DevTools are available"); - this.devToolsAvailable = true; - this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); - this.devTools.init(this.initialState); - this.devTools.subscribe(function (message) { - _this.logger[getLogType(_this.options, "devToolsStatus", LogLevel.debug)]("DevTools sent change " + message.type); - if (message.type === "DISPATCH") { - _this._state.next(JSON.parse(message.state)); - } - }); - } - }; - Store.prototype.updateDevToolsState = function (action, state) { - if (this.devToolsAvailable) { - this.devTools.send(action, state); - } - }; - Store.prototype.registerHistoryMethods = function () { - this.registerAction("jump", jump); - }; - return Store; -}()); -export { Store }; -export function dispatchify(action) { - var store = Container.instance.get(Store); - return function () { - var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - return store.dispatch.apply(store, [action].concat(params)); - }; -} -//# sourceMappingURL=store.js.map \ No newline at end of file diff --git a/dist/native-modules/store.js.map b/dist/native-modules/store.js.map deleted file mode 100644 index d2c7d2a..0000000 --- a/dist/native-modules/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAc,MAAM,MAAM,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAkB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAc,mBAAmB,EAAiB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAkB,QAAQ,EAAE,UAAU,EAAiB,MAAM,WAAW,CAAC;AAKhF,MAAM,CAAN,IAAY,sB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AAC,CAAC,CAAC,0BAAwB,OAAO,CAAC,IAAM,CAAC,CAAC;gBAEhH,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;oBAC/B,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;iBAC7C;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAEO,mCAAmB,GAA3B,UAA4B,MAAsB,EAAE,KAAQ;QAC1D,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAEO,sCAAsB,GAA9B;QACE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,IAAyB,CAAC,CAAC;IACzD,CAAC;IACH,YAAC;AAAD,CAAC,AA1PD,IA0PC;;AAED,MAAM,UAAU,WAAW,CAAqB,MAA8B;IAC5E,IAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAE5C,OAAO;QAAU,gBAAY;aAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;YAAZ,2BAAY;;QAC3B,OAAO,KAAK,CAAC,QAAQ,OAAd,KAAK,GAAU,MAAM,SAAK,MAAM,EAAkB,CAAC;IAC5D,CAAC,CAAA;AACH,CAAC"} \ No newline at end of file diff --git a/dist/native-modules/test-helpers.d.ts b/dist/native-modules/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/native-modules/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/native-modules/test-helpers.js b/dist/native-modules/test-helpers.js deleted file mode 100644 index 7f9c480..0000000 --- a/dist/native-modules/test-helpers.js +++ /dev/null @@ -1,80 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -import { delay, skip, take } from "rxjs/operators"; -export function executeSteps(store, shouldLogResults) { - var steps = []; - for (var _i = 2; _i < arguments.length; _i++) { - steps[_i - 2] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var logStep, tryStep, lastStep; - return __generator(this, function (_a) { - logStep = function (step, stepIdx) { return function (res) { - if (shouldLogResults) { - console.group("Step " + stepIdx); - console.log(res); - console.groupEnd(); - } - step(res); - }; }; - tryStep = function (step, reject) { - return function (res) { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - }; - lastStep = function (step, resolve) { - return function (res) { - step(res); - resolve(); - }; - }; - return [2 /*return*/, new Promise(function (resolve, reject) { - var currentStep = 0; - steps.slice(0, -1).forEach(function (step) { - store.state.pipe(skip(currentStep), take(1), delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(skip(currentStep), take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - })]; - }); - }); -} -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/native-modules/test-helpers.js.map b/dist/native-modules/test-helpers.js.map deleted file mode 100644 index 2ba69c5..0000000 --- a/dist/native-modules/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAOnD,MAAM,UAAgB,YAAY,CAAI,KAAe,EAAE,gBAAyB;IAAE,eAAqB;SAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;QAArB,8BAAqB;;;;;YAC/F,OAAO,GAAG,UAAC,IAAe,EAAE,OAAe,IAAK,OAAA,UAAC,GAAM;gBAC3D,IAAI,gBAAgB,EAAE;oBACpB,OAAO,CAAC,KAAK,CAAC,UAAQ,OAAS,CAAC,CAAA;oBAChC,OAAO,CAAC,GAAG,CAAC,GA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C,CAAC,CAAC;gBACvF,CAAC,CAAC,EAAC;;;CACJ"} \ No newline at end of file diff --git a/dist/system/aurelia-store.d.ts b/dist/system/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/system/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/system/aurelia-store.js b/dist/system/aurelia-store.js deleted file mode 100644 index ff2df6f..0000000 --- a/dist/system/aurelia-store.js +++ /dev/null @@ -1,55 +0,0 @@ -System.register(["./store", "./history", "./test-helpers", "./middleware", "./logging", "./decorator"], function (exports_1, context_1) { - "use strict"; - var store_1, history_1; - var __moduleName = context_1 && context_1.id; - function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - var initState = options.initialState; - if (options && options.history && options.history.undoable && !history_1.isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(store_1.Store, new store_1.Store(initState, options)); - } - exports_1("configure", configure); - var exportedNames_1 = { - "configure": true - }; - function exportStar_1(m) { - var exports = {}; - for (var n in m) { - if (n !== "default" && !exportedNames_1.hasOwnProperty(n)) exports[n] = m[n]; - } - exports_1(exports); - } - return { - setters: [ - function (store_1_1) { - store_1 = store_1_1; - exportStar_1(store_1_1); - }, - function (history_1_1) { - history_1 = history_1_1; - exportStar_1(history_1_1); - }, - function (test_helpers_1_1) { - exportStar_1(test_helpers_1_1); - }, - function (middleware_1_1) { - exportStar_1(middleware_1_1); - }, - function (logging_1_1) { - exportStar_1(logging_1_1); - }, - function (decorator_1_1) { - exportStar_1(decorator_1_1); - } - ], - execute: function () { - } - }; -}); -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/system/aurelia-store.js.map b/dist/system/aurelia-store.js.map deleted file mode 100644 index 8c1bf4f..0000000 --- a/dist/system/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":";;;;IAQA,SAAgB,SAAS,CACvB,OAA+B,EAC/B,OAAuC;QAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;QAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,wBAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;SACrE;QAED,OAAO,OAAO,CAAC,YAAY,CAAC;QAE5B,OAAO,CAAC,SAAS;aACd,gBAAgB,CAAC,aAAK,EAAE,IAAI,aAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC"} \ No newline at end of file diff --git a/dist/system/decorator.d.ts b/dist/system/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/system/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/system/decorator.js b/dist/system/decorator.js deleted file mode 100644 index 04f1e8a..0000000 --- a/dist/system/decorator.js +++ /dev/null @@ -1,118 +0,0 @@ -System.register(["aurelia-dependency-injection", "rxjs", "./store"], function (exports_1, context_1) { - "use strict"; - var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(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); - }; - var aurelia_dependency_injection_1, rxjs_1, store_1, defaultSelector; - var __moduleName = context_1 && context_1.id; - function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - var store = aurelia_dependency_injection_1.Container.instance.get(store_1.Store); - var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - var source = selector(store); - if (source instanceof rxjs_1.Observable) { - return source; - } - return store.state; - } - function createSelectors() { - var _a; - var isSelectorObj = typeof _settings.selector === "object"; - var fallbackSelector = (_a = {}, - _a[_settings.target || "state"] = _settings.selector || defaultSelector, - _a); - return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { - var target = _a[0], selector = _a[1]; - var _b; - return ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector: selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: (_b = {}, - _b[_settings.onChanged || ""] = 1, - _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, - _b["propertyChanged"] = 0, - _b) - }); - }); - } - return function (target) { - var originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - var originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - var _this = this; - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { - var lastTargetIdx = s.targets.length - 1; - var oldState = s.targets.reduce(function (accu, curr) { - if (accu === void 0) { accu = {}; } - return accu[curr]; - }, _this); - Object.entries(s.changeHandlers).forEach(function (_a) { - var handlerName = _a[0], args = _a[1]; - if (handlerName in _this) { - _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce(function (accu, curr, idx) { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, _this); - }); }); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach(function (sub) { - if (sub instanceof rxjs_1.Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; - } - exports_1("connectTo", connectTo); - return { - setters: [ - function (aurelia_dependency_injection_1_1) { - aurelia_dependency_injection_1 = aurelia_dependency_injection_1_1; - }, - function (rxjs_1_1) { - rxjs_1 = rxjs_1_1; - }, - function (store_1_1) { - store_1 = store_1_1; - } - ], - execute: function () { - defaultSelector = function (store) { return store.state; }; - } - }; -}); -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/system/decorator.js.map b/dist/system/decorator.js.map deleted file mode 100644 index 3382375..0000000 --- a/dist/system/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;IAmBA,SAAgB,SAAS,CAAa,QAAyE;QAC7G,IAAI,CAAC,MAAM,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BACvE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAC,GAAiB;wBACjD,IAAI,GAAG,YAAY,mBAAY,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;4BACvD,GAAG,CAAC,WAAW,EAAE,CAAC;yBACnB;oBACH,CAAC,CAAC,CAAC;iBACJ;gBAED,IAAI,gBAAgB,EAAE;oBACpB,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;iBAChD;YACH,CAAC,CAAA;QACH,CAAC,CAAA;IACH,CAAC;;;;;;;;;;;;;;;YA9FK,eAAe,GAAG,UAAI,KAAe,IAAK,OAAA,KAAK,CAAC,KAAK,EAAX,CAAW,CAAC"} \ No newline at end of file diff --git a/dist/system/devtools.d.ts b/dist/system/devtools.d.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/system/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/system/devtools.js b/dist/system/devtools.js deleted file mode 100644 index 21a3f82..0000000 --- a/dist/system/devtools.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: function () { - } - }; -}); -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/system/devtools.js.map b/dist/system/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/system/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/system/history.d.ts b/dist/system/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/system/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/system/history.js b/dist/system/history.js deleted file mode 100644 index 270a4dd..0000000 --- a/dist/system/history.js +++ /dev/null @@ -1,69 +0,0 @@ -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; - } - exports_1("jump", jump); - function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.concat([present], future.slice(0, index)); - var newPresent = future[index]; - var newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; - } - function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.slice(0, index); - var newFuture = past.slice(index + 1).concat([present], future); - var newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; - } - function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: presentStateHistory.past.concat([presentStateHistory.present]), - present: nextPresent, - future: [] - }); - } - exports_1("nextStateHistory", nextStateHistory); - function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; - } - exports_1("applyLimits", applyLimits); - function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); - } - exports_1("isStateHistory", isStateHistory); - return { - setters: [], - execute: function () { - } - }; -}); -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/system/history.js.map b/dist/system/history.js.map deleted file mode 100644 index bf99955..0000000 --- a/dist/system/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceR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OAAO,CAAC,MAAM,CAAC;YAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC"} \ No newline at end of file diff --git a/dist/system/logging.d.ts b/dist/system/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/system/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/system/logging.js b/dist/system/logging.js deleted file mode 100644 index b247f04..0000000 --- a/dist/system/logging.js +++ /dev/null @@ -1,56 +0,0 @@ -System.register(["aurelia-logging"], function (exports_1, context_1) { - "use strict"; - 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; - })(); - var aurelia_logging_1, LogLevel, LoggerIndexed; - var __moduleName = context_1 && context_1.id; - function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; - } - exports_1("getLogType", getLogType); - return { - setters: [ - function (aurelia_logging_1_1) { - aurelia_logging_1 = aurelia_logging_1_1; - } - ], - execute: function () { - (function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; - })(LogLevel || (LogLevel = {})); - exports_1("LogLevel", LogLevel); - LoggerIndexed = /** @class */ (function (_super) { - __extends(LoggerIndexed, _super); - function LoggerIndexed() { - return _super !== null && _super.apply(this, arguments) || this; - } - return LoggerIndexed; - }(aurelia_logging_1.Logger)); - exports_1("LoggerIndexed", LoggerIndexed); - } - }; -}); -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/system/logging.js.map b/dist/system/logging.js.map deleted file mode 100644 index 1c7a5ec..0000000 --- a/dist/system/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;IAsBA,SAAgB,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;QAEtB,IAAI,UAAU;YACZ,OAAO,CAAC,cAAc;YACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;YACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;YACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;SAC5C;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;;;;;;;;;YAjCD,WAAY,QAAQ;gBAClB,2BAAe,CAAA;gBACf,2BAAe,CAAA;gBACf,yBAAa,CAAA;gBACb,uBAAW,CAAA;gBACX,yBAAa,CAAA;gBACb,2BAAe,CAAA;YACjB,CAAC,EAPW,QAAQ,KAAR,QAAQ,QAOnB;;YAED;gBAAmC,iCAAM;gBAAzC;;gBAEA,CAAC;gBAAD,oBAAC;YAAD,CAAC,AAFD,CAAmC,wBAAM,GAExC"} \ No newline at end of file diff --git a/dist/system/middleware.d.ts b/dist/system/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/system/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/system/middleware.js b/dist/system/middleware.js deleted file mode 100644 index e877d52..0000000 --- a/dist/system/middleware.js +++ /dev/null @@ -1,53 +0,0 @@ -System.register(["aurelia-pal"], function (exports_1, context_1) { - "use strict"; - var aurelia_pal_1, MiddlewarePlacement; - var __moduleName = context_1 && context_1.id; - function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } - } - exports_1("logMiddleware", logMiddleware); - function localStorageMiddleware(state, _, settings) { - if (aurelia_pal_1.PLATFORM.global.localStorage) { - var key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - aurelia_pal_1.PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } - } - exports_1("localStorageMiddleware", localStorageMiddleware); - function rehydrateFromLocalStorage(state, key) { - if (!aurelia_pal_1.PLATFORM.global.localStorage) { - return state; - } - var storedState = aurelia_pal_1.PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; - } - exports_1("rehydrateFromLocalStorage", rehydrateFromLocalStorage); - return { - setters: [ - function (aurelia_pal_1_1) { - aurelia_pal_1 = aurelia_pal_1_1; - } - ], - execute: function () { - (function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; - })(MiddlewarePlacement || (MiddlewarePlacement = {})); - exports_1("MiddlewarePlacement", MiddlewarePlacement); - } - }; -}); -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/system/middleware.js.map b/dist/system/middleware.js.map deleted file mode 100644 index b77428f..0000000 --- a/dist/system/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":";;;;IAaA,SAAgB,aAAa,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;QAC7D,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC3E,OAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SAC1D;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;;IAED,SAAgB,sBAAsB,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;QACtE,IAAI,sBAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;YAChC,IAAM,GAAG,GAAG,QAAQ,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;gBACtE,CAAC,CAAC,QAAQ,CAAC,GAAG;gBACd,CAAC,CAAC,qBAAqB,CAAC;YAE1B,sBAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;SAClE;IACH,CAAC;;IAED,SAAgB,yBAAyB,CAAI,KAAQ,EAAE,GAAY;QACjE,IAAI,CAAC,sBAAQ,CAAC,MAAM,CAAC,YAAY,EAAE;YACjC,OAAO,KAAK,CAAC;SACd;QAED,IAAM,WAAW,GAAG,sBAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;QACvF,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QAED,IAAI;YACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAY,CAAC,CAAC;SACjC;QAAC,OAAO,CAAC,EAAE,GAAG;QAEf,OAAO,KAAK,CAAC;IACf,CAAC;;;;;;;;;YAtCD,WAAY,mBAAmB;gBAC7B,wCAAiB,CAAA;gBACjB,sCAAe,CAAA;YACjB,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B"} \ No newline at end of file diff --git a/dist/system/store.d.ts b/dist/system/store.d.ts deleted file mode 100644 index 01189ea..0000000 --- a/dist/system/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/system/store.js b/dist/system/store.js deleted file mode 100644 index 6edd970..0000000 --- a/dist/system/store.js +++ /dev/null @@ -1,330 +0,0 @@ -System.register(["rxjs", "aurelia-dependency-injection", "aurelia-logging", "aurelia-pal", "./history", "./middleware", "./logging"], function (exports_1, context_1) { - "use strict"; - var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - }; - 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 rxjs_1, aurelia_dependency_injection_1, aurelia_logging_1, aurelia_pal_1, history_1, middleware_1, logging_1, PerformanceMeasurement, Store; - var __moduleName = context_1 && context_1.id; - function dispatchify(action) { - var store = aurelia_dependency_injection_1.Container.instance.get(Store); - return function () { - var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - return store.dispatch.apply(store, [action].concat(params)); - }; - } - exports_1("dispatchify", dispatchify); - return { - setters: [ - function (rxjs_1_1) { - rxjs_1 = rxjs_1_1; - }, - function (aurelia_dependency_injection_1_1) { - aurelia_dependency_injection_1 = aurelia_dependency_injection_1_1; - }, - function (aurelia_logging_1_1) { - aurelia_logging_1 = aurelia_logging_1_1; - }, - function (aurelia_pal_1_1) { - aurelia_pal_1 = aurelia_pal_1_1; - }, - function (history_1_1) { - history_1 = history_1_1; - }, - function (middleware_1_1) { - middleware_1 = middleware_1_1; - }, - function (logging_1_1) { - logging_1 = logging_1_1; - } - ], - execute: function () { - (function (PerformanceMeasurement) { - PerformanceMeasurement["StartEnd"] = "startEnd"; - PerformanceMeasurement["All"] = "all"; - })(PerformanceMeasurement || (PerformanceMeasurement = {})); - exports_1("PerformanceMeasurement", PerformanceMeasurement); - Store = /** @class */ (function () { - function Store(initialState, options) { - this.initialState = initialState; - this.logger = aurelia_logging_1.getLogger("aurelia-store"); - this.devToolsAvailable = false; - this.actions = new Map(); - this.middlewares = new Map(); - this.dispatchQueue = []; - this.options = options || {}; - var isUndoable = this.options.history && this.options.history.undoable === true; - this._state = new rxjs_1.BehaviorSubject(initialState); - this.state = this._state.asObservable(); - this.setupDevTools(); - if (isUndoable) { - this.registerHistoryMethods(); - } - } - Store.prototype.registerMiddleware = function (reducer, placement, settings) { - this.middlewares.set(reducer, { placement: placement, settings: settings }); - }; - Store.prototype.unregisterMiddleware = function (reducer) { - if (this.middlewares.has(reducer)) { - this.middlewares.delete(reducer); - } - }; - Store.prototype.isMiddlewareRegistered = function (middleware) { - return this.middlewares.has(middleware); - }; - Store.prototype.registerAction = function (name, reducer) { - if (reducer.length === 0) { - throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); - } - this.actions.set(reducer, { type: name }); - }; - Store.prototype.unregisterAction = function (reducer) { - if (this.actions.has(reducer)) { - this.actions.delete(reducer); - } - }; - Store.prototype.isActionRegistered = function (reducer) { - if (typeof reducer === "string") { - return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; - } - return this.actions.has(reducer); - }; - Store.prototype.resetToState = function (state) { - this._state.next(state); - }; - Store.prototype.dispatch = function (reducer) { - var _this = this; - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - var action; - if (typeof reducer === "string") { - var result = Array.from(this.actions) - .find(function (val) { return val[1].type === reducer; }); - if (result) { - action = result[0]; - } - } - else { - action = reducer; - } - return new Promise(function (resolve, reject) { - _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); - if (_this.dispatchQueue.length === 1) { - _this.handleQueue(); - } - }); - }; - Store.prototype.handleQueue = function () { - return __awaiter(this, void 0, void 0, function () { - var queueItem, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; - queueItem = this.dispatchQueue[0]; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; - case 2: - _a.sent(); - queueItem.resolve(); - return [3 /*break*/, 4]; - case 3: - e_1 = _a.sent(); - queueItem.reject(e_1); - return [3 /*break*/, 4]; - case 4: - this.dispatchQueue.shift(); - this.handleQueue(); - _a.label = 5; - case 5: return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.internalDispatch = function (reducer) { - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.actions.has(reducer)) { - throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-start"); - action = this.actions.get(reducer); - if (this.options.logDispatchedActions) { - this.logger[logging_1.getLogType(this.options, "dispatchedActions", logging_1.LogLevel.info)]("Dispatching: " + action.type); - } - return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), middleware_1.MiddlewarePlacement.Before, { - name: action.type, - params: params - })]; - case 1: - beforeMiddleswaresResult = _a.sent(); - if (beforeMiddleswaresResult === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; - case 2: - result = _a.sent(); - if (result === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); - if (!result && typeof result !== "object") { - throw new Error("The reducer has to return a new state"); - } - return [4 /*yield*/, this.executeMiddlewares(result, middleware_1.MiddlewarePlacement.After, { - name: action.type, - params: params - })]; - case 3: - resultingState = _a.sent(); - if (resultingState === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - if (history_1.isStateHistory(resultingState) && - this.options.history && - this.options.history.limit) { - resultingState = history_1.applyLimits(resultingState, this.options.history.limit); - } - this._state.next(resultingState); - aurelia_pal_1.PLATFORM.performance.mark("dispatch-end"); - if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { - aurelia_pal_1.PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); - measures = aurelia_pal_1.PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); - } - else if (this.options.measurePerformance === PerformanceMeasurement.All) { - marks = aurelia_pal_1.PLATFORM.performance.getEntriesByType("mark"); - totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); - } - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - this.updateDevToolsState(action, resultingState); - return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.executeMiddlewares = function (state, placement, action) { - var _this = this; - return Array.from(this.middlewares) - .filter(function (middleware) { return middleware[1].placement === placement; }) - .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { - var result, _a, _b, _c, e_2; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _d.trys.push([0, 5, 7, 8]); - _b = (_a = curr)[0]; - return [4 /*yield*/, prev]; - case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; - case 2: - result = _d.sent(); - if (result === false) { - _arr = []; - return [2 /*return*/, false]; - } - _c = result; - if (_c) return [3 /*break*/, 4]; - return [4 /*yield*/, prev]; - case 3: - _c = (_d.sent()); - _d.label = 4; - case 4: return [2 /*return*/, _c]; - case 5: - e_2 = _d.sent(); - if (this.options.propagateError) { - _arr = []; - throw e_2; - } - return [4 /*yield*/, prev]; - case 6: return [2 /*return*/, _d.sent()]; - case 7: - aurelia_pal_1.PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); - return [7 /*endfinally*/]; - case 8: return [2 /*return*/]; - } - }); - }); }, state); - }; - Store.prototype.setupDevTools = function () { - var _this = this; - if (aurelia_pal_1.PLATFORM.global.devToolsExtension) { - this.logger[logging_1.getLogType(this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools are available"); - this.devToolsAvailable = true; - this.devTools = aurelia_pal_1.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); - this.devTools.init(this.initialState); - this.devTools.subscribe(function (message) { - _this.logger[logging_1.getLogType(_this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools sent change " + message.type); - if (message.type === "DISPATCH") { - _this._state.next(JSON.parse(message.state)); - } - }); - } - }; - Store.prototype.updateDevToolsState = function (action, state) { - if (this.devToolsAvailable) { - this.devTools.send(action, state); - } - }; - Store.prototype.registerHistoryMethods = function () { - this.registerAction("jump", history_1.jump); - }; - return Store; - }()); - exports_1("Store", Store); - } - }; -}); -//# sourceMappingURL=store.js.map \ No newline at end of file diff --git a/dist/system/store.js.map b/dist/system/store.js.map deleted file mode 100644 index 92ab5fe..0000000 --- a/dist/system/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8RA,SAAgB,WAAW,CAAqB,MAA8B;QAC5E,IAAM,KAAK,GAAG,wCAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE5C,OAAO;YAAU,gBAAY;iBAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;gBAAZ,2BAAY;;YAC3B,OAAO,KAAK,CAAC,QAAQ,OAAd,KAAK,GAAU,MAAM,SAAK,MAAM,EAAkB,CAAC;QAC5D,CAAC,CAAA;IACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;YAvRD,WAAY,sBAAsB;gBAChC,+CAAqB,CAAA;gBACr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AAI,CAAC,MAAM,CAAC,oBAAU,CAAC,KAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,kBAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,0BAAwB,OAAO,CAAC,IAAM,CAAC,CAAC;4BAEhH,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE;gCAC/B,KAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;6BAC7C;wBACH,CAAC,CAAC,CAAC;qBACJ;gBACH,CAAC;gBAEO,mCAAmB,GAA3B,UAA4B,MAAsB,EAAE,KAAQ;oBAC1D,IAAI,IAAI,CAAC,iBAAiB,EAAE;wBAC1B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;qBACnC;gBACH,CAAC;gBAEO,sCAAsB,GAA9B;oBACE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,cAAyB,CAAC,CAAC;gBACzD,CAAC;gBACH,YAAC;YAAD,CAAC,AA1PD,IA0PC"} \ No newline at end of file diff --git a/dist/system/test-helpers.d.ts b/dist/system/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/system/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/system/test-helpers.js b/dist/system/test-helpers.js deleted file mode 100644 index 2dbdba8..0000000 --- a/dist/system/test-helpers.js +++ /dev/null @@ -1,94 +0,0 @@ -System.register(["rxjs/operators"], function (exports_1, context_1) { - "use strict"; - var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - }; - 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 operators_1; - var __moduleName = context_1 && context_1.id; - function executeSteps(store, shouldLogResults) { - var steps = []; - for (var _i = 2; _i < arguments.length; _i++) { - steps[_i - 2] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var logStep, tryStep, lastStep; - return __generator(this, function (_a) { - logStep = function (step, stepIdx) { return function (res) { - if (shouldLogResults) { - console.group("Step " + stepIdx); - console.log(res); - console.groupEnd(); - } - step(res); - }; }; - tryStep = function (step, reject) { - return function (res) { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - }; - lastStep = function (step, resolve) { - return function (res) { - step(res); - resolve(); - }; - }; - return [2 /*return*/, new Promise(function (resolve, reject) { - var currentStep = 0; - steps.slice(0, -1).forEach(function (step) { - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1), operators_1.delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - })]; - }); - }); - } - exports_1("executeSteps", executeSteps); - return { - setters: [ - function (operators_1_1) { - operators_1 = operators_1_1; - } - ], - execute: function () { - } - }; -}); -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/system/test-helpers.js.map b/dist/system/test-helpers.js.map deleted file mode 100644 index b4cf83b..0000000 --- a/dist/system/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOA,SAAsB,YAAY,CAAI,KAAe,EAAE,gBAAyB;QAAE,eAAqB;aAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;YAArB,8BAAqB;;;;;gBAC/F,OAAO,GAAG,UAAC,IAAe,EAAE,OAAe,IAAK,OAAA,UAAC,GAAM;oBAC3D,IAAI,gBAAgB,EAAE;wBACpB,OAAO,CAAC,KAAK,CAAC,UAAQ,OAAS,CAAC,CAAA;wBAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACjB,OAAO,CAAC,QAAQ,EAAE,CAAC;qBACpB;oBACD,IAAI,CAAC,GAAG,CAAC,CAAC;gBACZ,CAAC,EAPqD,CAOrD,CAAC;gBAGI,OAAO,GAAG,UAAC,IAAe,EAAE,MAA8B;oBAC9D,OAAA,UAAC,GAAM;wBACL,IAAI;4BACF,IAAI,CAAC,GAAG,CAAC,CAAC;yBACX;wBAAC,OAAO,GAAG,EAAE;4BACZ,MAAM,CAAC,GAAG,CAAC,CAAC;yBACb;oBACH,CAAC;gBAND,CAMC,CAAC;gBAEE,QAAQ,GAAG,UAAC,IAAe,EAAE,OAAmB;oBACpD,OAAA,UAAC,GAAM;wBACL,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO,EAAE,CAAC;oBACZ,CAAC;gBAHD,CAGC,CAAC;gBAEJ,sBAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBACjC,IAAI,WAAW,GAAG,CAAC,CAAC;wBAEpB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAC,IAAI;4BAC9B,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,EACP,iBAAK,CAAC,CAAC,CAAC,CACT,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;4BACzD,WAAW,EAAE,CAAC;wBAChB,CAAC,CAAC,CAAC;wBAEH,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,CACR,CAAC,SAAS,CACT,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;oBACvF,CAAC,CAAC,EAAC;;;KACJ"} \ No newline at end of file

(reducer: Reducer | string, ...params: P): Promise; - private handleQueue; - private internalDispatch; - private executeMiddlewares; - private setupDevTools; - private updateDevToolsState; - private registerHistoryMethods; -} -export declare function dispatchify(action: Reducer | string): (...params: P) => Promise; diff --git a/dist/amd/store.js b/dist/amd/store.js deleted file mode 100644 index 1eb4c12..0000000 --- a/dist/amd/store.js +++ /dev/null @@ -1,302 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -define(["require", "exports", "rxjs", "aurelia-dependency-injection", "aurelia-logging", "aurelia-pal", "./history", "./middleware", "./logging"], function (require, exports, rxjs_1, aurelia_dependency_injection_1, aurelia_logging_1, aurelia_pal_1, history_1, middleware_1, logging_1) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - var PerformanceMeasurement; - (function (PerformanceMeasurement) { - PerformanceMeasurement["StartEnd"] = "startEnd"; - PerformanceMeasurement["All"] = "all"; - })(PerformanceMeasurement = exports.PerformanceMeasurement || (exports.PerformanceMeasurement = {})); - var Store = /** @class */ (function () { - function Store(initialState, options) { - this.initialState = initialState; - this.logger = aurelia_logging_1.getLogger("aurelia-store"); - this.devToolsAvailable = false; - this.actions = new Map(); - this.middlewares = new Map(); - this.dispatchQueue = []; - this.options = options || {}; - var isUndoable = this.options.history && this.options.history.undoable === true; - this._state = new rxjs_1.BehaviorSubject(initialState); - this.state = this._state.asObservable(); - this.setupDevTools(); - if (isUndoable) { - this.registerHistoryMethods(); - } - } - Store.prototype.registerMiddleware = function (reducer, placement, settings) { - this.middlewares.set(reducer, { placement: placement, settings: settings }); - }; - Store.prototype.unregisterMiddleware = function (reducer) { - if (this.middlewares.has(reducer)) { - this.middlewares.delete(reducer); - } - }; - Store.prototype.isMiddlewareRegistered = function (middleware) { - return this.middlewares.has(middleware); - }; - Store.prototype.registerAction = function (name, reducer) { - if (reducer.length === 0) { - throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); - } - this.actions.set(reducer, { type: name }); - }; - Store.prototype.unregisterAction = function (reducer) { - if (this.actions.has(reducer)) { - this.actions.delete(reducer); - } - }; - Store.prototype.isActionRegistered = function (reducer) { - if (typeof reducer === "string") { - return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; - } - return this.actions.has(reducer); - }; - Store.prototype.resetToState = function (state) { - this._state.next(state); - }; - Store.prototype.dispatch = function (reducer) { - var _this = this; - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - var action; - if (typeof reducer === "string") { - var result = Array.from(this.actions) - .find(function (val) { return val[1].type === reducer; }); - if (result) { - action = result[0]; - } - } - else { - action = reducer; - } - return new Promise(function (resolve, reject) { - _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); - if (_this.dispatchQueue.length === 1) { - _this.handleQueue(); - } - }); - }; - Store.prototype.handleQueue = function () { - return __awaiter(this, void 0, void 0, function () { - var queueItem, e_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; - queueItem = this.dispatchQueue[0]; - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; - case 2: - _a.sent(); - queueItem.resolve(); - return [3 /*break*/, 4]; - case 3: - e_1 = _a.sent(); - queueItem.reject(e_1); - return [3 /*break*/, 4]; - case 4: - this.dispatchQueue.shift(); - this.handleQueue(); - _a.label = 5; - case 5: return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.internalDispatch = function (reducer) { - var params = []; - for (var _i = 1; _i < arguments.length; _i++) { - params[_i - 1] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!this.actions.has(reducer)) { - throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-start"); - action = this.actions.get(reducer); - if (this.options.logDispatchedActions) { - this.logger[logging_1.getLogType(this.options, "dispatchedActions", logging_1.LogLevel.info)]("Dispatching: " + action.type); - } - return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), middleware_1.MiddlewarePlacement.Before, { - name: action.type, - params: params - })]; - case 1: - beforeMiddleswaresResult = _a.sent(); - if (beforeMiddleswaresResult === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; - case 2: - result = _a.sent(); - if (result === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - aurelia_pal_1.PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); - if (!result && typeof result !== "object") { - throw new Error("The reducer has to return a new state"); - } - return [4 /*yield*/, this.executeMiddlewares(result, middleware_1.MiddlewarePlacement.After, { - name: action.type, - params: params - })]; - case 3: - resultingState = _a.sent(); - if (resultingState === false) { - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - return [2 /*return*/]; - } - if (history_1.isStateHistory(resultingState) && - this.options.history && - this.options.history.limit) { - resultingState = history_1.applyLimits(resultingState, this.options.history.limit); - } - this._state.next(resultingState); - aurelia_pal_1.PLATFORM.performance.mark("dispatch-end"); - if (this.options.measurePerformance === PerformanceMeasurement.StartEnd) { - aurelia_pal_1.PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); - measures = aurelia_pal_1.PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); - } - else if (this.options.measurePerformance === PerformanceMeasurement.All) { - marks = aurelia_pal_1.PLATFORM.performance.getEntriesByType("mark"); - totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; - this.logger[logging_1.getLogType(this.options, "performanceLog", logging_1.LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); - } - aurelia_pal_1.PLATFORM.performance.clearMarks(); - aurelia_pal_1.PLATFORM.performance.clearMeasures(); - this.updateDevToolsState(action, resultingState); - return [2 /*return*/]; - } - }); - }); - }; - Store.prototype.executeMiddlewares = function (state, placement, action) { - var _this = this; - return Array.from(this.middlewares) - .filter(function (middleware) { return middleware[1].placement === placement; }) - .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { - var result, _a, _b, _c, e_2; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - _d.trys.push([0, 5, 7, 8]); - _b = (_a = curr)[0]; - return [4 /*yield*/, prev]; - case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; - case 2: - result = _d.sent(); - if (result === false) { - _arr = []; - return [2 /*return*/, false]; - } - _c = result; - if (_c) return [3 /*break*/, 4]; - return [4 /*yield*/, prev]; - case 3: - _c = (_d.sent()); - _d.label = 4; - case 4: return [2 /*return*/, _c]; - case 5: - e_2 = _d.sent(); - if (this.options.propagateError) { - _arr = []; - throw e_2; - } - return [4 /*yield*/, prev]; - case 6: return [2 /*return*/, _d.sent()]; - case 7: - aurelia_pal_1.PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); - return [7 /*endfinally*/]; - case 8: return [2 /*return*/]; - } - }); - }); }, state); - }; - Store.prototype.setupDevTools = function () { - var _this = this; - if (aurelia_pal_1.PLATFORM.global.devToolsExtension) { - this.logger[logging_1.getLogType(this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools are available"); - this.devToolsAvailable = true; - this.devTools = aurelia_pal_1.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); - this.devTools.init(this.initialState); - this.devTools.subscribe(function (message) { - _this.logger[logging_1.getLogType(_this.options, "devToolsStatus", logging_1.LogLevel.debug)]("DevTools sent change " + message.type); - if (message.type === "DISPATCH") { - _this._state.next(JSON.parse(message.state)); - } - }); - } - }; - Store.prototype.updateDevToolsState = function (action, state) { - if (this.devToolsAvailable) { - this.devTools.send(action, state); - } - }; - Store.prototype.registerHistoryMethods = function () { - this.registerAction("jump", history_1.jump); - }; - return Store; - }()); - exports.Store = Store; - function dispatchify(action) { - var store = aurelia_dependency_injection_1.Container.instance.get(Store); - return function () { - var params = []; - for (var _i = 0; _i < arguments.length; _i++) { - params[_i] = arguments[_i]; - } - return store.dispatch.apply(store, [action].concat(params)); - }; - } - exports.dispatchify = dispatchify; -}); -//# sourceMappingURL=store.js.map \ No newline at end of file diff --git a/dist/amd/store.js.map b/dist/amd/store.js.map deleted file mode 100644 index f0c9ee9..0000000 --- a/dist/amd/store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAaA,IAAY,sBAGX;IAHD,WAAY,sBAAsB;QAChC,+CAAqB,CAAA;QACrB,qCAAW,CAAA;IACb,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC;IAkBD;QAaE,eAAoB,YAAe,EAAE,OAA+B;YAAhD,iBAAY,GAAZ,YAAY,CAAG;YAV3B,WAAM,GAAG,2BAAS,CAAC,eAAe,CAAkB,CAAC;YACrD,sBAAiB,GAAY,KAAK,CAAC;YAEnC,YAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;YACrD,gBAAW,GAA2E,IAAI,GAAG,EAAE,CAAC;YAIhG,kBAAa,GAA2B,EAAE,CAAC;YAGjD,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;YAC7B,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC;YAClF,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAe,CAAI,YAAY,CAAC,CAAC;YACnD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,YAA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,IAAM,KAAK,GAAG,wCAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAE5C,OAAO;YAAU,gBAAY;iBAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;gBAAZ,2BAAY;;YAC3B,OAAO,KAAK,CAAC,QAAQ,OAAd,KAAK,GAAU,MAAM,SAAK,MAAM,EAAkB,CAAC;QAC5D,CAAC,CAAA;IACH,CAAC;IAND,kCAMC"} \ No newline at end of file diff --git a/dist/amd/test-helpers.d.ts b/dist/amd/test-helpers.d.ts deleted file mode 100644 index 3e8ef12..0000000 --- a/dist/amd/test-helpers.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Store } from "./store"; -export declare type StepFn = (res: T) => void; -export declare function executeSteps(store: Store, shouldLogResults: boolean, ...steps: StepFn[]): Promise<{}>; diff --git a/dist/amd/test-helpers.js b/dist/amd/test-helpers.js deleted file mode 100644 index 01d3d89..0000000 --- a/dist/amd/test-helpers.js +++ /dev/null @@ -1,84 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -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 }; - } -}; -define(["require", "exports", "rxjs/operators"], function (require, exports, operators_1) { - "use strict"; - Object.defineProperty(exports, "__esModule", { value: true }); - function executeSteps(store, shouldLogResults) { - var steps = []; - for (var _i = 2; _i < arguments.length; _i++) { - steps[_i - 2] = arguments[_i]; - } - return __awaiter(this, void 0, void 0, function () { - var logStep, tryStep, lastStep; - return __generator(this, function (_a) { - logStep = function (step, stepIdx) { return function (res) { - if (shouldLogResults) { - console.group("Step " + stepIdx); - console.log(res); - console.groupEnd(); - } - step(res); - }; }; - tryStep = function (step, reject) { - return function (res) { - try { - step(res); - } - catch (err) { - reject(err); - } - }; - }; - lastStep = function (step, resolve) { - return function (res) { - step(res); - resolve(); - }; - }; - return [2 /*return*/, new Promise(function (resolve, reject) { - var currentStep = 0; - steps.slice(0, -1).forEach(function (step) { - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1), operators_1.delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); - currentStep++; - }); - store.state.pipe(operators_1.skip(currentStep), operators_1.take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); - })]; - }); - }); - } - exports.executeSteps = executeSteps; -}); -//# sourceMappingURL=test-helpers.js.map \ No newline at end of file diff --git a/dist/amd/test-helpers.js.map b/dist/amd/test-helpers.js.map deleted file mode 100644 index c9f3bdf..0000000 --- a/dist/amd/test-helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"test-helpers.js","sourceRoot":"","sources":["../../src/test-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOA,SAAsB,YAAY,CAAI,KAAe,EAAE,gBAAyB;QAAE,eAAqB;aAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;YAArB,8BAAqB;;;;;gBAC/F,OAAO,GAAG,UAAC,IAAe,EAAE,OAAe,IAAK,OAAA,UAAC,GAAM;oBAC3D,IAAI,gBAAgB,EAAE;wBACpB,OAAO,CAAC,KAAK,CAAC,UAAQ,OAAS,CAAC,CAAA;wBAChC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACjB,OAAO,CAAC,QAAQ,EAAE,CAAC;qBACpB;oBACD,IAAI,CAAC,GAAG,CAAC,CAAC;gBACZ,CAAC,EAPqD,CAOrD,CAAC;gBAGI,OAAO,GAAG,UAAC,IAAe,EAAE,MAA8B;oBAC9D,OAAA,UAAC,GAAM;wBACL,IAAI;4BACF,IAAI,CAAC,GAAG,CAAC,CAAC;yBACX;wBAAC,OAAO,GAAG,EAAE;4BACZ,MAAM,CAAC,GAAG,CAAC,CAAC;yBACb;oBACH,CAAC;gBAND,CAMC,CAAC;gBAEE,QAAQ,GAAG,UAAC,IAAe,EAAE,OAAmB;oBACpD,OAAA,UAAC,GAAM;wBACL,IAAI,CAAC,GAAG,CAAC,CAAC;wBACV,OAAO,EAAE,CAAC;oBACZ,CAAC;gBAHD,CAGC,CAAC;gBAEJ,sBAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;wBACjC,IAAI,WAAW,GAAG,CAAC,CAAC;wBAEpB,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAC,IAAI;4BAC9B,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,EACP,iBAAK,CAAC,CAAC,CAAC,CACT,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;4BACzD,WAAW,EAAE,CAAC;wBAChB,CAAC,CAAC,CAAC;wBAEH,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,gBAAI,CAAC,WAAW,CAAC,EACjB,gBAAI,CAAC,CAAC,CAAC,CACR,CAAC,SAAS,CACT,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;oBACvF,CAAC,CAAC,EAAC;;;KACJ;IA5CD,oCA4CC"} \ No newline at end of file diff --git a/dist/commonjs/aurelia-store.d.ts b/dist/commonjs/aurelia-store.d.ts deleted file mode 100644 index 406d78b..0000000 --- a/dist/commonjs/aurelia-store.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FrameworkConfiguration } from "aurelia-framework"; -import { StoreOptions } from "./store"; -export interface StorePluginOptions extends StoreOptions { - initialState: T; -} -export declare function configure(aurelia: FrameworkConfiguration, options: Partial>): void; -export * from "./store"; -export * from "./test-helpers"; -export * from "./history"; -export * from "./middleware"; -export * from "./logging"; -export * from "./decorator"; -export * from "./devtools"; diff --git a/dist/commonjs/aurelia-store.js b/dist/commonjs/aurelia-store.js deleted file mode 100644 index a92848b..0000000 --- a/dist/commonjs/aurelia-store.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -function __export(m) { - for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; -} -Object.defineProperty(exports, "__esModule", { value: true }); -var store_1 = require("./store"); -var history_1 = require("./history"); -function configure(aurelia, options) { - if (!options || !options.initialState) { - throw new Error("initialState must be provided via options"); - } - var initState = options.initialState; - if (options && options.history && options.history.undoable && !history_1.isStateHistory(options.initialState)) { - initState = { past: [], present: options.initialState, future: [] }; - } - delete options.initialState; - aurelia.container - .registerInstance(store_1.Store, new store_1.Store(initState, options)); -} -exports.configure = configure; -__export(require("./store")); -__export(require("./test-helpers")); -__export(require("./history")); -__export(require("./middleware")); -__export(require("./logging")); -__export(require("./decorator")); -//# sourceMappingURL=aurelia-store.js.map \ No newline at end of file diff --git a/dist/commonjs/aurelia-store.js.map b/dist/commonjs/aurelia-store.js.map deleted file mode 100644 index 6e6d0a5..0000000 --- a/dist/commonjs/aurelia-store.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"aurelia-store.js","sourceRoot":"","sources":["../../src/aurelia-store.ts"],"names":[],"mappings":";;;;;AACA,iCAA8C;AAC9C,qCAA2C;AAM3C,SAAgB,SAAS,CACvB,OAA+B,EAC/B,OAAuC;IAEvC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;QACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;KAC9D;IAED,IAAI,SAAS,GAAQ,OAAO,CAAC,YAAY,CAAC;IAC1C,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,wBAAc,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACnG,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;KACrE;IAED,OAAO,OAAO,CAAC,YAAY,CAAC;IAE5B,OAAO,CAAC,SAAS;SACd,gBAAgB,CAAC,aAAK,EAAE,IAAI,aAAK,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5D,CAAC;AAjBD,8BAiBC;AAED,6BAAwB;AACxB,oCAA+B;AAC/B,+BAA0B;AAC1B,kCAA6B;AAC7B,+BAA0B;AAC1B,iCAA4B"} \ No newline at end of file diff --git a/dist/commonjs/decorator.d.ts b/dist/commonjs/decorator.d.ts deleted file mode 100644 index e6bb57b..0000000 --- a/dist/commonjs/decorator.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Observable } from "rxjs"; -import { Store } from "./store"; -export interface ConnectToSettings { - onChanged?: string; - selector: ((store: Store) => Observable) | MultipleSelector; - setup?: string; - target?: string; - teardown?: string; -} -export interface MultipleSelector { - [key: string]: ((store: Store) => Observable); -} -export declare function connectTo(settings?: ((store: Store) => Observable) | ConnectToSettings): (target: any) => void; diff --git a/dist/commonjs/decorator.js b/dist/commonjs/decorator.js deleted file mode 100644 index 9fa1156..0000000 --- a/dist/commonjs/decorator.js +++ /dev/null @@ -1,103 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(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); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var aurelia_dependency_injection_1 = require("aurelia-dependency-injection"); -var rxjs_1 = require("rxjs"); -var store_1 = require("./store"); -var defaultSelector = function (store) { return store.state; }; -function connectTo(settings) { - if (!Object.entries) { - throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); - } - var store = aurelia_dependency_injection_1.Container.instance.get(store_1.Store); - var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); - function getSource(selector) { - var source = selector(store); - if (source instanceof rxjs_1.Observable) { - return source; - } - return store.state; - } - function createSelectors() { - var _a; - var isSelectorObj = typeof _settings.selector === "object"; - var fallbackSelector = (_a = {}, - _a[_settings.target || "state"] = _settings.selector || defaultSelector, - _a); - return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { - var target = _a[0], selector = _a[1]; - var _b; - return ({ - targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], - selector: selector, - // numbers are the starting index to slice all the change handling args, - // which are prop name, new state and old state - changeHandlers: (_b = {}, - _b[_settings.onChanged || ""] = 1, - _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, - _b["propertyChanged"] = 0, - _b) - }); - }); - } - return function (target) { - var originalSetup = typeof settings === "object" && settings.setup - ? target.prototype[settings.setup] - : target.prototype.bind; - var originalTeardown = typeof settings === "object" && settings.teardown - ? target.prototype[settings.teardown] - : target.prototype.unbind; - target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { - var _this = this; - if (typeof settings == "object" && - typeof settings.onChanged === "string" && - !(settings.onChanged in this)) { - throw new Error("Provided onChanged handler does not exist on target VM"); - } - this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { - var lastTargetIdx = s.targets.length - 1; - var oldState = s.targets.reduce(function (accu, curr) { - if (accu === void 0) { accu = {}; } - return accu[curr]; - }, _this); - Object.entries(s.changeHandlers).forEach(function (_a) { - var handlerName = _a[0], args = _a[1]; - if (handlerName in _this) { - _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); - } - }); - s.targets.reduce(function (accu, curr, idx) { - accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; - return accu[curr]; - }, _this); - }); }); - if (originalSetup) { - return originalSetup.apply(this, arguments); - } - }; - target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { - if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { - this._stateSubscriptions.forEach(function (sub) { - if (sub instanceof rxjs_1.Subscription && sub.closed === false) { - sub.unsubscribe(); - } - }); - } - if (originalTeardown) { - return originalTeardown.apply(this, arguments); - } - }; - }; -} -exports.connectTo = connectTo; -//# sourceMappingURL=decorator.js.map \ No newline at end of file diff --git a/dist/commonjs/decorator.js.map b/dist/commonjs/decorator.js.map deleted file mode 100644 index 812a617..0000000 --- a/dist/commonjs/decorator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../src/decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,6EAAyD;AACzD,6BAAgD;AAEhD,iCAAgC;AAchC,IAAM,eAAe,GAAG,UAAI,KAAe,IAAK,OAAA,KAAK,CAAC,KAAK,EAAX,CAAW,CAAC;AAE5D,SAAgB,SAAS,CAAa,QAAyE;IAC7G,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,+LAA+L,CAAC,CAAA;KACjN;IAED,IAAM,KAAK,GAAG,wCAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAK,CAAa,CAAC;IACxD,IAAM,SAAS,cACb,QAAQ,EAAE,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe,IAClE,QAAQ,CACZ,CAAC;IAEF,SAAS,SAAS,CAAC,QAAgD;QACjE,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE7B,IAAI,MAAM,YAAY,iBAAU,EAAE;YAChC,OAAO,MAAM,CAAC;SACf;QAEH,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,SAAS,eAAe;;QACtB,IAAM,aAAa,GAAG,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAC7D,IAAM,gBAAgB;YACpB,GAAC,SAAS,CAAC,MAAM,IAAI,OAAO,IAAG,SAAS,CAAC,QAAQ,IAAI,eAAe;eACrE,CAAC;QAEF,OAAO,MAAM,CAAC,OA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AC9D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC,EAAE,KAAI,CAAC,CAAC;YACX,CAAC,CAAC,EAdoD,CAcpD,CAAC,CAAC;YAEJ,IAAI,aAAa,EAAE;gBACjB,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAC7C;QACH,CAAC,CAAA;QAED,MAAM,CAAC,SAAS,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG;YACnG,IAAI,IAAI,CAAC,mBAAmB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBACvE,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,UAAC,GAAiB;oBACjD,IAAI,GAAG,YAAY,mBAAY,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE;wBACvD,GAAG,CAAC,WAAW,EAAE,CAAC;qBACnB;gBACH,CAAC,CAAC,CAAC;aACJ;YAED,IAAI,gBAAgB,EAAE;gBACpB,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAChD;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AA5FD,8BA4FC"} \ No newline at end of file diff --git a/dist/commonjs/devtools.d.ts b/dist/commonjs/devtools.d.ts deleted file mode 100644 index d24aa8c..0000000 --- a/dist/commonjs/devtools.d.ts +++ /dev/null @@ -1,163 +0,0 @@ -export interface Action { - type: T; -} -export interface ActionCreator { - (...args: any[]): T; -} -export interface DevToolsOptions { - /** - * the instance name to be showed on the monitor page. Default value is `document.title`. - * If not specified and there's no document title, it will consist of `tabId` and `instanceId`. - */ - name?: string; - /** - * action creators functions to be available in the Dispatcher. - */ - actionCreators?: ActionCreator[] | { - [key: string]: ActionCreator; - }; - /** - * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. - * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. - * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). - * - * @default 500 ms. - */ - latency?: number; - /** - * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. - * - * @default 50 - */ - maxAge?: number; - /** - * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). - * - `false` - will handle also circular references. - * - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. - * - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. - * For each of them you can indicate if to include (by setting as `true`). - * For `function` key you can also specify a custom function which handles serialization. - * See [`jsan`](https://github.com/kolodny/jsan) for more details. - */ - serialize?: boolean | { - date?: boolean; - regex?: boolean; - undefined?: boolean; - error?: boolean; - symbol?: boolean; - map?: boolean; - set?: boolean; - function?: boolean | Function; - }; - /** - * function which takes `action` object and id number as arguments, and should return `action` object back. - */ - actionSanitizer?: (action: A, id: number) => A; - /** - * function which takes `state` object and index as arguments, and should return `state` object back. - */ - stateSanitizer?: (state: S, index: number) => S; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsBlacklist?: string[]; - /** - * *array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). - * If `actionsWhitelist` specified, `actionsBlacklist` is ignored. - */ - actionsWhitelist?: string[]; - /** - * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. - * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. - */ - predicate?: (state: S, action: A) => boolean; - /** - * if specified as `false`, it will not record the changes till clicking on `Start recording` button. - * Available only for Redux enhancer, for others use `autoPause`. - * - * @default true - */ - shouldRecordChanges?: boolean; - /** - * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. - * If not specified, will commit when paused. Available only for Redux enhancer. - * - * @default "@@PAUSED"" - */ - pauseActionType?: string; - /** - * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. - * Not available for Redux enhancer (as it already does it but storing the data to be sent). - * - * @default false - */ - autoPause?: boolean; - /** - * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. - * Available only for Redux enhancer. - * - * @default false - */ - shouldStartLocked?: boolean; - /** - * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. - * - * @default true - */ - shouldHotReload?: boolean; - /** - * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. - * - * @default false - */ - shouldCatchErrors?: boolean; - /** - * If you want to restrict the extension, specify the features you allow. - * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. - * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. - * Otherwise, you'll get/set the data right from the monitor part. - */ - features?: { - /** - * start/pause recording of dispatched actions - */ - pause?: boolean; - /** - * lock/unlock dispatching actions and side effects - */ - lock?: boolean; - /** - * persist states on page reloading - */ - persist?: boolean; - /** - * export history of actions in a file - */ - export?: boolean | "custom"; - /** - * import history of actions from a file - */ - import?: boolean | "custom"; - /** - * jump back and forth (time travelling) - */ - jump?: boolean; - /** - * skip (cancel) actions - */ - skip?: boolean; - /** - * drag and drop actions in the history list - */ - reorder?: boolean; - /** - * dispatch custom actions or action creators - */ - dispatch?: boolean; - /** - * generate tests for the selected actions - */ - test?: boolean; - }; -} diff --git a/dist/commonjs/devtools.js b/dist/commonjs/devtools.js deleted file mode 100644 index 15a1f68..0000000 --- a/dist/commonjs/devtools.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=devtools.js.map \ No newline at end of file diff --git a/dist/commonjs/devtools.js.map b/dist/commonjs/devtools.js.map deleted file mode 100644 index 504bcee..0000000 --- a/dist/commonjs/devtools.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../../src/devtools.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/commonjs/history.d.ts b/dist/commonjs/history.d.ts deleted file mode 100644 index bf81f06..0000000 --- a/dist/commonjs/history.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface StateHistory { - past: T[]; - present: T; - future: T[]; -} -export interface HistoryOptions { - undoable: boolean; - limit?: number; -} -export declare function jump(state: T, n: number): T | StateHistory; -export declare function nextStateHistory(presentStateHistory: StateHistory, nextPresent: T): StateHistory; -export declare function applyLimits(state: T, limit: number): T; -export declare function isStateHistory(history: any): history is StateHistory; diff --git a/dist/commonjs/history.js b/dist/commonjs/history.js deleted file mode 100644 index 2093573..0000000 --- a/dist/commonjs/history.js +++ /dev/null @@ -1,62 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function jump(state, n) { - if (!isStateHistory(state)) { - return state; - } - if (n > 0) - return jumpToFuture(state, n - 1); - if (n < 0) - return jumpToPast(state, state.past.length + n); - return state; -} -exports.jump = jump; -function jumpToFuture(state, index) { - if (index < 0 || index >= state.future.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.concat([present], future.slice(0, index)); - var newPresent = future[index]; - var newFuture = future.slice(index + 1); - return { past: newPast, present: newPresent, future: newFuture }; -} -function jumpToPast(state, index) { - if (index < 0 || index >= state.past.length) { - return state; - } - var past = state.past, future = state.future, present = state.present; - var newPast = past.slice(0, index); - var newFuture = past.slice(index + 1).concat([present], future); - var newPresent = past[index]; - return { past: newPast, present: newPresent, future: newFuture }; -} -function nextStateHistory(presentStateHistory, nextPresent) { - return Object.assign({}, presentStateHistory, { - past: presentStateHistory.past.concat([presentStateHistory.present]), - present: nextPresent, - future: [] - }); -} -exports.nextStateHistory = nextStateHistory; -function applyLimits(state, limit) { - if (isStateHistory(state)) { - if (state.past.length > limit) { - state.past = state.past.slice(state.past.length - limit); - } - if (state.future.length > limit) { - state.future = state.future.slice(0, limit); - } - } - return state; -} -exports.applyLimits = applyLimits; -function isStateHistory(history) { - return typeof history.present !== "undefined" && - typeof history.future !== "undefined" && - typeof history.past !== "undefined" && - Array.isArray(history.future) && - Array.isArray(history.past); -} -exports.isStateHistory = isStateHistory; -//# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/commonjs/history.js.map b/dist/commonjs/history.js.map deleted file mode 100644 index 10bb49d..0000000 --- a/dist/commonjs/history.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/history.ts"],"names":[],"mappings":";;AAWA,SAAgB,IAAI,CAAI,KAAQ,EAAE,CAAS;IACzC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAC;AACf,CAAC;AATD,oBASC;AAED,SAAS,YAAY,CAAI,KAAsB,EAAE,KAAa;IAC5D,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE;QAC7C,OAAO,KAAK,CAAC;KACd;IAEO,IAAA,iBAAI,EAAE,qBAAM,EAAE,uBAAO,CAAW;IAExC,IAAM,OAAO,GAAO,IAAI,SAAE,OAAO,GAAK,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9D,IAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAA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AED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE;YAC/B,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC7C;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,kCAYC;AAED,SAAgB,cAAc,CAAC,OAAY;IACzC,OAAO,OAAO,OAAO,CAAC,OAAO,KAAK,WAAW;QAC3C,OAAO,OAAO,CAAC,MAAM,KAAK,WAAW;QACrC,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW;QACnC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC;AAND,wCAMC"} \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js new file mode 100644 index 0000000..884f5da --- /dev/null +++ b/dist/commonjs/index.js @@ -0,0 +1,623 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var aureliaPal = require('aurelia-pal'); +var aureliaLogging = require('aurelia-logging'); +var rxjs = require('rxjs'); +var aureliaDependencyInjection = require('aurelia-dependency-injection'); +var operators = require('rxjs/operators'); + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +/* 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 (b.hasOwnProperty(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 __awaiter(thisArg, _arguments, P, generator) { + 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) : new P(function (resolve) { resolve(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 }; + } +} + +function jump(state, n) { + if (!isStateHistory(state)) { + return state; + } + if (n > 0) + return jumpToFuture(state, n - 1); + if (n < 0) + return jumpToPast(state, state.past.length + n); + return state; +} +function jumpToFuture(state, index) { + if (index < 0 || index >= state.future.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.concat([present], future.slice(0, index)); + var newPresent = future[index]; + var newFuture = future.slice(index + 1); + return { past: newPast, present: newPresent, future: newFuture }; +} +function jumpToPast(state, index) { + if (index < 0 || index >= state.past.length) { + return state; + } + var past = state.past, future = state.future, present = state.present; + var newPast = past.slice(0, index); + var newFuture = past.slice(index + 1).concat([present], future); + var newPresent = past[index]; + return { past: newPast, present: newPresent, future: newFuture }; +} +function nextStateHistory(presentStateHistory, nextPresent) { + return Object.assign({}, presentStateHistory, { + past: presentStateHistory.past.concat([presentStateHistory.present]), + present: nextPresent, + future: [] + }); +} +function applyLimits(state, limit) { + if (isStateHistory(state)) { + if (state.past.length > limit) { + state.past = state.past.slice(state.past.length - limit); + } + if (state.future.length > limit) { + state.future = state.future.slice(0, limit); + } + } + return state; +} +function isStateHistory(history) { + return typeof history.present !== "undefined" && + typeof history.future !== "undefined" && + typeof history.past !== "undefined" && + Array.isArray(history.future) && + Array.isArray(history.past); +} + +(function (MiddlewarePlacement) { + MiddlewarePlacement["Before"] = "before"; + MiddlewarePlacement["After"] = "after"; +})(exports.MiddlewarePlacement || (exports.MiddlewarePlacement = {})); +function logMiddleware(state, _, settings) { + if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { + console[settings.logType]("New state: ", state); + } + else { + console.log("New state: ", state); + } +} +function localStorageMiddleware(state, _, settings) { + if (aureliaPal.PLATFORM.global.localStorage) { + var key = settings && settings.key && typeof settings.key === "string" + ? settings.key + : "aurelia-store-state"; + aureliaPal.PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); + } +} +function rehydrateFromLocalStorage(state, key) { + if (!aureliaPal.PLATFORM.global.localStorage) { + return state; + } + var storedState = aureliaPal.PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); + if (!storedState) { + return state; + } + try { + return JSON.parse(storedState); + } + catch (e) { } + return state; +} + +(function (LogLevel) { + LogLevel["trace"] = "trace"; + LogLevel["debug"] = "debug"; + LogLevel["info"] = "info"; + LogLevel["log"] = "log"; + LogLevel["warn"] = "warn"; + LogLevel["error"] = "error"; +})(exports.LogLevel || (exports.LogLevel = {})); +var LoggerIndexed = /** @class */ (function (_super) { + __extends(LoggerIndexed, _super); + function LoggerIndexed() { + return _super !== null && _super.apply(this, arguments) || this; + } + return LoggerIndexed; +}(aureliaLogging.Logger)); +function getLogType(options, definition, defaultLevel) { + if (definition && + options.logDefinitions && + options.logDefinitions.hasOwnProperty(definition) && + options.logDefinitions[definition] && + Object.values(exports.LogLevel).includes(options.logDefinitions[definition])) { + return options.logDefinitions[definition]; + } + return defaultLevel; +} + +(function (PerformanceMeasurement) { + PerformanceMeasurement["StartEnd"] = "startEnd"; + PerformanceMeasurement["All"] = "all"; +})(exports.PerformanceMeasurement || (exports.PerformanceMeasurement = {})); +var Store = /** @class */ (function () { + function Store(initialState, options) { + this.initialState = initialState; + this.logger = aureliaLogging.getLogger("aurelia-store"); + this.devToolsAvailable = false; + this.actions = new Map(); + this.middlewares = new Map(); + this.dispatchQueue = []; + this.options = options || {}; + var isUndoable = this.options.history && this.options.history.undoable === true; + this._state = new rxjs.BehaviorSubject(initialState); + this.state = this._state.asObservable(); + if (!this.options.devToolsOptions || this.options.devToolsOptions.disable !== true) { + this.setupDevTools(); + } + if (isUndoable) { + this.registerHistoryMethods(); + } + } + Store.prototype.registerMiddleware = function (reducer, placement, settings) { + this.middlewares.set(reducer, { placement: placement, settings: settings }); + }; + Store.prototype.unregisterMiddleware = function (reducer) { + if (this.middlewares.has(reducer)) { + this.middlewares.delete(reducer); + } + }; + Store.prototype.isMiddlewareRegistered = function (middleware) { + return this.middlewares.has(middleware); + }; + Store.prototype.registerAction = function (name, reducer) { + if (reducer.length === 0) { + throw new Error("The reducer is expected to have one or more parameters, where the first will be the present state"); + } + this.actions.set(reducer, { type: name }); + }; + Store.prototype.unregisterAction = function (reducer) { + if (this.actions.has(reducer)) { + this.actions.delete(reducer); + } + }; + Store.prototype.isActionRegistered = function (reducer) { + if (typeof reducer === "string") { + return Array.from(this.actions).find(function (action) { return action[1].type === reducer; }) !== undefined; + } + return this.actions.has(reducer); + }; + Store.prototype.resetToState = function (state) { + this._state.next(state); + }; + Store.prototype.dispatch = function (reducer) { + var _this = this; + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + var action; + if (typeof reducer === "string") { + var result = Array.from(this.actions) + .find(function (val) { return val[1].type === reducer; }); + if (result) { + action = result[0]; + } + } + else { + action = reducer; + } + return new Promise(function (resolve, reject) { + _this.dispatchQueue.push({ reducer: action, params: params, resolve: resolve, reject: reject }); + if (_this.dispatchQueue.length === 1) { + _this.handleQueue(); + } + }); + }; + Store.prototype.handleQueue = function () { + return __awaiter(this, void 0, void 0, function () { + var queueItem, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.dispatchQueue.length > 0)) return [3 /*break*/, 5]; + queueItem = this.dispatchQueue[0]; + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, this.internalDispatch.apply(this, [queueItem.reducer].concat(queueItem.params))]; + case 2: + _a.sent(); + queueItem.resolve(); + return [3 /*break*/, 4]; + case 3: + e_1 = _a.sent(); + queueItem.reject(e_1); + return [3 /*break*/, 4]; + case 4: + this.dispatchQueue.shift(); + this.handleQueue(); + _a.label = 5; + case 5: return [2 /*return*/]; + } + }); + }); + }; + Store.prototype.internalDispatch = function (reducer) { + var params = []; + for (var _i = 1; _i < arguments.length; _i++) { + params[_i - 1] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var action, beforeMiddleswaresResult, result, resultingState, measures, marks, totalDuration; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this.actions.has(reducer)) { + throw new Error("Tried to dispatch an unregistered action" + (reducer ? " " + reducer.name : "")); + } + aureliaPal.PLATFORM.performance.mark("dispatch-start"); + action = __assign({}, this.actions.get(reducer), { params: params }); + if (this.options.logDispatchedActions) { + this.logger[getLogType(this.options, "dispatchedActions", exports.LogLevel.info)]("Dispatching: " + action.type); + } + return [4 /*yield*/, this.executeMiddlewares(this._state.getValue(), exports.MiddlewarePlacement.Before, { + name: action.type, + params: params + })]; + case 1: + beforeMiddleswaresResult = _a.sent(); + if (beforeMiddleswaresResult === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + return [4 /*yield*/, reducer.apply(void 0, [beforeMiddleswaresResult].concat(params))]; + case 2: + result = _a.sent(); + if (result === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + aureliaPal.PLATFORM.performance.mark("dispatch-after-reducer-" + action.type); + if (!result && typeof result !== "object") { + throw new Error("The reducer has to return a new state"); + } + return [4 /*yield*/, this.executeMiddlewares(result, exports.MiddlewarePlacement.After, { + name: action.type, + params: params + })]; + case 3: + resultingState = _a.sent(); + if (resultingState === false) { + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + return [2 /*return*/]; + } + if (isStateHistory(resultingState) && + this.options.history && + this.options.history.limit) { + resultingState = applyLimits(resultingState, this.options.history.limit); + } + this._state.next(resultingState); + aureliaPal.PLATFORM.performance.mark("dispatch-end"); + if (this.options.measurePerformance === exports.PerformanceMeasurement.StartEnd) { + aureliaPal.PLATFORM.performance.measure("startEndDispatchDuration", "dispatch-start", "dispatch-end"); + measures = aureliaPal.PLATFORM.performance.getEntriesByName("startEndDispatchDuration"); + this.logger[getLogType(this.options, "performanceLog", exports.LogLevel.info)]("Total duration " + measures[0].duration + " of dispatched action " + action.type + ":", measures); + } + else if (this.options.measurePerformance === exports.PerformanceMeasurement.All) { + marks = aureliaPal.PLATFORM.performance.getEntriesByType("mark"); + totalDuration = marks[marks.length - 1].startTime - marks[0].startTime; + this.logger[getLogType(this.options, "performanceLog", exports.LogLevel.info)]("Total duration " + totalDuration + " of dispatched action " + action.type + ":", marks); + } + aureliaPal.PLATFORM.performance.clearMarks(); + aureliaPal.PLATFORM.performance.clearMeasures(); + this.updateDevToolsState(action, resultingState); + return [2 /*return*/]; + } + }); + }); + }; + Store.prototype.executeMiddlewares = function (state, placement, action) { + var _this = this; + return Array.from(this.middlewares) + .filter(function (middleware) { return middleware[1].placement === placement; }) + .reduce(function (prev, curr, _, _arr) { return __awaiter(_this, void 0, void 0, function () { + var result, _a, _b, _c, e_2; + return __generator(this, function (_d) { + switch (_d.label) { + case 0: + _d.trys.push([0, 5, 7, 8]); + _b = (_a = curr)[0]; + return [4 /*yield*/, prev]; + case 1: return [4 /*yield*/, _b.apply(_a, [_d.sent(), this._state.getValue(), curr[1].settings, action])]; + case 2: + result = _d.sent(); + if (result === false) { + _arr = []; + return [2 /*return*/, false]; + } + _c = result; + if (_c) return [3 /*break*/, 4]; + return [4 /*yield*/, prev]; + case 3: + _c = (_d.sent()); + _d.label = 4; + case 4: return [2 /*return*/, _c]; + case 5: + e_2 = _d.sent(); + if (this.options.propagateError) { + _arr = []; + throw e_2; + } + return [4 /*yield*/, prev]; + case 6: return [2 /*return*/, _d.sent()]; + case 7: + aureliaPal.PLATFORM.performance.mark("dispatch-" + placement + "-" + curr[0].name); + return [7 /*endfinally*/]; + case 8: return [2 /*return*/]; + } + }); + }); }, state); + }; + Store.prototype.setupDevTools = function () { + var _this = this; + if (aureliaPal.PLATFORM.global.devToolsExtension) { + this.logger[getLogType(this.options, "devToolsStatus", exports.LogLevel.debug)]("DevTools are available"); + this.devToolsAvailable = true; + this.devTools = aureliaPal.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions); + this.devTools.init(this.initialState); + this.devTools.subscribe(function (message) { + _this.logger[getLogType(_this.options, "devToolsStatus", exports.LogLevel.debug)]("DevTools sent change " + message.type); + if (message.type === "DISPATCH") { + _this._state.next(JSON.parse(message.state)); + } + }); + } + }; + Store.prototype.updateDevToolsState = function (action, state) { + if (this.devToolsAvailable) { + this.devTools.send(action, state); + } + }; + Store.prototype.registerHistoryMethods = function () { + this.registerAction("jump", jump); + }; + return Store; +}()); +function dispatchify(action) { + var store = aureliaDependencyInjection.Container.instance.get(Store); + return function () { + var params = []; + for (var _i = 0; _i < arguments.length; _i++) { + params[_i] = arguments[_i]; + } + return store.dispatch.apply(store, [action].concat(params)); + }; +} + +function executeSteps(store, shouldLogResults) { + var steps = []; + for (var _i = 2; _i < arguments.length; _i++) { + steps[_i - 2] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var logStep, tryStep, lastStep; + return __generator(this, function (_a) { + logStep = function (step, stepIdx) { return function (res) { + if (shouldLogResults) { + console.group("Step " + stepIdx); + console.log(res); + console.groupEnd(); + } + step(res); + }; }; + tryStep = function (step, reject) { + return function (res) { + try { + step(res); + } + catch (err) { + reject(err); + } + }; + }; + lastStep = function (step, resolve) { + return function (res) { + step(res); + resolve(); + }; + }; + return [2 /*return*/, new Promise(function (resolve, reject) { + var currentStep = 0; + steps.slice(0, -1).forEach(function (step) { + store.state.pipe(operators.skip(currentStep), operators.take(1), operators.delay(0)).subscribe(tryStep(logStep(step, currentStep), reject)); + currentStep++; + }); + store.state.pipe(operators.skip(currentStep), operators.take(1)).subscribe(lastStep(tryStep(logStep(steps[steps.length - 1], currentStep), reject), resolve)); + })]; + }); + }); +} + +var defaultSelector = function (store) { return store.state; }; +function connectTo(settings) { + if (!Object.entries) { + throw new Error("You need a polyfill for Object.entries for browsers like Internet Explorer. Example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill"); + } + var store = aureliaDependencyInjection.Container.instance.get(Store); + var _settings = __assign({ selector: typeof settings === "function" ? settings : defaultSelector }, settings); + function getSource(selector) { + var source = selector(store); + if (source instanceof rxjs.Observable) { + return source; + } + return store.state; + } + function createSelectors() { + var _a; + var isSelectorObj = typeof _settings.selector === "object"; + var fallbackSelector = (_a = {}, + _a[_settings.target || "state"] = _settings.selector || defaultSelector, + _a); + return Object.entries(__assign({}, (isSelectorObj ? _settings.selector : fallbackSelector))).map(function (_a) { + var target = _a[0], selector = _a[1]; + var _b; + return ({ + targets: _settings.target && isSelectorObj ? [_settings.target, target] : [target], + selector: selector, + // numbers are the starting index to slice all the change handling args, + // which are prop name, new state and old state + changeHandlers: (_b = {}, + _b[_settings.onChanged || ""] = 1, + _b[(_settings.target || target) + "Changed"] = _settings.target ? 0 : 1, + _b["propertyChanged"] = 0, + _b) + }); + }); + } + return function (target) { + var originalSetup = typeof settings === "object" && settings.setup + ? target.prototype[settings.setup] + : target.prototype.bind; + var originalTeardown = typeof settings === "object" && settings.teardown + ? target.prototype[settings.teardown] + : target.prototype.unbind; + target.prototype[typeof settings === "object" && settings.setup ? settings.setup : "bind"] = function () { + var _this = this; + if (typeof settings == "object" && + typeof settings.onChanged === "string" && + !(settings.onChanged in this)) { + throw new Error("Provided onChanged handler does not exist on target VM"); + } + this._stateSubscriptions = createSelectors().map(function (s) { return getSource(s.selector).subscribe(function (state) { + var lastTargetIdx = s.targets.length - 1; + var oldState = s.targets.reduce(function (accu, curr) { + if (accu === void 0) { accu = {}; } + return accu[curr]; + }, _this); + Object.entries(s.changeHandlers).forEach(function (_a) { + var handlerName = _a[0], args = _a[1]; + if (handlerName in _this) { + _this[handlerName].apply(_this, [s.targets[lastTargetIdx], state, oldState].slice(args, 3)); + } + }); + s.targets.reduce(function (accu, curr, idx) { + accu[curr] = idx === lastTargetIdx ? state : accu[curr] || {}; + return accu[curr]; + }, _this); + }); }); + if (originalSetup) { + return originalSetup.apply(this, arguments); + } + }; + target.prototype[typeof settings === "object" && settings.teardown ? settings.teardown : "unbind"] = function () { + if (this._stateSubscriptions && Array.isArray(this._stateSubscriptions)) { + this._stateSubscriptions.forEach(function (sub) { + if (sub instanceof rxjs.Subscription && sub.closed === false) { + sub.unsubscribe(); + } + }); + } + if (originalTeardown) { + return originalTeardown.apply(this, arguments); + } + }; + }; +} + +function configure(aurelia, options) { + if (!options || !options.initialState) { + throw new Error("initialState must be provided via options"); + } + var initState = options.initialState; + if (options && options.history && options.history.undoable && !isStateHistory(options.initialState)) { + initState = { past: [], present: options.initialState, future: [] }; + } + delete options.initialState; + aurelia.container + .registerInstance(Store, new Store(initState, options)); +} + +exports.configure = configure; +exports.Store = Store; +exports.dispatchify = dispatchify; +exports.executeSteps = executeSteps; +exports.jump = jump; +exports.nextStateHistory = nextStateHistory; +exports.applyLimits = applyLimits; +exports.isStateHistory = isStateHistory; +exports.logMiddleware = logMiddleware; +exports.localStorageMiddleware = localStorageMiddleware; +exports.rehydrateFromLocalStorage = rehydrateFromLocalStorage; +exports.LoggerIndexed = LoggerIndexed; +exports.getLogType = getLogType; +exports.connectTo = connectTo; diff --git a/dist/commonjs/logging.d.ts b/dist/commonjs/logging.d.ts deleted file mode 100644 index aa5bdf2..0000000 --- a/dist/commonjs/logging.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { StoreOptions } from "./store"; -import { Logger } from "aurelia-logging"; -export declare enum LogLevel { - trace = "trace", - debug = "debug", - info = "info", - log = "log", - warn = "warn", - error = "error" -} -export declare class LoggerIndexed extends Logger { - [key: string]: any; -} -export interface LogDefinitions { - performanceLog?: LogLevel; - dispatchedActions?: LogLevel; - devToolsStatus?: LogLevel; -} -export declare function getLogType(options: Partial, definition: keyof LogDefinitions, defaultLevel: LogLevel): LogLevel; diff --git a/dist/commonjs/logging.js b/dist/commonjs/logging.js deleted file mode 100644 index bcd94e4..0000000 --- a/dist/commonjs/logging.js +++ /dev/null @@ -1,45 +0,0 @@ -"use strict"; -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 (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - } - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var aurelia_logging_1 = require("aurelia-logging"); -var LogLevel; -(function (LogLevel) { - LogLevel["trace"] = "trace"; - LogLevel["debug"] = "debug"; - LogLevel["info"] = "info"; - LogLevel["log"] = "log"; - LogLevel["warn"] = "warn"; - LogLevel["error"] = "error"; -})(LogLevel = exports.LogLevel || (exports.LogLevel = {})); -var LoggerIndexed = /** @class */ (function (_super) { - __extends(LoggerIndexed, _super); - function LoggerIndexed() { - return _super !== null && _super.apply(this, arguments) || this; - } - return LoggerIndexed; -}(aurelia_logging_1.Logger)); -exports.LoggerIndexed = LoggerIndexed; -function getLogType(options, definition, defaultLevel) { - if (definition && - options.logDefinitions && - options.logDefinitions.hasOwnProperty(definition) && - options.logDefinitions[definition] && - Object.values(LogLevel).includes(options.logDefinitions[definition])) { - return options.logDefinitions[definition]; - } - return defaultLevel; -} -exports.getLogType = getLogType; -//# sourceMappingURL=logging.js.map \ No newline at end of file diff --git a/dist/commonjs/logging.js.map b/dist/commonjs/logging.js.map deleted file mode 100644 index bcea5f7..0000000 --- a/dist/commonjs/logging.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mDAAyC;AAEzC,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,uBAAW,CAAA;IACX,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAOnB;AAED;IAAmC,iCAAM;IAAzC;;IAEA,CAAC;IAAD,oBAAC;AAAD,CAAC,AAFD,CAAmC,wBAAM,GAExC;AAFY,sCAAa;AAU1B,SAAgB,UAAU,CACxB,OAA8B,EAC9B,UAAgC,EAChC,YAAsB;IAEtB,IAAI,UAAU;QACZ,OAAO,CAAC,cAAc;QACtB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC;QACjD,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC,EAAE;QACvE,OAAO,OAAO,CAAC,cAAc,CAAC,UAAU,CAAE,CAAC;KAC5C;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAdD,gCAcC"} \ No newline at end of file diff --git a/dist/commonjs/middleware.d.ts b/dist/commonjs/middleware.d.ts deleted file mode 100644 index 5044195..0000000 --- a/dist/commonjs/middleware.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface CallingAction { - name: string; - params?: any[]; -} -export declare type Middleware = (state: T, originalState?: T, settings?: any, action?: CallingAction) => T | Promise | void | false; -export declare enum MiddlewarePlacement { - Before = "before", - After = "after" -} -export declare function logMiddleware(state: T, _: T, settings?: any): void; -export declare function localStorageMiddleware(state: T, _: T, settings?: any): void; -export declare function rehydrateFromLocalStorage(state: T, key?: string): any; diff --git a/dist/commonjs/middleware.js b/dist/commonjs/middleware.js deleted file mode 100644 index d073b37..0000000 --- a/dist/commonjs/middleware.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var aurelia_pal_1 = require("aurelia-pal"); -var MiddlewarePlacement; -(function (MiddlewarePlacement) { - MiddlewarePlacement["Before"] = "before"; - MiddlewarePlacement["After"] = "after"; -})(MiddlewarePlacement = exports.MiddlewarePlacement || (exports.MiddlewarePlacement = {})); -function logMiddleware(state, _, settings) { - if (settings && settings.logType && console.hasOwnProperty(settings.logType)) { - console[settings.logType]("New state: ", state); - } - else { - console.log("New state: ", state); - } -} -exports.logMiddleware = logMiddleware; -function localStorageMiddleware(state, _, settings) { - if (aurelia_pal_1.PLATFORM.global.localStorage) { - var key = settings && settings.key && typeof settings.key === "string" - ? settings.key - : "aurelia-store-state"; - aurelia_pal_1.PLATFORM.global.localStorage.setItem(key, JSON.stringify(state)); - } -} -exports.localStorageMiddleware = localStorageMiddleware; -function rehydrateFromLocalStorage(state, key) { - if (!aurelia_pal_1.PLATFORM.global.localStorage) { - return state; - } - var storedState = aurelia_pal_1.PLATFORM.global.localStorage.getItem(key || "aurelia-store-state"); - if (!storedState) { - return state; - } - try { - return JSON.parse(storedState); - } - catch (e) { } - return state; -} -exports.rehydrateFromLocalStorage = rehydrateFromLocalStorage; -//# sourceMappingURL=middleware.js.map \ No newline at end of file diff --git a/dist/commonjs/middleware.js.map b/dist/commonjs/middleware.js.map deleted file mode 100644 index e353b37..0000000 --- a/dist/commonjs/middleware.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":";;AAAA,2CAAuC;AAQvC,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,sCAAe,CAAA;AACjB,CAAC,EAHW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAG9B;AAED,SAAgB,aAAa,CAAI,KAAQ,EAAE,CAAI,EAAE,QAAc;IAC7D,IAAI,QAA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js/store.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Observable } from "rxjs"; -import { HistoryOptions } from "./history"; -import { Middleware, MiddlewarePlacement } from "./middleware"; -import { LogDefinitions } from "./logging"; -import { DevToolsOptions } from "./devtools"; -export declare type Reducer = (state: T, ...params: P) => T | false | Promise; -export declare enum PerformanceMeasurement { - StartEnd = "startEnd", - All = "all" -} -export interface StoreOptions { - history: Partial; - logDispatchedActions?: boolean; - measurePerformance?: PerformanceMeasurement; - propagateError?: boolean; - logDefinitions?: LogDefinitions; - devToolsOptions?: DevToolsOptions; -} -export declare class Store { - private initialState; - readonly state: Observable; - private logger; - private devToolsAvailable; - private devTools; - private actions; - private middlewares; - private _state; - private options; - private dispatchQueue; - constructor(initialState: T, options?: Partial); - registerMiddleware(reducer: Middleware, placement: MiddlewarePlacement, settings?: any): void; - unregisterMiddleware(reducer: Middleware): void; - isMiddlewareRegistered(middleware: Middleware): boolean; - registerAction(name: string, reducer: Reducer): void; - unregisterAction(reducer: Reducer): void; - isActionRegistered(reducer: Reducer | string): boolean; - resetToState(state: T): void; - dispatch