Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ngxs/store

Package Overview
Dependencies
Maintainers
2
Versions
1360
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngxs/store - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0-beta.0

256

bundles/ngxs-store.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/Subject'), require('rxjs/BehaviorSubject'), require('rxjs/Observable'), require('rxjs/operators'), require('rxjs/observable/forkJoin'), require('rxjs/operators/map'), require('rxjs/observable/fromPromise'), require('rxjs/observable/of')) :
typeof define === 'function' && define.amd ? define('@ngxs/store', ['exports', '@angular/core', 'rxjs/Subject', 'rxjs/BehaviorSubject', 'rxjs/Observable', 'rxjs/operators', 'rxjs/observable/forkJoin', 'rxjs/operators/map', 'rxjs/observable/fromPromise', 'rxjs/observable/of'], factory) :
(factory((global.ngxs = global.ngxs || {}, global.ngxs.store = {}),global.ng.core,global.Rx,global.Rx,global.Rx,global.Rx.Observable.prototype,global.Rx.Observable,global.Rx.Observable.prototype,global.Rx.Observable,global.Rx.Observable));
}(this, (function (exports,core,Subject,BehaviorSubject,Observable,operators,forkJoin,map,fromPromise,of) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('rxjs/Observable'), require('rxjs/observable/fromPromise'), require('rxjs/observable/of'), require('rxjs/observable/forkJoin'), require('rxjs/Subject'), require('rxjs/BehaviorSubject'), require('rxjs/operators/map')) :
typeof define === 'function' && define.amd ? define('@ngxs/store', ['exports', '@angular/core', 'rxjs/operators', 'rxjs/Observable', 'rxjs/observable/fromPromise', 'rxjs/observable/of', 'rxjs/observable/forkJoin', 'rxjs/Subject', 'rxjs/BehaviorSubject', 'rxjs/operators/map'], factory) :
(factory((global.ngxs = global.ngxs || {}, global.ngxs.store = {}),global.ng.core,global.Rx.Observable.prototype,global.Rx,global.Rx.Observable,global.Rx.Observable,global.Rx.Observable,global.Rx,global.Rx,global.Rx.Observable.prototype));
}(this, (function (exports,core,operators,Observable,fromPromise,of,forkJoin,Subject,BehaviorSubject,map) { 'use strict';

@@ -210,2 +210,15 @@ /*! *****************************************************************************

var getValue = function (obj, prop) { return prop.split('.').reduce(function (acc, part) { return acc && acc[part]; }, obj); };
function ofAction() {
var allowedTypes = [];
for (var _i = 0; _i < arguments.length; _i++) {
allowedTypes[_i] = arguments[_i];
}
var allowedMap = {};
allowedTypes.forEach(function (klass) {
allowedMap[klass.type || klass.name] = true;
});
return operators.filter(function (action) {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
var StateFactory = /** @class */ (function () {

@@ -282,74 +295,105 @@ function StateFactory(_injector, _parentFactory) {

};
StateFactory.prototype.addAndReturnDefaults = function (stores) {
return this.add(stores).reduce(function (result, meta) { return setValue(result, meta.depth, meta.defaults); }, {});
StateFactory.prototype.addAndReturnDefaults = function (stateKlasses) {
if (stateKlasses) {
var states = this.add(stateKlasses);
var defaults = states.reduce(function (result, meta) { return setValue(result, meta.depth, meta.defaults); }, {});
return { defaults: defaults, states: states };
}
};
StateFactory.prototype.invokeActions = function (getState, setState, dispatch, action) {
StateFactory.prototype.invokeInit = function (getState, setState, dispatch, stateMetadatas) {
try {
for (var stateMetadatas_1 = __values(stateMetadatas), stateMetadatas_1_1 = stateMetadatas_1.next(); !stateMetadatas_1_1.done; stateMetadatas_1_1 = stateMetadatas_1.next()) {
var metadata = stateMetadatas_1_1.value;
if (metadata.instance.onInit) {
var stateContext = this.createStateContext(getState, setState, dispatch, metadata);
metadata.instance.onInit(stateContext);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (stateMetadatas_1_1 && !stateMetadatas_1_1.done && (_a = stateMetadatas_1.return)) _a.call(stateMetadatas_1);
}
finally { if (e_2) throw e_2.error; }
}
var e_2, _a;
};
StateFactory.prototype.invokeActions = function (getState, setState, dispatch, actions$, action) {
var results = [];
var _loop_2 = function (metadata) {
var name = getActionTypeFromInstance(action);
var actionMetas = metadata.actions[name];
if (actionMetas) {
try {
for (var actionMetas_1 = __values(actionMetas), actionMetas_1_1 = actionMetas_1.next(); !actionMetas_1_1.done; actionMetas_1_1 = actionMetas_1.next()) {
var actionMeta = actionMetas_1_1.value;
var stateContext = {
getState: function () {
var state = getState();
return getValue(state, metadata.depth);
},
patchState: function (val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
var state = getState();
var local = getValue(state, metadata.depth);
for (var k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
setState: function (val) {
var state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
dispatch: function (actions) {
return dispatch(actions);
try {
for (var _a = __values(this.states), _b = _a.next(); !_b.done; _b = _a.next()) {
var metadata = _b.value;
var name = getActionTypeFromInstance(action);
var actionMetas = metadata.actions[name];
if (actionMetas) {
try {
for (var actionMetas_1 = __values(actionMetas), actionMetas_1_1 = actionMetas_1.next(); !actionMetas_1_1.done; actionMetas_1_1 = actionMetas_1.next()) {
var actionMeta = actionMetas_1_1.value;
var stateContext = this.createStateContext(getState, setState, dispatch, metadata);
var result = metadata.instance[actionMeta.fn](stateContext, action);
if (result === undefined) {
result = of.of({}).pipe(operators.shareReplay());
}
};
var result = metadata.instance[actionMeta.fn](stateContext, action);
if (result) {
else if (result instanceof Promise) {
result = fromPromise.fromPromise(result);
}
if (result instanceof Observable.Observable) {
result = result.pipe(((actionMeta.options)).takeLast
? operators.takeUntil(actions$.pipe(ofAction(action.constructor)))
: operators.map(function (r) { return r; }));
}
results.push(result);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (actionMetas_1_1 && !actionMetas_1_1.done && (_a = actionMetas_1.return)) _a.call(actionMetas_1);
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (actionMetas_1_1 && !actionMetas_1_1.done && (_c = actionMetas_1.return)) _c.call(actionMetas_1);
}
finally { if (e_3) throw e_3.error; }
}
finally { if (e_2) throw e_2.error; }
}
}
var e_2, _a;
};
try {
for (var _a = __values(this.states), _b = _a.next(); !_b.done; _b = _a.next()) {
var metadata = _b.value;
_loop_2(metadata);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
}
finally { if (e_3) throw e_3.error; }
finally { if (e_4) throw e_4.error; }
}
return results;
var e_3, _c;
return forkJoin.forkJoin(results);
var e_4, _d, e_3, _c;
};
StateFactory.prototype.createStateContext = function (getState, setState, dispatch, metadata) {
return {
getState: function () {
var state = getState();
return getValue(state, metadata.depth);
},
patchState: function (val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
var state = getState();
var local = getValue(state, metadata.depth);
for (var k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
setState: function (val) {
var state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
dispatch: function (actions) {
return dispatch(actions);
}
};
};
return StateFactory;

@@ -484,2 +528,5 @@ }());

};
Store.prototype.selectSnapshot = function (selector) {
return selector(this._stateStream.getValue());
};
Store.prototype.subscribe = function (fn) {

@@ -498,34 +545,8 @@ return this._stateStream.subscribe(fn);

_this._actions.next(nextAction);
return _this._dispatchActions(nextAction).pipe(map.map(function () { return _this._stateStream.getValue(); }));
return _this._storeFactory
.invokeActions(function () { return _this._stateStream.getValue(); }, function (newState) { return _this._stateStream.next(newState); }, function (actions) { return _this.dispatch(actions); }, _this._actions, action)
.pipe(map.map(function () { return _this._stateStream.getValue(); }));
}
]))(prevState, action))).pipe(operators.shareReplay());
};
Store.prototype._dispatchActions = function (action) {
var _this = this;
var results = this._storeFactory.invokeActions(function () { return _this._stateStream.getValue(); }, function (newState) { return _this._stateStream.next(newState); }, function (actions) { return _this.dispatch(actions); }, action);
return (results.length ? forkJoin.forkJoin(this._handleNesting(results)) : of.of({})).pipe(operators.shareReplay());
};
Store.prototype._handleNesting = function (eventResults) {
var results = [];
try {
for (var eventResults_1 = __values(eventResults), eventResults_1_1 = eventResults_1.next(); !eventResults_1_1.done; eventResults_1_1 = eventResults_1.next()) {
var eventResult = eventResults_1_1.value;
if (eventResult instanceof Promise) {
eventResult = fromPromise.fromPromise(eventResult);
}
if (eventResult instanceof Observable.Observable) {
results.push(eventResult);
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (eventResults_1_1 && !eventResults_1_1.done && (_a = eventResults_1.return)) _a.call(eventResults_1);
}
finally { if (e_4) throw e_4.error; }
}
return results;
var e_4, _a;
};
return Store;

@@ -617,15 +638,13 @@ }());

var NgxsRootModule = /** @class */ (function () {
function NgxsRootModule(_factory, _stateStream, store, select, states) {
this._factory = _factory;
this._stateStream = _stateStream;
this.initStates(states);
function NgxsRootModule(factory, stateStream, store, select, states) {
var results = factory.addAndReturnDefaults(states);
if (results) {
var cur = stateStream.getValue();
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new InitState());
if (results) {
factory.invokeInit(function () { return stateStream.getValue(); }, function (newState) { return stateStream.next(newState); }, function (actions) { return store.dispatch(actions); }, results.states);
}
}
NgxsRootModule.prototype.initStates = function (states) {
if (states) {
var init = this._factory.addAndReturnDefaults(states);
var cur = this._stateStream.getValue();
this._stateStream.next(Object.assign({}, cur, init));
}
};
return NgxsRootModule;

@@ -644,16 +663,14 @@ }());

var NgxsFeatureModule = /** @class */ (function () {
function NgxsFeatureModule(root, store, _stateStream, _factory, states) {
this._stateStream = _stateStream;
this._factory = _factory;
function NgxsFeatureModule(store, stateStream, factory, states) {
var flattenedStates = (([])).concat.apply((([])), __spread(states));
this.initStates(flattenedStates);
var results = factory.addAndReturnDefaults(flattenedStates);
if (results) {
var cur = stateStream.getValue();
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new UpdateState());
if (results) {
factory.invokeInit(function () { return stateStream.getValue(); }, function (newState) { return stateStream.next(newState); }, function (actions) { return store.dispatch(actions); }, results.states);
}
}
NgxsFeatureModule.prototype.initStates = function (stores) {
if (stores) {
var init = this._factory.addAndReturnDefaults(stores);
var cur = this._stateStream.getValue();
this._stateStream.next(Object.assign({}, cur, init));
}
};
return NgxsFeatureModule;

@@ -665,3 +682,2 @@ }());

NgxsFeatureModule.ctorParameters = function () { return [
{ type: NgxsRootModule, },
{ type: Store, },

@@ -715,3 +731,3 @@ { type: StateStream, },

NgxsModule.ctorParameters = function () { return []; };
function Action(actions) {
function Action(actions, options) {
return function (target, name, descriptor) {

@@ -731,2 +747,3 @@ var meta = ensureStoreMetadata(target.constructor);

fn: name,
options: options || {},
type: type

@@ -761,13 +778,2 @@ });

}
function ofAction() {
var allowedTypes = [];
for (var _i = 0; _i < arguments.length; _i++) {
allowedTypes[_i] = arguments[_i];
}
var allowedMap = {};
allowedTypes.forEach(function (klass) { return (allowedMap[klass.type || klass.name] = true); });
return operators.filter(function (action) {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
function memoize(func, resolver) {

@@ -774,0 +780,0 @@ var memoized = function () {

@@ -1,2 +0,2 @@

!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("rxjs/Subject"),require("rxjs/BehaviorSubject"),require("rxjs/Observable"),require("rxjs/operators"),require("rxjs/observable/forkJoin"),require("rxjs/operators/map"),require("rxjs/observable/fromPromise"),require("rxjs/observable/of")):"function"==typeof define&&define.amd?define("@ngxs/store",["exports","@angular/core","rxjs/Subject","rxjs/BehaviorSubject","rxjs/Observable","rxjs/operators","rxjs/observable/forkJoin","rxjs/operators/map","rxjs/observable/fromPromise","rxjs/observable/of"],r):r((t.ngxs=t.ngxs||{},t.ngxs.store={}),t.ng.core,t.Rx,t.Rx,t.Rx,t.Rx.Observable.prototype,t.Rx.Observable,t.Rx.Observable.prototype,t.Rx.Observable,t.Rx.Observable)}(this,function(t,r,e,n,u,o,a,i,c,s){"use strict";var f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};function p(t,r){function e(){this.constructor=t}f(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}function m(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}}function l(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,o,a=e.call(t),i=[];try{for(;(void 0===r||0<r--)&&!(n=a.next()).done;)i.push(n.value)}catch(s){o={error:s}}finally{try{n&&!n.done&&(e=a["return"])&&e.call(a)}finally{if(o)throw o.error}}return i}function S(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(l(arguments[r]));return t}var h=new r.InjectionToken("ROOT_STATE_TOKEN"),y=new r.InjectionToken("FEATURE_STATE_TOKEN"),j="NGXS_META",d=new r.InjectionToken("NGXS_PLUGINS");function v(t){if(!t.hasOwnProperty(j)){Object.defineProperty(t,j,{value:{name:null,actions:{},defaults:{},path:null,children:[]}})}return t[j]}function b(t){for(var r=t,e="store."+r[0],n=0,o=r.length,a=e;++n<o;)a=a+" && "+(e=e+"."+r[n]);return new Function("store","return "+a+";")}function g(t){return t.constructor.type?t.constructor.type:t.constructor.name?t.constructor.name:t.type?t.type:void 0}var _=function(t,r,e){t=Object.assign({},t);var n=r.split("."),o=n[n.length-1];return n.reduce(function(t,r){return t[r]=r===o?e:Object.assign({},t[r]),t&&t[r]},t),t},x=function(t,r){return r.split(".").reduce(function(t,r){return t&&t[r]},t)},w=function(){function t(t,r){this._injector=t,this._parentFactory=r,this._states=[]}return Object.defineProperty(t.prototype,"states",{get:function(){return this._parentFactory?this._parentFactory.states:this._states},enumerable:!0,configurable:!0}),t.prototype.add=function(t){Array.isArray(t)||(t=[t]);var e,a,n,o,i,s,r,u,c,f=(a=function(r){var t=e.find(function(t){return t===r});if(!t)throw new Error("Child state not found: "+r);if(!t[j])throw new Error("States must be decorated with @State() decorator");return t[j].name},(e=t).reduce(function(t,r){if(!r[j])throw new Error("States must be decorated with @State() decorator");var e=r[j],n=e.name,o=e.children;return t[n]=(o||[]).map(a),t},{})),p=(n=f,o=[],i={},s=function(r,e){void 0===e&&(e=[]),Array.isArray(e)||(e=[]),e.push(r),i[r]=!0,n[r].forEach(function(t){if(0<=e.indexOf(t))throw new Error("Circular dependency '"+t+"' is required by '"+r+"': "+e.join(" -> "));i[t]||s(t,e.slice(0))}),o.indexOf(r)<0&&o.push(r)},Object.keys(n).forEach(function(t){return s(t)}),o.reverse()),l=function(t,r){void 0===r&&(r={});var o=function(t,r){for(var e in t)if(t.hasOwnProperty(e)&&0<=t[e].indexOf(r)){var n=o(t,e);return null!==n?n+"."+e:e}return null};for(var e in t)if(t.hasOwnProperty(e)){var n=o(t,e);r[e]=n?n+"."+e:e}return r}(f),h=t.reduce(function(t,r){if(!r[j])throw new Error("States must be decorated with @State() decorator");return t[r[j].name]=r,t},{}),y=[],d=function(r){var t=h[r];if(!t[j])throw new Error("States must be decorated with @State() decorator");var e,n=l[r],o=t[j].actions,a=t[j].defaults;if(t[j].path=n,v.states.find(function(t){return t.name===r}))throw new Error("Store has already been added: "+r);Array.isArray(a)?a=S(a):"object"==typeof(e=a)&&null!==e||"function"==typeof e?a=Object.assign({},a):a===undefined&&(a={});var i=v._injector.get(t);y.push({actions:o,instance:i,defaults:a,name:r,depth:n})},v=this;try{for(var b=m(p),g=b.next();!g.done;g=b.next()){d(g.value)}}catch(_){r={error:_}}finally{try{g&&!g.done&&(u=b["return"])&&u.call(b)}finally{if(r)throw r.error}}return(c=this.states).push.apply(c,S(y)),y},t.prototype.addAndReturnDefaults=function(t){return this.add(t).reduce(function(t,r){return _(t,r.depth,r.defaults)},{})},t.prototype.invokeActions=function(p,l,h,y){var t,r,d=[],e=function(o){var t,r,e=g(y),n=o.actions[e];if(n)try{for(var a=m(n),i=a.next();!i.done;i=a.next()){var s=i.value,u={getState:function(){var t=p();return x(t,o.depth)},patchState:function(t){if(Array.isArray(t))throw new Error("Patching arrays is not supported.");var r=p(),e=x(r,o.depth);for(var n in t)e[n]=t[n];return r=_(r,o.depth,Object.assign({},e)),l(r),r},setState:function(t){var r=p();return r=_(r,o.depth,t),l(r),r},dispatch:function(t){return h(t)}},c=o.instance[s.fn](u,y);c&&d.push(c)}}catch(f){t={error:f}}finally{try{i&&!i.done&&(r=a["return"])&&r.call(a)}finally{if(t)throw t.error}}};try{for(var n=m(this.states),o=n.next();!o.done;o=n.next()){e(o.value)}}catch(a){t={error:a}}finally{try{o&&!o.done&&(r=n["return"])&&r.call(n)}finally{if(t)throw t.error}}return d},t}();w.decorators=[{type:r.Injectable}],w.ctorParameters=function(){return[{type:r.Injector},{type:w,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var O=function(e){function t(t){var r=e.call(this)||this;return t&&Object.assign(r,t),r}return p(t,e),t}(e.Subject);O.decorators=[{type:r.Injectable}],O.ctorParameters=function(){return[{type:O,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var A=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.shift().apply(void 0,S(t,[function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return A(e).apply(void 0,S(t))}]))}},E=function(e){function t(t){var r=e.call(this,{})||this;return t&&Object.assign(r,t),r}return p(t,e),t}(n.BehaviorSubject);E.decorators=[{type:r.Injectable}],E.ctorParameters=function(){return[{type:E,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var P=function(){function t(t,r){this._parentManager=t,this._plugins=r,this.plugins=[],this.register()}return t.prototype.register=function(){var t;this._plugins&&(this.plugins=this._plugins.map(function(t){return t.handle?t.handle.bind(t):t}),this._parentManager&&(t=this._parentManager.plugins).push.apply(t,S(this.plugins)))},t}();P.decorators=[{type:r.Injectable}],P.ctorParameters=function(){return[{type:P,decorators:[{type:r.Optional},{type:r.SkipSelf}]},{type:Array,decorators:[{type:r.Inject,args:[d]},{type:r.Optional}]}]};var I=function(){function t(t,r,e,n,o){this._errorHandler=t,this._actions=r,this._storeFactory=e,this._pluginManager=n,this._stateStream=o}return t.prototype.dispatch=function(t){var r,e=this;return(r=Array.isArray(t)?a.forkJoin(t.map(function(t){return e._dispatch(t)})):this._dispatch(t)).pipe(o.catchError(function(t){return e._errorHandler.handleError(t),s.of(t)})),r.subscribe(),r},t.prototype.select=function(t){if(t[j]&&t[j].path){var r=b(t[j].path.split("."));return this._stateStream.pipe(i.map(r),o.distinctUntilChanged())}return this._stateStream.pipe(i.map(t),o.catchError(function(t){if(t instanceof TypeError)return s.of(undefined);throw t}),o.distinctUntilChanged())},t.prototype.selectOnce=function(t){return this.select(t).pipe(o.take(1))},t.prototype.subscribe=function(t){return this._stateStream.subscribe(t)},t.prototype._dispatch=function(t){var e=this,n=this._stateStream.getValue(),r=this._pluginManager.plugins;return A(S(r,[function(t,r){return t!==n&&e._stateStream.next(t),e._actions.next(r),e._dispatchActions(r).pipe(i.map(function(){return e._stateStream.getValue()}))}]))(n,t).pipe(o.shareReplay())},t.prototype._dispatchActions=function(t){var r=this,e=this._storeFactory.invokeActions(function(){return r._stateStream.getValue()},function(t){return r._stateStream.next(t)},function(t){return r.dispatch(t)},t);return(e.length?a.forkJoin(this._handleNesting(e)):s.of({})).pipe(o.shareReplay())},t.prototype._handleNesting=function(t){var r,e,n=[];try{for(var o=m(t),a=o.next();!a.done;a=o.next()){var i=a.value;i instanceof Promise&&(i=c.fromPromise(i)),i instanceof u.Observable&&n.push(i)}}catch(s){r={error:s}}finally{try{a&&!a.done&&(e=o["return"])&&e.call(o)}finally{if(r)throw r.error}}return n},t}();I.decorators=[{type:r.Injectable}],I.ctorParameters=function(){return[{type:r.ErrorHandler},{type:O},{type:w},{type:P},{type:E}]};var T=function(t){};T.store=undefined,T.decorators=[{type:r.Injectable}],T.ctorParameters=function(){return[{type:I}]};var k=function(){};k.type="@@INIT";var R=function(){};R.type="@@UPDATE_STATE";var M=function(){function t(t,r,e,n,o){this._factory=t,this._stateStream=r,this.initStates(o),e.dispatch(new k)}return t.prototype.initStates=function(t){if(t){var r=this._factory.addAndReturnDefaults(t),e=this._stateStream.getValue();this._stateStream.next(Object.assign({},e,r))}},t}();M.decorators=[{type:r.NgModule}],M.ctorParameters=function(){return[{type:w},{type:E},{type:I},{type:T},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[h]}]}]};var N=function(){function t(t,r,e,n,o){this._stateStream=e,this._factory=n;var a=[].concat.apply([],S(o));this.initStates(a),r.dispatch(new R)}return t.prototype.initStates=function(t){if(t){var r=this._factory.addAndReturnDefaults(t),e=this._stateStream.getValue();this._stateStream.next(Object.assign({},e,r))}},t}();N.decorators=[{type:r.NgModule,args:[{}]}],N.ctorParameters=function(){return[{type:M},{type:I},{type:E},{type:w},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[y]}]}]};var q=function(){function t(){}return t.forRoot=function(t){return void 0===t&&(t=[]),{ngModule:M,providers:S([w,O,I,E,T,P],t,[{provide:h,useValue:t}])}},t.forFeature=function(t){return{ngModule:N,providers:S([w,P],t,[{provide:y,multi:!0,useValue:t}])}},t}();q.decorators=[{type:r.NgModule,args:[{}]}],q.ctorParameters=function(){return[]},t.NgxsModule=q,t.Action=function(l){return function(t,r,e){var n,o,a,i=v(t.constructor);Array.isArray(l)||(l=[l]);try{for(var s=m(l),u=s.next();!u.done;u=s.next()){var c=u.value,f=(n=c).type?n.type:n.name?n.name:void 0;i.actions[f]||(i.actions[f]=[]),i.actions[f].push({fn:r,type:f})}}catch(p){o={error:p}}finally{try{u&&!u.done&&(a=s["return"])&&a.call(s)}finally{if(o)throw o.error}}}},t.Store=I,t.State=function(n){return function(t){var r=v(t);if(t.__proto__.hasOwnProperty(j)){var e=t.__proto__[j];r.actions=Object.assign({},r.actions,e.actions)}if(r.children=n.children,r.defaults=n.defaults,r.name=n.name,!n.name)throw new Error("States must register a 'name' property")}},t.Select=function(n){for(var o=[],t=1;t<arguments.length;t++)o[t-1]=arguments[t];return function(t,r){var e="__"+r+"__selector";if(n||(n=r.lastIndexOf("$")===r.length-1?r.substring(0,r.length-1):r),t[e])throw new Error("You cannot use @Select decorator and a "+e+" property.");delete t[r]&&(Object.defineProperty(t,e,{writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(t,r,{get:function(){return this[e]||(this[e]=function(t){var r=T.store;if(!r)throw new Error("SelectFactory not connected to store!");return r.select(t)}.apply(this,["string"==typeof n?b(o.length?S([n],o):n.split(".")):n[j]&&n[j].path?b(n[j].path.split(".")):n]))},enumerable:!0,configurable:!0}))}},t.Actions=O,t.ofAction=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e={};return t.forEach(function(t){return e[t.type||t.name]=!0}),o.filter(function(t){return e[t.constructor.type||t.constructor.name]})},t.Selector=function(){for(var i=[],t=0;t<arguments.length;t++)i[t]=arguments[t];return function(t,r,e){var n=v(t);if(null!==e.value){var o=e.value,a=function(t){var r=x(t,n.path);try{return o(r)}catch(e){if(e instanceof TypeError)return undefined;throw e}};return{configurable:!0,get:function(){return function(a,i){var s=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=i?i.apply(this,t):t[0],n=s.cache;if(n.has(e))return n.get(e);var o=a.apply(this,t);return s.cache=n.set(e,o)||n,o};return s.cache=new WeakMap,s}.apply(null,S([a],i))}}}throw new Error("Selectors only work on methods")}},t.getActionTypeFromInstance=g,t.NGXS_PLUGINS=d,t.StateStream=E,t.setValue=_,t.getValue=x,t.InitState=k,t.UpdateState=R,t.ɵb=N,t.ɵa=M,t.ɵg=P,t.ɵc=T,t.ɵf=w,t.ɵe=y,t.ɵd=h,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("rxjs/operators"),require("rxjs/Observable"),require("rxjs/observable/fromPromise"),require("rxjs/observable/of"),require("rxjs/observable/forkJoin"),require("rxjs/Subject"),require("rxjs/BehaviorSubject"),require("rxjs/operators/map")):"function"==typeof define&&define.amd?define("@ngxs/store",["exports","@angular/core","rxjs/operators","rxjs/Observable","rxjs/observable/fromPromise","rxjs/observable/of","rxjs/observable/forkJoin","rxjs/Subject","rxjs/BehaviorSubject","rxjs/operators/map"],r):r((t.ngxs=t.ngxs||{},t.ngxs.store={}),t.ng.core,t.Rx.Observable.prototype,t.Rx,t.Rx.Observable,t.Rx.Observable,t.Rx.Observable,t.Rx,t.Rx,t.Rx.Observable.prototype)}(this,function(t,r,x,j,w,O,A,e,n,a){"use strict";var o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};function i(t,r){function e(){this.constructor=t}o(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}function E(t){var r="function"==typeof Symbol&&t[Symbol.iterator],e=0;return r?r.call(t):{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}}}function u(t,r){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var n,o,a=e.call(t),i=[];try{for(;(void 0===r||0<r--)&&!(n=a.next()).done;)i.push(n.value)}catch(u){o={error:u}}finally{try{n&&!n.done&&(e=a["return"])&&e.call(a)}finally{if(o)throw o.error}}return i}function _(){for(var t=[],r=0;r<arguments.length;r++)t=t.concat(u(arguments[r]));return t}var c=new r.InjectionToken("ROOT_STATE_TOKEN"),s=new r.InjectionToken("FEATURE_STATE_TOKEN"),S="NGXS_META",f=new r.InjectionToken("NGXS_PLUGINS");function d(t){if(!t.hasOwnProperty(S)){Object.defineProperty(t,S,{value:{name:null,actions:{},defaults:{},path:null,children:[]}})}return t[S]}function p(t){for(var r=t,e="store."+r[0],n=0,o=r.length,a=e;++n<o;)a=a+" && "+(e=e+"."+r[n]);return new Function("store","return "+a+";")}function P(t){return t.constructor.type?t.constructor.type:t.constructor.name?t.constructor.name:t.type?t.type:void 0}var l=function(t,r,e){t=Object.assign({},t);var n=r.split("."),o=n[n.length-1];return n.reduce(function(t,r){return t[r]=r===o?e:Object.assign({},t[r]),t&&t[r]},t),t},y=function(t,r){return r.split(".").reduce(function(t,r){return t&&t[r]},t)};function I(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e={};return t.forEach(function(t){e[t.type||t.name]=!0}),x.filter(function(t){return e[t.constructor.type||t.constructor.name]})}var h=function(){function t(t,r){this._injector=t,this._parentFactory=r,this._states=[]}return Object.defineProperty(t.prototype,"states",{get:function(){return this._parentFactory?this._parentFactory.states:this._states},enumerable:!0,configurable:!0}),t.prototype.add=function(t){Array.isArray(t)||(t=[t]);var e,a,n,o,i,u,r,c,s,f=(a=function(r){var t=e.find(function(t){return t===r});if(!t)throw new Error("Child state not found: "+r);if(!t[S])throw new Error("States must be decorated with @State() decorator");return t[S].name},(e=t).reduce(function(t,r){if(!r[S])throw new Error("States must be decorated with @State() decorator");var e=r[S],n=e.name,o=e.children;return t[n]=(o||[]).map(a),t},{})),p=(n=f,o=[],i={},u=function(r,e){void 0===e&&(e=[]),Array.isArray(e)||(e=[]),e.push(r),i[r]=!0,n[r].forEach(function(t){if(0<=e.indexOf(t))throw new Error("Circular dependency '"+t+"' is required by '"+r+"': "+e.join(" -> "));i[t]||u(t,e.slice(0))}),o.indexOf(r)<0&&o.push(r)},Object.keys(n).forEach(function(t){return u(t)}),o.reverse()),l=function(t,r){void 0===r&&(r={});var o=function(t,r){for(var e in t)if(t.hasOwnProperty(e)&&0<=t[e].indexOf(r)){var n=o(t,e);return null!==n?n+"."+e:e}return null};for(var e in t)if(t.hasOwnProperty(e)){var n=o(t,e);r[e]=n?n+"."+e:e}return r}(f),y=t.reduce(function(t,r){if(!r[S])throw new Error("States must be decorated with @State() decorator");return t[r[S].name]=r,t},{}),d=[],h=function(r){var t=y[r];if(!t[S])throw new Error("States must be decorated with @State() decorator");var e,n=l[r],o=t[S].actions,a=t[S].defaults;if(t[S].path=n,v.states.find(function(t){return t.name===r}))throw new Error("Store has already been added: "+r);Array.isArray(a)?a=_(a):"object"==typeof(e=a)&&null!==e||"function"==typeof e?a=Object.assign({},a):a===undefined&&(a={});var i=v._injector.get(t);d.push({actions:o,instance:i,defaults:a,name:r,depth:n})},v=this;try{for(var b=E(p),g=b.next();!g.done;g=b.next()){h(g.value)}}catch(m){r={error:m}}finally{try{g&&!g.done&&(c=b["return"])&&c.call(b)}finally{if(r)throw r.error}}return(s=this.states).push.apply(s,_(d)),d},t.prototype.addAndReturnDefaults=function(t){if(t){var r=this.add(t);return{defaults:r.reduce(function(t,r){return l(t,r.depth,r.defaults)},{}),states:r}}},t.prototype.invokeInit=function(t,r,e,n){try{for(var o=E(n),a=o.next();!a.done;a=o.next()){var i=a.value;if(i.instance.onInit){var u=this.createStateContext(t,r,e,i);i.instance.onInit(u)}}}catch(f){c={error:f}}finally{try{a&&!a.done&&(s=o["return"])&&s.call(o)}finally{if(c)throw c.error}}var c,s},t.prototype.invokeActions=function(t,r,e,n,o){var a,i,u,c,s=[];try{for(var f=E(this.states),p=f.next();!p.done;p=f.next()){var l=p.value,y=P(o),d=l.actions[y];if(d)try{for(var h=E(d),v=h.next();!v.done;v=h.next()){var b=v.value,g=this.createStateContext(t,r,e,l),m=l.instance[b.fn](g,o);m===undefined?m=O.of({}).pipe(x.shareReplay()):m instanceof Promise&&(m=w.fromPromise(m)),m instanceof j.Observable&&(m=m.pipe(b.options.takeLast?x.takeUntil(n.pipe(I(o.constructor))):x.map(function(t){return t}))),s.push(m)}}catch(_){u={error:_}}finally{try{v&&!v.done&&(c=h["return"])&&c.call(h)}finally{if(u)throw u.error}}}}catch(S){a={error:S}}finally{try{p&&!p.done&&(i=f["return"])&&i.call(f)}finally{if(a)throw a.error}}return A.forkJoin(s)},t.prototype.createStateContext=function(o,a,r,i){return{getState:function(){var t=o();return y(t,i.depth)},patchState:function(t){if(Array.isArray(t))throw new Error("Patching arrays is not supported.");var r=o(),e=y(r,i.depth);for(var n in t)e[n]=t[n];return r=l(r,i.depth,Object.assign({},e)),a(r),r},setState:function(t){var r=o();return r=l(r,i.depth,t),a(r),r},dispatch:function(t){return r(t)}}},t}();h.decorators=[{type:r.Injectable}],h.ctorParameters=function(){return[{type:r.Injector},{type:h,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var v=function(e){function t(t){var r=e.call(this)||this;return t&&Object.assign(r,t),r}return i(t,e),t}(e.Subject);v.decorators=[{type:r.Injectable}],v.ctorParameters=function(){return[{type:v,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var b=function(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.shift().apply(void 0,_(t,[function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return b(e).apply(void 0,_(t))}]))}},g=function(e){function t(t){var r=e.call(this,{})||this;return t&&Object.assign(r,t),r}return i(t,e),t}(n.BehaviorSubject);g.decorators=[{type:r.Injectable}],g.ctorParameters=function(){return[{type:g,decorators:[{type:r.Optional},{type:r.SkipSelf}]}]};var m=function(){function t(t,r){this._parentManager=t,this._plugins=r,this.plugins=[],this.register()}return t.prototype.register=function(){var t;this._plugins&&(this.plugins=this._plugins.map(function(t){return t.handle?t.handle.bind(t):t}),this._parentManager&&(t=this._parentManager.plugins).push.apply(t,_(this.plugins)))},t}();m.decorators=[{type:r.Injectable}],m.ctorParameters=function(){return[{type:m,decorators:[{type:r.Optional},{type:r.SkipSelf}]},{type:Array,decorators:[{type:r.Inject,args:[f]},{type:r.Optional}]}]};var k=function(){function t(t,r,e,n,o){this._errorHandler=t,this._actions=r,this._storeFactory=e,this._pluginManager=n,this._stateStream=o}return t.prototype.dispatch=function(t){var r,e=this;return(r=Array.isArray(t)?A.forkJoin(t.map(function(t){return e._dispatch(t)})):this._dispatch(t)).pipe(x.catchError(function(t){return e._errorHandler.handleError(t),O.of(t)})),r.subscribe(),r},t.prototype.select=function(t){if(t[S]&&t[S].path){var r=p(t[S].path.split("."));return this._stateStream.pipe(a.map(r),x.distinctUntilChanged())}return this._stateStream.pipe(a.map(t),x.catchError(function(t){if(t instanceof TypeError)return O.of(undefined);throw t}),x.distinctUntilChanged())},t.prototype.selectOnce=function(t){return this.select(t).pipe(x.take(1))},t.prototype.selectSnapshot=function(t){return t(this._stateStream.getValue())},t.prototype.subscribe=function(t){return this._stateStream.subscribe(t)},t.prototype._dispatch=function(e){var n=this,o=this._stateStream.getValue(),t=this._pluginManager.plugins;return b(_(t,[function(t,r){return t!==o&&n._stateStream.next(t),n._actions.next(r),n._storeFactory.invokeActions(function(){return n._stateStream.getValue()},function(t){return n._stateStream.next(t)},function(t){return n.dispatch(t)},n._actions,e).pipe(a.map(function(){return n._stateStream.getValue()}))}]))(o,e).pipe(x.shareReplay())},t}();k.decorators=[{type:r.Injectable}],k.ctorParameters=function(){return[{type:r.ErrorHandler},{type:v},{type:h},{type:m},{type:g}]};var T=function(t){};T.store=undefined,T.decorators=[{type:r.Injectable}],T.ctorParameters=function(){return[{type:k}]};var R=function(){};R.type="@@INIT";var M=function(){};M.type="@@UPDATE_STATE";var N=function(t,r,e,n,o){var a=t.addAndReturnDefaults(o);if(a){var i=r.getValue();r.next(Object.assign({},i,a.defaults))}e.dispatch(new R),a&&t.invokeInit(function(){return r.getValue()},function(t){return r.next(t)},function(t){return e.dispatch(t)},a.states)};N.decorators=[{type:r.NgModule}],N.ctorParameters=function(){return[{type:h},{type:g},{type:k},{type:T},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[c]}]}]};var V=function(r,e,t,n){var o=[].concat.apply([],_(n)),a=t.addAndReturnDefaults(o);if(a){var i=e.getValue();e.next(Object.assign({},i,a.defaults))}r.dispatch(new M),a&&t.invokeInit(function(){return e.getValue()},function(t){return e.next(t)},function(t){return r.dispatch(t)},a.states)};V.decorators=[{type:r.NgModule,args:[{}]}],V.ctorParameters=function(){return[{type:k},{type:g},{type:h},{type:Array,decorators:[{type:r.Optional},{type:r.Inject,args:[s]}]}]};var q=function(){function t(){}return t.forRoot=function(t){return void 0===t&&(t=[]),{ngModule:N,providers:_([h,v,k,g,T,m],t,[{provide:c,useValue:t}])}},t.forFeature=function(t){return{ngModule:V,providers:_([h,m],t,[{provide:s,multi:!0,useValue:t}])}},t}();q.decorators=[{type:r.NgModule,args:[{}]}],q.ctorParameters=function(){return[]},t.NgxsModule=q,t.Action=function(l,y){return function(t,r,e){var n,o,a,i=d(t.constructor);Array.isArray(l)||(l=[l]);try{for(var u=E(l),c=u.next();!c.done;c=u.next()){var s=c.value,f=(n=s).type?n.type:n.name?n.name:void 0;i.actions[f]||(i.actions[f]=[]),i.actions[f].push({fn:r,options:y||{},type:f})}}catch(p){o={error:p}}finally{try{c&&!c.done&&(a=u["return"])&&a.call(u)}finally{if(o)throw o.error}}}},t.Store=k,t.State=function(n){return function(t){var r=d(t);if(t.__proto__.hasOwnProperty(S)){var e=t.__proto__[S];r.actions=Object.assign({},r.actions,e.actions)}if(r.children=n.children,r.defaults=n.defaults,r.name=n.name,!n.name)throw new Error("States must register a 'name' property")}},t.Select=function(n){for(var o=[],t=1;t<arguments.length;t++)o[t-1]=arguments[t];return function(t,r){var e="__"+r+"__selector";if(n||(n=r.lastIndexOf("$")===r.length-1?r.substring(0,r.length-1):r),t[e])throw new Error("You cannot use @Select decorator and a "+e+" property.");delete t[r]&&(Object.defineProperty(t,e,{writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(t,r,{get:function(){return this[e]||(this[e]=function(t){var r=T.store;if(!r)throw new Error("SelectFactory not connected to store!");return r.select(t)}.apply(this,["string"==typeof n?p(o.length?_([n],o):n.split(".")):n[S]&&n[S].path?p(n[S].path.split(".")):n]))},enumerable:!0,configurable:!0}))}},t.Actions=v,t.ofAction=I,t.Selector=function(){for(var i=[],t=0;t<arguments.length;t++)i[t]=arguments[t];return function(t,r,e){var n=d(t);if(null!==e.value){var o=e.value,a=function(t){var r=y(t,n.path);try{return o(r)}catch(e){if(e instanceof TypeError)return undefined;throw e}};return{configurable:!0,get:function(){return function(a,i){var u=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var e=i?i.apply(this,t):t[0],n=u.cache;if(n.has(e))return n.get(e);var o=a.apply(this,t);return u.cache=n.set(e,o)||n,o};return u.cache=new WeakMap,u}.apply(null,_([a],i))}}}throw new Error("Selectors only work on methods")}},t.getActionTypeFromInstance=P,t.NGXS_PLUGINS=f,t.StateStream=g,t.setValue=l,t.getValue=y,t.InitState=R,t.UpdateState=M,t.ɵb=V,t.ɵa=N,t.ɵg=m,t.ɵc=T,t.ɵf=h,t.ɵe=s,t.ɵd=c,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngxs-store.umd.min.js.map
import { InjectionToken, Injector, Injectable, SkipSelf, Optional, Inject, ErrorHandler, NgModule } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { filter, shareReplay, takeUntil, map, distinctUntilChanged, catchError, take } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import { distinctUntilChanged, catchError, take, shareReplay, filter } from 'rxjs/operators';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { map } from 'rxjs/operators/map';
import { fromPromise } from 'rxjs/observable/fromPromise';
import { of } from 'rxjs/observable/of';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { Subject } from 'rxjs/Subject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { map as map$1 } from 'rxjs/operators/map';

@@ -18,4 +18,6 @@ /**

const META_KEY = 'NGXS_META';
const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
/**
* @record
* @template T
*/

@@ -25,3 +27,2 @@

* @record
* @template T
*/

@@ -31,8 +32,7 @@

* @record
* @template T
*/
const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
/**
* @record
* @template T
*/

@@ -308,2 +308,21 @@

*/
/**
* RxJS operator for selecting out specific actions.
* @param {...?} allowedTypes
* @return {?}
*/
function ofAction(...allowedTypes) {
const /** @type {?} */ allowedMap = {};
allowedTypes.forEach(klass => {
allowedMap[klass.type || klass.name] = true;
});
return filter(action => {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
class StateFactory {

@@ -375,7 +394,11 @@ /**

/**
* @param {?} stores
* @param {?} stateKlasses
* @return {?}
*/
addAndReturnDefaults(stores) {
return this.add(stores).reduce((result, meta) => setValue(result, meta.depth, meta.defaults), {});
addAndReturnDefaults(stateKlasses) {
if (stateKlasses) {
const /** @type {?} */ states = this.add(stateKlasses);
const /** @type {?} */ defaults = states.reduce((result, meta) => setValue(result, meta.depth, meta.defaults), {});
return { defaults, states };
}
}

@@ -386,6 +409,22 @@ /**

* @param {?} dispatch
* @param {?} stateMetadatas
* @return {?}
*/
invokeInit(getState, setState, dispatch, stateMetadatas) {
for (const /** @type {?} */ metadata of stateMetadatas) {
if (metadata.instance.onInit) {
const /** @type {?} */ stateContext = this.createStateContext(getState, setState, dispatch, metadata);
metadata.instance.onInit(stateContext);
}
}
}
/**
* @param {?} getState
* @param {?} setState
* @param {?} dispatch
* @param {?} actions$
* @param {?} action
* @return {?}
*/
invokeActions(getState, setState, dispatch, action) {
invokeActions(getState, setState, dispatch, actions$, action) {
const /** @type {?} */ results = [];

@@ -397,54 +436,73 @@ for (const /** @type {?} */ metadata of this.states) {

for (const /** @type {?} */ actionMeta of actionMetas) {
const /** @type {?} */ stateContext = {
/**
* @return {?}
*/
getState() {
const /** @type {?} */ state = getState();
return getValue(state, metadata.depth);
},
/**
* @param {?} val
* @return {?}
*/
patchState(val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
let /** @type {?} */ state = getState();
const /** @type {?} */ local = getValue(state, metadata.depth);
for (const /** @type {?} */ k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
/**
* @param {?} val
* @return {?}
*/
setState(val) {
let /** @type {?} */ state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
/**
* @param {?} actions
* @return {?}
*/
dispatch(actions) {
return dispatch(actions);
}
};
const /** @type {?} */ result = metadata.instance[actionMeta.fn](stateContext, action);
if (result) {
results.push(result);
const /** @type {?} */ stateContext = this.createStateContext(getState, setState, dispatch, metadata);
let /** @type {?} */ result = metadata.instance[actionMeta.fn](stateContext, action);
if (result === undefined) {
result = of({}).pipe(shareReplay());
}
else if (result instanceof Promise) {
result = fromPromise(result);
}
if (result instanceof Observable) {
result = result.pipe((/** @type {?} */ (actionMeta.options)).takeLast
? takeUntil(actions$.pipe(ofAction(action.constructor)))
: map(r => r)); // act like a noop
}
results.push(result);
}
}
}
return results;
return forkJoin(results);
}
/**
* @param {?} getState
* @param {?} setState
* @param {?} dispatch
* @param {?} metadata
* @return {?}
*/
createStateContext(getState, setState, dispatch, metadata) {
return {
/**
* @return {?}
*/
getState() {
const /** @type {?} */ state = getState();
return getValue(state, metadata.depth);
},
/**
* @param {?} val
* @return {?}
*/
patchState(val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
let /** @type {?} */ state = getState();
const /** @type {?} */ local = getValue(state, metadata.depth);
for (const /** @type {?} */ k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
/**
* @param {?} val
* @return {?}
*/
setState(val) {
let /** @type {?} */ state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
/**
* @param {?} actions
* @return {?}
*/
dispatch(actions) {
return dispatch(actions);
}
};
}
}

@@ -633,5 +691,5 @@ StateFactory.decorators = [

const /** @type {?} */ getter = fastPropGetter(selector[META_KEY].path.split('.'));
return this._stateStream.pipe(map(getter), distinctUntilChanged());
return this._stateStream.pipe(map$1(getter), distinctUntilChanged());
}
return this._stateStream.pipe(map(selector), catchError(err => {
return this._stateStream.pipe(map$1(selector), catchError(err => {
// if error is TypeError we swallow it to prevent usual errors with property access

@@ -653,2 +711,11 @@ if (err instanceof TypeError) {

/**
* Select a snapshot from the state.
* @template T
* @param {?} selector
* @return {?}
*/
selectSnapshot(selector) {
return selector(this._stateStream.getValue());
}
/**
* Allow the user to subscribe to the root of the state

@@ -675,30 +742,8 @@ * @param {?=} fn

this._actions.next(nextAction);
return this._dispatchActions(nextAction).pipe(map(() => this._stateStream.getValue()));
return this._storeFactory
.invokeActions(() => this._stateStream.getValue(), newState => this._stateStream.next(newState), actions => this.dispatch(actions), this._actions, action)
.pipe(map$1(() => this._stateStream.getValue()));
}
])(prevState, action))).pipe(shareReplay());
}
/**
* @param {?} action
* @return {?}
*/
_dispatchActions(action) {
const /** @type {?} */ results = this._storeFactory.invokeActions(() => this._stateStream.getValue(), newState => this._stateStream.next(newState), actions => this.dispatch(actions), action);
return (results.length ? forkJoin(this._handleNesting(results)) : of({})).pipe(shareReplay());
}
/**
* @param {?} eventResults
* @return {?}
*/
_handleNesting(eventResults) {
const /** @type {?} */ results = [];
for (let /** @type {?} */ eventResult of eventResults) {
if (eventResult instanceof Promise) {
eventResult = fromPromise(eventResult);
}
if (eventResult instanceof Observable) {
results.push(eventResult);
}
}
return results;
}
}

@@ -806,4 +851,4 @@ Store.decorators = [

/**
* @param {?} _factory
* @param {?} _stateStream
* @param {?} factory
* @param {?} stateStream
* @param {?} store

@@ -813,21 +858,15 @@ * @param {?} select

*/
constructor(_factory, _stateStream, store, select, states) {
this._factory = _factory;
this._stateStream = _stateStream;
this.initStates(states);
store.dispatch(new InitState());
}
/**
* @param {?} states
* @return {?}
*/
initStates(states) {
if (states) {
// add stores to the state graph and return their defaults
const /** @type {?} */ init = this._factory.addAndReturnDefaults(states);
constructor(factory, stateStream, store, select, states) {
// add stores to the state graph and return their defaults
const /** @type {?} */ results = factory.addAndReturnDefaults(states);
if (results) {
// get our current stream
const /** @type {?} */ cur = this._stateStream.getValue();
const /** @type {?} */ cur = stateStream.getValue();
// set the state to the current + new
this._stateStream.next(Object.assign({}, cur, init));
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new InitState());
if (results) {
factory.invokeInit(() => stateStream.getValue(), newState => stateStream.next(newState), actions => store.dispatch(actions), results.states);
}
}

@@ -848,30 +887,23 @@ }

/**
* @param {?} root
* @param {?} store
* @param {?} _stateStream
* @param {?} _factory
* @param {?} stateStream
* @param {?} factory
* @param {?} states
*/
constructor(root, store, _stateStream, _factory, states) {
this._stateStream = _stateStream;
this._factory = _factory;
// since FEATURE_STATE_TOKEN is a multi token, we need to
constructor(store, stateStream, factory, states) {
// Since FEATURE_STATE_TOKEN is a multi token, we need to
// flatten it [[Feature1State, Feature2State], [Feature3State]]
const /** @type {?} */ flattenedStates = (/** @type {?} */ ([])).concat(...states);
this.initStates(flattenedStates);
store.dispatch(new UpdateState());
}
/**
* @param {?} stores
* @return {?}
*/
initStates(stores) {
if (stores) {
// bind the stores
const /** @type {?} */ init = this._factory.addAndReturnDefaults(stores);
// add stores to the state graph and return their defaults
const /** @type {?} */ results = factory.addAndReturnDefaults(flattenedStates);
if (results) {
// get our current stream
const /** @type {?} */ cur = this._stateStream.getValue();
const /** @type {?} */ cur = stateStream.getValue();
// set the state to the current + new
this._stateStream.next(Object.assign({}, cur, init));
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new UpdateState());
if (results) {
factory.invokeInit(() => stateStream.getValue(), newState => stateStream.next(newState), actions => store.dispatch(actions), results.states);
}
}

@@ -884,3 +916,2 @@ }

NgxsFeatureModule.ctorParameters = () => [
{ type: NgxsRootModule, },
{ type: Store, },

@@ -947,5 +978,6 @@ { type: StateStream, },

* @param {?} actions
* @param {?=} options
* @return {?}
*/
function Action(actions) {
function Action(actions, options) {
return function (target, name, descriptor) {

@@ -963,2 +995,3 @@ const /** @type {?} */ meta = ensureStoreMetadata(target.constructor);

fn: name,
options: options || {},
type

@@ -1002,19 +1035,2 @@ });

/**
* RxJS operator for selecting out specific actions.
* @param {...?} allowedTypes
* @return {?}
*/
function ofAction(...allowedTypes) {
const /** @type {?} */ allowedMap = {};
allowedTypes.forEach(klass => (allowedMap[klass.type || klass.name] = true));
return filter(action => {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Memoize a function.

@@ -1021,0 +1037,0 @@ * Oringinally from: https://github.com/lodash/lodash/blob/master/memoize.js with some modifications

import { __spread, __values, __extends } from 'tslib';
import { InjectionToken, Injector, Injectable, SkipSelf, Optional, Inject, ErrorHandler, NgModule } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { filter, shareReplay, takeUntil, map, distinctUntilChanged, catchError, take } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import { distinctUntilChanged, catchError, take, shareReplay, filter } from 'rxjs/operators';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { map } from 'rxjs/operators/map';
import { fromPromise } from 'rxjs/observable/fromPromise';
import { of } from 'rxjs/observable/of';
import { forkJoin } from 'rxjs/observable/forkJoin';
import { Subject } from 'rxjs/Subject';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { map as map$1 } from 'rxjs/operators/map';

@@ -154,2 +154,15 @@ var ROOT_STATE_TOKEN = new InjectionToken('ROOT_STATE_TOKEN');

var getValue = function (obj, prop) { return prop.split('.').reduce(function (acc, part) { return acc && acc[part]; }, obj); };
function ofAction() {
var allowedTypes = [];
for (var _i = 0; _i < arguments.length; _i++) {
allowedTypes[_i] = arguments[_i];
}
var allowedMap = {};
allowedTypes.forEach(function (klass) {
allowedMap[klass.type || klass.name] = true;
});
return filter(function (action) {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
var StateFactory = /** @class */ (function () {

@@ -226,74 +239,105 @@ function StateFactory(_injector, _parentFactory) {

};
StateFactory.prototype.addAndReturnDefaults = function (stores) {
return this.add(stores).reduce(function (result, meta) { return setValue(result, meta.depth, meta.defaults); }, {});
StateFactory.prototype.addAndReturnDefaults = function (stateKlasses) {
if (stateKlasses) {
var states = this.add(stateKlasses);
var defaults = states.reduce(function (result, meta) { return setValue(result, meta.depth, meta.defaults); }, {});
return { defaults: defaults, states: states };
}
};
StateFactory.prototype.invokeActions = function (getState, setState, dispatch, action) {
StateFactory.prototype.invokeInit = function (getState, setState, dispatch, stateMetadatas) {
try {
for (var stateMetadatas_1 = __values(stateMetadatas), stateMetadatas_1_1 = stateMetadatas_1.next(); !stateMetadatas_1_1.done; stateMetadatas_1_1 = stateMetadatas_1.next()) {
var metadata = stateMetadatas_1_1.value;
if (metadata.instance.onInit) {
var stateContext = this.createStateContext(getState, setState, dispatch, metadata);
metadata.instance.onInit(stateContext);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (stateMetadatas_1_1 && !stateMetadatas_1_1.done && (_a = stateMetadatas_1.return)) _a.call(stateMetadatas_1);
}
finally { if (e_2) throw e_2.error; }
}
var e_2, _a;
};
StateFactory.prototype.invokeActions = function (getState, setState, dispatch, actions$, action) {
var results = [];
var _loop_2 = function (metadata) {
var name = getActionTypeFromInstance(action);
var actionMetas = metadata.actions[name];
if (actionMetas) {
try {
for (var actionMetas_1 = __values(actionMetas), actionMetas_1_1 = actionMetas_1.next(); !actionMetas_1_1.done; actionMetas_1_1 = actionMetas_1.next()) {
var actionMeta = actionMetas_1_1.value;
var stateContext = {
getState: function () {
var state = getState();
return getValue(state, metadata.depth);
},
patchState: function (val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
var state = getState();
var local = getValue(state, metadata.depth);
for (var k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
setState: function (val) {
var state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
dispatch: function (actions) {
return dispatch(actions);
try {
for (var _a = __values(this.states), _b = _a.next(); !_b.done; _b = _a.next()) {
var metadata = _b.value;
var name = getActionTypeFromInstance(action);
var actionMetas = metadata.actions[name];
if (actionMetas) {
try {
for (var actionMetas_1 = __values(actionMetas), actionMetas_1_1 = actionMetas_1.next(); !actionMetas_1_1.done; actionMetas_1_1 = actionMetas_1.next()) {
var actionMeta = actionMetas_1_1.value;
var stateContext = this.createStateContext(getState, setState, dispatch, metadata);
var result = metadata.instance[actionMeta.fn](stateContext, action);
if (result === undefined) {
result = of({}).pipe(shareReplay());
}
};
var result = metadata.instance[actionMeta.fn](stateContext, action);
if (result) {
else if (result instanceof Promise) {
result = fromPromise(result);
}
if (result instanceof Observable) {
result = result.pipe(((actionMeta.options)).takeLast
? takeUntil(actions$.pipe(ofAction(action.constructor)))
: map(function (r) { return r; }));
}
results.push(result);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (actionMetas_1_1 && !actionMetas_1_1.done && (_a = actionMetas_1.return)) _a.call(actionMetas_1);
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (actionMetas_1_1 && !actionMetas_1_1.done && (_c = actionMetas_1.return)) _c.call(actionMetas_1);
}
finally { if (e_3) throw e_3.error; }
}
finally { if (e_2) throw e_2.error; }
}
}
var e_2, _a;
};
try {
for (var _a = __values(this.states), _b = _a.next(); !_b.done; _b = _a.next()) {
var metadata = _b.value;
_loop_2(metadata);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
}
finally { if (e_3) throw e_3.error; }
finally { if (e_4) throw e_4.error; }
}
return results;
var e_3, _c;
return forkJoin(results);
var e_4, _d, e_3, _c;
};
StateFactory.prototype.createStateContext = function (getState, setState, dispatch, metadata) {
return {
getState: function () {
var state = getState();
return getValue(state, metadata.depth);
},
patchState: function (val) {
if (Array.isArray(val)) {
throw new Error('Patching arrays is not supported.');
}
var state = getState();
var local = getValue(state, metadata.depth);
for (var k in val) {
local[k] = val[k];
}
state = setValue(state, metadata.depth, Object.assign({}, local));
setState(state);
return state;
},
setState: function (val) {
var state = getState();
state = setValue(state, metadata.depth, val);
setState(state);
return state;
},
dispatch: function (actions) {
return dispatch(actions);
}
};
};
return StateFactory;

@@ -416,5 +460,5 @@ }());

var getter = fastPropGetter(selector[META_KEY].path.split('.'));
return this._stateStream.pipe(map(getter), distinctUntilChanged());
return this._stateStream.pipe(map$1(getter), distinctUntilChanged());
}
return this._stateStream.pipe(map(selector), catchError(function (err) {
return this._stateStream.pipe(map$1(selector), catchError(function (err) {
if (err instanceof TypeError) {

@@ -429,2 +473,5 @@ return of(undefined);

};
Store.prototype.selectSnapshot = function (selector) {
return selector(this._stateStream.getValue());
};
Store.prototype.subscribe = function (fn) {

@@ -443,34 +490,8 @@ return this._stateStream.subscribe(fn);

_this._actions.next(nextAction);
return _this._dispatchActions(nextAction).pipe(map(function () { return _this._stateStream.getValue(); }));
return _this._storeFactory
.invokeActions(function () { return _this._stateStream.getValue(); }, function (newState) { return _this._stateStream.next(newState); }, function (actions) { return _this.dispatch(actions); }, _this._actions, action)
.pipe(map$1(function () { return _this._stateStream.getValue(); }));
}
]))(prevState, action))).pipe(shareReplay());
};
Store.prototype._dispatchActions = function (action) {
var _this = this;
var results = this._storeFactory.invokeActions(function () { return _this._stateStream.getValue(); }, function (newState) { return _this._stateStream.next(newState); }, function (actions) { return _this.dispatch(actions); }, action);
return (results.length ? forkJoin(this._handleNesting(results)) : of({})).pipe(shareReplay());
};
Store.prototype._handleNesting = function (eventResults) {
var results = [];
try {
for (var eventResults_1 = __values(eventResults), eventResults_1_1 = eventResults_1.next(); !eventResults_1_1.done; eventResults_1_1 = eventResults_1.next()) {
var eventResult = eventResults_1_1.value;
if (eventResult instanceof Promise) {
eventResult = fromPromise(eventResult);
}
if (eventResult instanceof Observable) {
results.push(eventResult);
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (eventResults_1_1 && !eventResults_1_1.done && (_a = eventResults_1.return)) _a.call(eventResults_1);
}
finally { if (e_4) throw e_4.error; }
}
return results;
var e_4, _a;
};
return Store;

@@ -562,15 +583,13 @@ }());

var NgxsRootModule = /** @class */ (function () {
function NgxsRootModule(_factory, _stateStream, store, select, states) {
this._factory = _factory;
this._stateStream = _stateStream;
this.initStates(states);
function NgxsRootModule(factory, stateStream, store, select, states) {
var results = factory.addAndReturnDefaults(states);
if (results) {
var cur = stateStream.getValue();
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new InitState());
if (results) {
factory.invokeInit(function () { return stateStream.getValue(); }, function (newState) { return stateStream.next(newState); }, function (actions) { return store.dispatch(actions); }, results.states);
}
}
NgxsRootModule.prototype.initStates = function (states) {
if (states) {
var init = this._factory.addAndReturnDefaults(states);
var cur = this._stateStream.getValue();
this._stateStream.next(Object.assign({}, cur, init));
}
};
return NgxsRootModule;

@@ -589,16 +608,14 @@ }());

var NgxsFeatureModule = /** @class */ (function () {
function NgxsFeatureModule(root, store, _stateStream, _factory, states) {
this._stateStream = _stateStream;
this._factory = _factory;
function NgxsFeatureModule(store, stateStream, factory, states) {
var flattenedStates = (([])).concat.apply((([])), __spread(states));
this.initStates(flattenedStates);
var results = factory.addAndReturnDefaults(flattenedStates);
if (results) {
var cur = stateStream.getValue();
stateStream.next(Object.assign({}, cur, results.defaults));
}
store.dispatch(new UpdateState());
if (results) {
factory.invokeInit(function () { return stateStream.getValue(); }, function (newState) { return stateStream.next(newState); }, function (actions) { return store.dispatch(actions); }, results.states);
}
}
NgxsFeatureModule.prototype.initStates = function (stores) {
if (stores) {
var init = this._factory.addAndReturnDefaults(stores);
var cur = this._stateStream.getValue();
this._stateStream.next(Object.assign({}, cur, init));
}
};
return NgxsFeatureModule;

@@ -610,3 +627,2 @@ }());

NgxsFeatureModule.ctorParameters = function () { return [
{ type: NgxsRootModule, },
{ type: Store, },

@@ -660,3 +676,3 @@ { type: StateStream, },

NgxsModule.ctorParameters = function () { return []; };
function Action(actions) {
function Action(actions, options) {
return function (target, name, descriptor) {

@@ -676,2 +692,3 @@ var meta = ensureStoreMetadata(target.constructor);

fn: name,
options: options || {},
type: type

@@ -706,13 +723,2 @@ });

}
function ofAction() {
var allowedTypes = [];
for (var _i = 0; _i < arguments.length; _i++) {
allowedTypes[_i] = arguments[_i];
}
var allowedMap = {};
allowedTypes.forEach(function (klass) { return (allowedMap[klass.type || klass.name] = true); });
return filter(function (action) {
return allowedMap[action.constructor.type || action.constructor.name];
});
}
function memoize(func, resolver) {

@@ -719,0 +725,0 @@ var memoized = function () {

@@ -1,1 +0,1 @@

{"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":11,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":18,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":19,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵd"}]}]],"parameters":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"ɵc"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"any"}]}]}],"initStates":[{"__symbolic":"method"}]}},"ɵb":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":40,"character":1},"arguments":[{}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":47,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":48,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵe"}]}]],"parameters":[{"__symbolic":"reference","name":"ɵa"},{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"any"}]}]}]}],"initStates":[{"__symbolic":"method"}]}},"ɵc":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Store"}]}]},"statics":{"store":{"__symbolic":"reference","name":"undefined"}}},"ɵd":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":3,"character":36},"arguments":["ROOT_STATE_TOKEN"]},"ɵe":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":4,"character":39},"arguments":["FEATURE_STATE_TOKEN"]},"NgxsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":72,"character":1},"arguments":[{}]}],"members":{},"statics":{"forRoot":{"__symbolic":"function","parameters":["states"],"defaults":[[]],"value":{"ngModule":{"__symbolic":"reference","name":"ɵa"},"providers":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"Actions"},{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"ɵc"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"spread","expression":{"__symbolic":"reference","name":"states"}},{"provide":{"__symbolic":"reference","name":"ɵd"},"useValue":{"__symbolic":"reference","name":"states"}}]}},"forFeature":{"__symbolic":"function","parameters":["states"],"value":{"ngModule":{"__symbolic":"reference","name":"ɵb"},"providers":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"spread","expression":{"__symbolic":"reference","name":"states"}},{"provide":{"__symbolic":"reference","name":"ɵe"},"multi":true,"useValue":{"__symbolic":"reference","name":"states"}}]}}}},"Action":{"__symbolic":"function","parameters":["actions"],"value":{"__symbolic":"error","message":"Lambda not supported","line":6,"character":9,"module":"./src/action"}},"Store":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":17,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ErrorHandler","line":20,"character":27},{"__symbolic":"reference","name":"Actions"},{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"reference","name":"StateStream"}]}],"dispatch":[{"__symbolic":"method"}],"select":[{"__symbolic":"method"},{"__symbolic":"method"},{"__symbolic":"method"}],"selectOnce":[{"__symbolic":"method"},{"__symbolic":"method"},{"__symbolic":"method"}],"subscribe":[{"__symbolic":"method"}],"_dispatch":[{"__symbolic":"method"}],"_dispatchActions":[{"__symbolic":"method"}],"_handleNesting":[{"__symbolic":"method"}]}},"State":{"__symbolic":"function","parameters":["options"],"value":{"__symbolic":"error","message":"Lambda not supported","line":7,"character":9,"module":"./src/state"}},"Select":{"__symbolic":"function","parameters":["selectorOrFeature","paths"],"value":{"__symbolic":"error","message":"Lambda not supported","line":18,"character":9,"module":"./src/select"}},"Actions":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"rxjs/Subject","name":"Subject","line":9,"character":29},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":8,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":11,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":12,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"Actions"}]}]}},"ofAction":{"__symbolic":"function"},"NgxsPlugin":{"__symbolic":"interface"},"NgxsPluginFn":{"__symbolic":"interface"},"StateContext":{"__symbolic":"interface"},"Selector":{"__symbolic":"function","parameters":["args"],"value":{"__symbolic":"error","message":"Lambda not supported","line":8,"character":9,"module":"./src/selector"}},"getActionTypeFromInstance":{"__symbolic":"function"},"NGXS_PLUGINS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":44,"character":32},"arguments":["NGXS_PLUGINS"]},"StateStream":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"rxjs/BehaviorSubject","name":"BehaviorSubject","line":7,"character":33},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":9,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":10,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"StateStream"}]}]}},"setValue":{"__symbolic":"error","message":"Lambda not supported","line":22,"character":24,"module":"./src/utils"},"getValue":{"__symbolic":"error","message":"Lambda not supported","line":47,"character":24,"module":"./src/utils"},"InitState":{"__symbolic":"class","members":{},"statics":{"type":"@@INIT"}},"UpdateState":{"__symbolic":"class","members":{},"statics":{"type":"@@UPDATE_STATE"}},"ɵf":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":19,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":28,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":29,"character":5}}]],"parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":27,"character":23},{"__symbolic":"reference","name":"ɵf"}]}],"add":[{"__symbolic":"method"}],"addAndReturnDefaults":[{"__symbolic":"method"}],"invokeActions":[{"__symbolic":"method"}]}},"ɵg":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":3,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":8,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":9,"character":5}}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":11,"character":5},"arguments":[{"__symbolic":"reference","name":"NGXS_PLUGINS"}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":12,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"NgxsPlugin"}]}]}],"register":[{"__symbolic":"method"}]}}},"origins":{"ɵa":"./src/module","ɵb":"./src/module","ɵc":"./src/select","ɵd":"./src/symbols","ɵe":"./src/symbols","NgxsModule":"./src/module","Action":"./src/action","Store":"./src/store","State":"./src/state","Select":"./src/select","Actions":"./src/actions-stream","ofAction":"./src/of-action","NgxsPlugin":"./src/symbols","NgxsPluginFn":"./src/symbols","StateContext":"./src/symbols","Selector":"./src/selector","getActionTypeFromInstance":"./src/utils","NGXS_PLUGINS":"./src/symbols","StateStream":"./src/state-stream","setValue":"./src/utils","getValue":"./src/utils","InitState":"./src/actions","UpdateState":"./src/actions","ɵf":"./src/state-factory","ɵg":"./src/plugin-manager"},"importAs":"@ngxs/store"}
{"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":11,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":18,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":19,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵd"}]}]],"parameters":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"ɵc"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"any"}]}]}]}},"ɵb":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":45,"character":1},"arguments":[{}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":51,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":52,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵe"}]}]],"parameters":[{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"any"}]}]}]}]}},"ɵc":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","name":"Store"}]}]},"statics":{"store":{"__symbolic":"reference","name":"undefined"}}},"ɵd":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":3,"character":36},"arguments":["ROOT_STATE_TOKEN"]},"ɵe":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":4,"character":39},"arguments":["FEATURE_STATE_TOKEN"]},"NgxsModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":82,"character":1},"arguments":[{}]}],"members":{},"statics":{"forRoot":{"__symbolic":"function","parameters":["states"],"defaults":[[]],"value":{"ngModule":{"__symbolic":"reference","name":"ɵa"},"providers":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"Actions"},{"__symbolic":"reference","name":"Store"},{"__symbolic":"reference","name":"StateStream"},{"__symbolic":"reference","name":"ɵc"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"spread","expression":{"__symbolic":"reference","name":"states"}},{"provide":{"__symbolic":"reference","name":"ɵd"},"useValue":{"__symbolic":"reference","name":"states"}}]}},"forFeature":{"__symbolic":"function","parameters":["states"],"value":{"ngModule":{"__symbolic":"reference","name":"ɵb"},"providers":[{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"spread","expression":{"__symbolic":"reference","name":"states"}},{"provide":{"__symbolic":"reference","name":"ɵe"},"multi":true,"useValue":{"__symbolic":"reference","name":"states"}}]}}}},"Action":{"__symbolic":"function","parameters":["actions","options"],"value":{"__symbolic":"error","message":"Lambda not supported","line":7,"character":9,"module":"./src/action"}},"Store":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":16,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ErrorHandler","line":19,"character":27},{"__symbolic":"reference","name":"Actions"},{"__symbolic":"reference","name":"ɵf"},{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"reference","name":"StateStream"}]}],"dispatch":[{"__symbolic":"method"}],"select":[{"__symbolic":"method"},{"__symbolic":"method"},{"__symbolic":"method"}],"selectOnce":[{"__symbolic":"method"},{"__symbolic":"method"},{"__symbolic":"method"}],"selectSnapshot":[{"__symbolic":"method"}],"subscribe":[{"__symbolic":"method"}],"_dispatch":[{"__symbolic":"method"}]}},"State":{"__symbolic":"function","parameters":["options"],"value":{"__symbolic":"error","message":"Lambda not supported","line":7,"character":9,"module":"./src/state"}},"Select":{"__symbolic":"function","parameters":["selectorOrFeature","paths"],"value":{"__symbolic":"error","message":"Lambda not supported","line":18,"character":9,"module":"./src/select"}},"Actions":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"rxjs/Subject","name":"Subject","line":9,"character":29},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":8,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":11,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":12,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"Actions"}]}]}},"ofAction":{"__symbolic":"function"},"NgxsPlugin":{"__symbolic":"interface"},"NgxsPluginFn":{"__symbolic":"interface"},"StateContext":{"__symbolic":"interface"},"Selector":{"__symbolic":"function","parameters":["args"],"value":{"__symbolic":"error","message":"Lambda not supported","line":8,"character":9,"module":"./src/selector"}},"getActionTypeFromInstance":{"__symbolic":"function"},"NGXS_PLUGINS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":7,"character":32},"arguments":["NGXS_PLUGINS"]},"StateStream":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"rxjs/BehaviorSubject","name":"BehaviorSubject","line":7,"character":33},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":6,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":9,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":10,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"StateStream"}]}]}},"setValue":{"__symbolic":"error","message":"Lambda not supported","line":22,"character":24,"module":"./src/utils"},"getValue":{"__symbolic":"error","message":"Lambda not supported","line":47,"character":24,"module":"./src/utils"},"InitState":{"__symbolic":"class","members":{},"statics":{"type":"@@INIT"}},"UpdateState":{"__symbolic":"class","members":{},"statics":{"type":"@@UPDATE_STATE"}},"ɵf":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":12,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":22,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":23,"character":5}}]],"parameters":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":21,"character":23},{"__symbolic":"reference","name":"ɵf"}]}],"add":[{"__symbolic":"method"}],"addAndReturnDefaults":[{"__symbolic":"method"}],"invokeInit":[{"__symbolic":"method"}],"invokeActions":[{"__symbolic":"method"}],"createStateContext":[{"__symbolic":"method"}]}},"ɵg":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":3,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":8,"character":5}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":9,"character":5}}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":11,"character":5},"arguments":[{"__symbolic":"reference","name":"NGXS_PLUGINS"}]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":12,"character":5}}]],"parameters":[{"__symbolic":"reference","name":"ɵg"},{"__symbolic":"reference","name":"Array","arguments":[{"__symbolic":"reference","name":"NgxsPlugin"}]}]}],"register":[{"__symbolic":"method"}]}}},"origins":{"ɵa":"./src/module","ɵb":"./src/module","ɵc":"./src/select","ɵd":"./src/symbols","ɵe":"./src/symbols","NgxsModule":"./src/module","Action":"./src/action","Store":"./src/store","State":"./src/state","Select":"./src/select","Actions":"./src/actions-stream","ofAction":"./src/of-action","NgxsPlugin":"./src/symbols","NgxsPluginFn":"./src/symbols","StateContext":"./src/symbols","Selector":"./src/selector","getActionTypeFromInstance":"./src/utils","NGXS_PLUGINS":"./src/symbols","StateStream":"./src/state-stream","setValue":"./src/utils","getValue":"./src/utils","InitState":"./src/actions","UpdateState":"./src/actions","ɵf":"./src/state-factory","ɵg":"./src/plugin-manager"},"importAs":"@ngxs/store"}
{
"name": "@ngxs/store",
"version": "2.0.0",
"version": "2.1.0-beta.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "peerDependencies": {

@@ -0,4 +1,5 @@

import { ActionOptions } from './symbols';
/**
* Decorates a method with a action information.
*/
export declare function Action(actions: any | any[]): (target: any, name: string, descriptor: TypedPropertyDescriptor<any>) => void;
export declare function Action(actions: any | any[], options?: ActionOptions): (target: any, name: string, descriptor: TypedPropertyDescriptor<any>) => void;

@@ -7,12 +7,6 @@ import { ModuleWithProviders } from '@angular/core';

export declare class NgxsRootModule {
private _factory;
private _stateStream;
constructor(_factory: StateFactory, _stateStream: StateStream, store: Store, select: SelectFactory, states: any[]);
initStates(states: any): void;
constructor(factory: StateFactory, stateStream: StateStream, store: Store, select: SelectFactory, states: any[]);
}
export declare class NgxsFeatureModule {
private _stateStream;
private _factory;
constructor(root: NgxsRootModule, store: Store, _stateStream: StateStream, _factory: StateFactory, states: any[][]);
initStates(stores: any): void;
constructor(store: Store, stateStream: StateStream, factory: StateFactory, states: any[][]);
}

@@ -19,0 +13,0 @@ export declare class NgxsModule {

import { Injector } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { StateContext } from './symbols';
export declare class StateFactory {

@@ -9,4 +11,9 @@ private _injector;

add(states: any | any[]): any[];
addAndReturnDefaults(stores: any[]): any;
invokeActions(getState: any, setState: any, dispatch: any, action: any): any[];
addAndReturnDefaults(stateKlasses: any[]): {
defaults: any;
states: any[];
};
invokeInit(getState: any, setState: any, dispatch: any, stateMetadatas: any): void;
invokeActions(getState: any, setState: any, dispatch: any, actions$: any, action: any): Observable<{}[]>;
createStateContext(getState: any, setState: any, dispatch: any, metadata: any): StateContext<any>;
}

@@ -30,2 +30,6 @@ import { ErrorHandler } from '@angular/core';

/**
* Select a snapshot from the state.
*/
selectSnapshot<T>(selector: (state: any) => T): any;
/**
* Allow the user to subscribe to the root of the state

@@ -35,4 +39,2 @@ */

private _dispatch(action);
private _dispatchActions(action);
private _handleNesting(eventResults);
}

@@ -6,6 +6,5 @@ import { InjectionToken } from '@angular/core';

export declare const META_KEY = "NGXS_META";
export declare const NGXS_PLUGINS: InjectionToken<{}>;
export declare type NgxsPluginConstructor = new (...args: any[]) => NgxsPlugin;
export interface NgxsOptions {
plugins: Array<NgxsPluginConstructor | NgxsPluginFn>;
}
export declare type NgxsPluginFn = (state: any, mutation: any, next: NgxsNextPluginFn) => any;
export interface StateContext<T> {

@@ -36,4 +35,2 @@ /**

}
export declare const NGXS_PLUGINS: InjectionToken<{}>;
export declare type NgxsPluginFn = (state: any, mutation: any, next: NgxsNextPluginFn) => any;
export interface StoreOptions<T> {

@@ -53,1 +50,7 @@ /**

}
export interface ActionOptions {
/**
* Cancel the previous uncompleted request(s).
*/
takeLast: boolean;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc