@ngxs/store 3.8.1-dev.master-3e21e23 → 3.8.1-dev.master-94c82c4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store/internals'), require('@angular/common'), require('rxjs'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('@ngxs/store', ['exports', '@angular/core', '@ngxs/store/internals', '@angular/common', 'rxjs', 'rxjs/operators'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngxs = global.ngxs || {}, global.ngxs.store = {}), global.ng.core, global.ngxs.store.internals, global.ng.common, global.rxjs, global.rxjs.operators));
5
- })(this, (function (exports, i0, i5, common, rxjs, operators) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store/internals'), require('@angular/common'), require('rxjs'), require('rxjs/operators'), require('@ngxs/store/operators')) :
3
+ typeof define === 'function' && define.amd ? define('@ngxs/store', ['exports', '@angular/core', '@ngxs/store/internals', '@angular/common', 'rxjs', 'rxjs/operators', '@ngxs/store/operators'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ngxs = global.ngxs || {}, global.ngxs.store = {}), global.ng.core, global.ngxs.store.internals, global.ng.common, global.rxjs, global.rxjs.operators, global.ngxs.store.operators));
5
+ })(this, (function (exports, i0, i5, common, rxjs, operators, operators$1) { 'use strict';
6
6
 
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
@@ -1010,33 +1010,28 @@
1010
1010
  }, {});
1011
1011
  }
1012
1012
 
1013
- var StoreValidators = /** @class */ (function () {
1014
- function StoreValidators() {
1013
+ var stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
1014
+ function ensureStateNameIsValid(name) {
1015
+ if (!name) {
1016
+ throwStateNamePropertyError();
1015
1017
  }
1016
- StoreValidators.checkThatStateIsNamedCorrectly = function (name) {
1017
- if (!name) {
1018
- throwStateNamePropertyError();
1019
- }
1020
- else if (!this.stateNameRegex.test(name)) {
1021
- throwStateNameError(name);
1022
- }
1023
- };
1024
- StoreValidators.checkThatStateNameIsUnique = function (stateName, state, statesByName) {
1025
- var existingState = statesByName[stateName];
1026
- if (existingState && existingState !== state) {
1027
- throwStateUniqueError(stateName, state.name, existingState.name);
1018
+ else if (!stateNameRegex.test(name)) {
1019
+ throwStateNameError(name);
1020
+ }
1021
+ }
1022
+ function ensureStateNameIsUnique(stateName, state, statesByName) {
1023
+ var existingState = statesByName[stateName];
1024
+ if (existingState && existingState !== state) {
1025
+ throwStateUniqueError(stateName, state.name, existingState.name);
1026
+ }
1027
+ }
1028
+ function ensureStatesAreDecorated(stateClasses) {
1029
+ stateClasses.forEach(function (stateClass) {
1030
+ if (!getStoreMetadata$1(stateClass)) {
1031
+ throwStateDecoratorError(stateClass.name);
1028
1032
  }
1029
- };
1030
- StoreValidators.checkThatStateClassesHaveBeenDecorated = function (stateClasses) {
1031
- stateClasses.forEach(function (stateClass) {
1032
- if (!getStoreMetadata$1(stateClass)) {
1033
- throwStateDecoratorError(stateClass.name);
1034
- }
1035
- });
1036
- };
1037
- return StoreValidators;
1038
- }());
1039
- StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
1033
+ });
1034
+ }
1040
1035
 
1041
1036
  /**
1042
1037
  * All provided or injected tokens must have `@Injectable` decorator
@@ -1728,43 +1723,21 @@
1728
1723
  */
1729
1724
  StateContextFactory.prototype.createStateContext = function (mappedStore) {
1730
1725
  var root = this._internalStateOperations.getRootStateOperations();
1731
- function getState(currentAppState) {
1732
- return getValue(currentAppState, mappedStore.path);
1733
- }
1734
- function setStateValue(currentAppState, newValue) {
1735
- var newAppState = setValue(currentAppState, mappedStore.path, newValue);
1736
- root.setState(newAppState);
1737
- return newAppState;
1738
- // In doing this refactoring I noticed that there is a 'bug' where the
1739
- // application state is returned instead of this state slice.
1740
- // This has worked this way since the beginning see:
1741
- // https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
1742
- // This needs to be fixed, but is a 'breaking' change.
1743
- // I will do this fix in a subsequent PR and we can decide how to handle it.
1744
- }
1745
- function setStateFromOperator(currentAppState, stateOperator) {
1746
- var local = getState(currentAppState);
1747
- var newValue = stateOperator(local);
1748
- return setStateValue(currentAppState, newValue);
1749
- }
1750
- function isStateOperator(value) {
1751
- return typeof value === 'function';
1752
- }
1753
1726
  return {
1754
1727
  getState: function () {
1755
1728
  var currentAppState = root.getState();
1756
- return getState(currentAppState);
1729
+ return getState(currentAppState, mappedStore.path);
1757
1730
  },
1758
1731
  patchState: function (val) {
1759
1732
  var currentAppState = root.getState();
1760
1733
  var patchOperator = simplePatch(val);
1761
- return setStateFromOperator(currentAppState, patchOperator);
1734
+ return setStateFromOperator(root, currentAppState, patchOperator, mappedStore.path);
1762
1735
  },
1763
1736
  setState: function (val) {
1764
1737
  var currentAppState = root.getState();
1765
- return isStateOperator(val)
1766
- ? setStateFromOperator(currentAppState, val)
1767
- : setStateValue(currentAppState, val);
1738
+ return operators$1.isStateOperator(val)
1739
+ ? setStateFromOperator(root, currentAppState, val, mappedStore.path)
1740
+ : setStateValue(root, currentAppState, val, mappedStore.path);
1768
1741
  },
1769
1742
  dispatch: function (actions) {
1770
1743
  return root.dispatch(actions);
@@ -1779,6 +1752,25 @@
1779
1752
  type: i0.Injectable,
1780
1753
  args: [{ providedIn: 'root' }]
1781
1754
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1755
+ function setStateValue(root, currentAppState, newValue, path) {
1756
+ var newAppState = setValue(currentAppState, path, newValue);
1757
+ root.setState(newAppState);
1758
+ return newAppState;
1759
+ // In doing this refactoring I noticed that there is a 'bug' where the
1760
+ // application state is returned instead of this state slice.
1761
+ // This has worked this way since the beginning see:
1762
+ // https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
1763
+ // This needs to be fixed, but is a 'breaking' change.
1764
+ // I will do this fix in a subsequent PR and we can decide how to handle it.
1765
+ }
1766
+ function setStateFromOperator(root, currentAppState, stateOperator, path) {
1767
+ var local = getState(currentAppState, path);
1768
+ var newValue = stateOperator(local);
1769
+ return setStateValue(root, currentAppState, newValue, path);
1770
+ }
1771
+ function getState(currentAppState, path) {
1772
+ return getValue(currentAppState, path);
1773
+ }
1782
1774
 
1783
1775
  var NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1784
1776
  /**
@@ -1864,8 +1856,8 @@
1864
1856
  enumerable: false,
1865
1857
  configurable: true
1866
1858
  });
1867
- StateFactory.cloneDefaults = function (defaults) {
1868
- var value = {};
1859
+ StateFactory._cloneDefaults = function (defaults) {
1860
+ var value = defaults;
1869
1861
  if (Array.isArray(defaults)) {
1870
1862
  value = defaults.slice();
1871
1863
  }
@@ -1875,9 +1867,6 @@
1875
1867
  else if (defaults === undefined) {
1876
1868
  value = {};
1877
1869
  }
1878
- else {
1879
- value = defaults;
1880
- }
1881
1870
  return value;
1882
1871
  };
1883
1872
  StateFactory.prototype.ngOnDestroy = function () {
@@ -1890,7 +1879,7 @@
1890
1879
  StateFactory.prototype.add = function (stateClasses) {
1891
1880
  var e_1, _b;
1892
1881
  if (NG_DEV_MODE) {
1893
- StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1882
+ ensureStatesAreDecorated(stateClasses);
1894
1883
  }
1895
1884
  var newStates = this.addToStatesMap(stateClasses).newStates;
1896
1885
  if (!newStates.length)
@@ -1911,7 +1900,7 @@
1911
1900
  // `State` decorator. This check is moved here because the `ɵprov` property
1912
1901
  // will not exist on the class in JIT mode (because it's set asynchronously
1913
1902
  // during JIT compilation through `Object.defineProperty`).
1914
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1903
+ if (NG_DEV_MODE) {
1915
1904
  ensureStateClassIsInjectable(stateClass);
1916
1905
  }
1917
1906
  var stateMap = {
@@ -1920,7 +1909,7 @@
1920
1909
  isInitialised: false,
1921
1910
  actions: meta.actions,
1922
1911
  instance: this._injector.get(stateClass),
1923
- defaults: StateFactory.cloneDefaults(meta.defaults)
1912
+ defaults: StateFactory._cloneDefaults(meta.defaults)
1924
1913
  };
1925
1914
  // ensure our store hasn't already been added
1926
1915
  // but don't throw since it could be lazy
@@ -2066,7 +2055,7 @@
2066
2055
  var stateClass = stateClasses_1_1.value;
2067
2056
  var stateName = getStoreMetadata$1(stateClass).name;
2068
2057
  if (NG_DEV_MODE) {
2069
- StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
2058
+ ensureStateNameIsUnique(stateName, stateClass, statesMap);
2070
2059
  }
2071
2060
  var unmountedState = !statesMap[stateName];
2072
2061
  if (unmountedState) {
@@ -2601,36 +2590,34 @@
2601
2590
  * Decorates a class with ngxs state information.
2602
2591
  */
2603
2592
  function State(options) {
2604
- function getStateOptions(inheritedStateClass) {
2605
- var inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
2606
- return Object.assign(Object.assign({}, inheritanceOptions), options);
2607
- }
2608
- function mutateMetaData(params) {
2609
- var meta = params.meta, inheritedStateClass = params.inheritedStateClass, optionsWithInheritance = params.optionsWithInheritance;
2610
- var children = optionsWithInheritance.children, defaults = optionsWithInheritance.defaults, name = optionsWithInheritance.name;
2611
- var stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
2612
- // Caretaker note: we have still left the `typeof` condition in order to avoid
2613
- // creating a breaking change for projects that still use the View Engine.
2614
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
2615
- StoreValidators.checkThatStateIsNamedCorrectly(stateName);
2616
- }
2617
- if (inheritedStateClass.hasOwnProperty(META_KEY)) {
2618
- var inheritedMeta = inheritedStateClass[META_KEY] || {};
2619
- meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
2620
- }
2621
- meta.children = children;
2622
- meta.defaults = defaults;
2623
- meta.name = stateName;
2624
- }
2625
2593
  return function (target) {
2626
2594
  var stateClass = target;
2627
2595
  var meta = ensureStoreMetadata$1(stateClass);
2628
2596
  var inheritedStateClass = Object.getPrototypeOf(stateClass);
2629
- var optionsWithInheritance = getStateOptions(inheritedStateClass);
2597
+ var optionsWithInheritance = getStateOptions(inheritedStateClass, options);
2630
2598
  mutateMetaData({ meta: meta, inheritedStateClass: inheritedStateClass, optionsWithInheritance: optionsWithInheritance });
2631
2599
  stateClass[META_OPTIONS_KEY] = optionsWithInheritance;
2632
2600
  };
2633
2601
  }
2602
+ function getStateOptions(inheritedStateClass, options) {
2603
+ var inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
2604
+ return Object.assign(Object.assign({}, inheritanceOptions), options);
2605
+ }
2606
+ function mutateMetaData(params) {
2607
+ var meta = params.meta, inheritedStateClass = params.inheritedStateClass, optionsWithInheritance = params.optionsWithInheritance;
2608
+ var children = optionsWithInheritance.children, defaults = optionsWithInheritance.defaults, name = optionsWithInheritance.name;
2609
+ var stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
2610
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2611
+ ensureStateNameIsValid(stateName);
2612
+ }
2613
+ if (inheritedStateClass.hasOwnProperty(META_KEY)) {
2614
+ var inheritedMeta = inheritedStateClass[META_KEY] || {};
2615
+ meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
2616
+ }
2617
+ meta.children = children;
2618
+ meta.defaults = defaults;
2619
+ meta.name = stateName;
2620
+ }
2634
2621
 
2635
2622
  var DOLLAR_CHAR_CODE = 36;
2636
2623
  function createSelectObservable(selector) {