@angular-redux/store
Version:
Angular bindings for Redux
2 lines • 7.26 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("redux"),require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@angular-redux/store",["exports","redux","@angular/core","rxjs","rxjs/operators"],t):t((e["angular-redux"]=e["angular-redux"]||{},e["angular-redux"].store={}),e.redux,e.ng.core,e.rxjs,e.rxjs.operators)}(this,function(e,u,i,a,s){"use strict";var c=function(){function e(){}return e.instance=undefined,e}(),n="undefined"!=typeof window?window:{},t=function(){function e(e,t){var r=this;this.appRef=e,this.ngRedux=t,this.enhancer=function(e){var n;return r.isEnabled()?(r.getDevTools().listen(function(e){var t=e.type;"START"===t?n=r.ngRedux.subscribe(function(){i.NgZone.isInAngularZone()||r.appRef.tick()}):"STOP"===t&&n()}),r.getDevTools()(e||{})):null},this.isEnabled=function(){return!!r.getDevTools()},this.getDevTools=function(){return n&&(n.__REDUX_DEVTOOLS_EXTENSION__||n.devToolsExtension)}}return e.decorators=[{type:i.Injectable}],e.ctorParameters=function(){return[{type:i.ApplicationRef},{type:c}]},e}(),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var f=function(){return(f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,u=n.call(e),i=[];try{for(;(void 0===t||0<t--)&&!(r=u.next()).done;)i.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(n=u["return"])&&n.call(u)}finally{if(o)throw o.error}}return i}function d(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));return e}function p(e,t){if(!e)return e;if("function"==typeof e.getIn)return e.getIn(t);var n=l(t),r=n[0],o=n.slice(1);return undefined===e[r]?undefined:0===o.length?e[r]:p(e[r],o)}var g=function(e,t,n){var r,o,u=l(t),i=u[0],a=u.slice(1);return"function"==typeof(e[i]||{}).setIn?f({},e,((r={})[i]=e[i].setIn(a,n),r)):f({},e,((o={})[i]=0===a.length?n:g(e[i]||{},a,n),o))},h={},r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return function(e,n){return t.reduce(function(e,t){return t(e,n)},e)}};function b(e){return h={},r(v,e)}function v(e,t){void 0===e&&(e={});var n=t["@angular-redux::fractalkey"],r=n?JSON.parse(n):[],o=h[n||""];return n&&o?g(e,r,o(p(e,r),t)):e}var y="@angular-redux::substore::class::options",S="@angular-redux::substore::instance::store",x="@angular-redux::substore::instance::selections",O="@angular-redux::substore::instance::basepath",w=function(e){return e[S]},P=function(e){if(!c.instance)return undefined;var t=e.constructor[y];if(!t)return c.instance;var n,r,o,u,i,a=e[t.basePathMethodName]();return o=a,e[O]!==(o||[]).toString()&&((r=e)[x]=null,r[S]=null,r[O]=null,n=a,e[O]=(n||[]).toString()),a?(w(e)||(u=e,i=c.instance.configureSubStore(a,t.localReducer),u[S]=i),w(e)):c.instance},m=function(t,e,n,r,o){var u,i,a=P(t);if(a){var c=(i=(u=t)[x]||{},u[x]=i);return c[e]=c[e]||(r?a.select(n).pipe(function(e){return r(e,t)},s.distinctUntilChanged(o)):a.select(n,o)),c[e]}return undefined};function j(r,o,u){return function(e,t){delete e[t]&&Object.defineProperty(e,t,{get:function n(){return m(this,t,r,o,u)},enumerable:!0,configurable:!0})}}var R=function(e,t){if(!e)throw new Error(t)},N=function(e){return(n=e,{property:function(e){return e?e[n]:undefined},path:function(e){return p(e,n)},"function":n,nil:function(e){return e}})[(t=e,t?Array.isArray(t)?"path":"function"==typeof t?"function":"property":"nil")];var t,n},_=function I(e,t,n){var r=this;this.rootStore=e,this.basePath=t,this.dispatch=function(e){return r.rootStore.dispatch(f({},e,{"@angular-redux::fractalkey":JSON.stringify(r.basePath)}))},this.getState=function(){return p(r.rootStore.getState(),r.basePath)},this.configureSubStore=function(e,t){return new I(r.rootStore,d(r.basePath,e),t)},this.select=function(e,t){return r.rootStore.select(r.basePath).pipe(s.map(N(e)),s.distinctUntilChanged(t))},this.subscribe=function(e){var t=r.select().subscribe(e);return function(){return t.unsubscribe()}},this.replaceReducer=function(e){return function n(e,t){h[JSON.stringify(e)]=t}(r.basePath,e)},function o(e,t){var n=h[JSON.stringify(e)];if(n&&n!==t)throw new Error("attempt to overwrite fractal reducer for basePath "+e);h[JSON.stringify(e)]=t}(t,n)},T=function(t){function e(e){var o=t.call(this)||this;return o.ngZone=e,o.store=undefined,o.configureStore=function(e,t,n,r){void 0===n&&(n=[]),void 0===r&&(r=[]),R(!o.store,"Store already configured!"),o.setStore(u.compose.apply(void 0,d([u.applyMiddleware.apply(void 0,d(n))],r))(u.createStore)(b(e),t))},o.provideStore=function(e){R(!o.store,"Store already configured!"),o.setStore(e)},o.getState=function(){return o.store.getState()},o.subscribe=function(e){return o.store.subscribe(e)},o.replaceReducer=function(e){o.store.replaceReducer(e)},o.dispatch=function(e){return R(!!o.store,"Dispatch failed: did you forget to configure your store? https://github.com/angular-redux/platform/blob/master/packages/store/README.md#quick-start"),i.NgZone.isInAngularZone()?o.store.dispatch(e):o.ngZone.run(function(){return o.store.dispatch(e)})},o.select=function(e,t){return o.store$.pipe(s.distinctUntilChanged(),s.map(N(e)),s.distinctUntilChanged(t))},o.configureSubStore=function(e,t){return new _(o,e,t)},o.storeToObservable=function(n){return new a.Observable(function(e){e.next(n.getState());var t=n.subscribe(function(){return e.next(n.getState())});return function(){t(),e.complete()}})},(c.instance=o).store$=new a.BehaviorSubject(undefined).pipe(s.filter(function(e){return e!==undefined}),s.switchMap(function(e){return e})),o}return function r(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(e,t),e.prototype.setStore=function(e){this.store=e;var t=this.storeToObservable(e);this.store$.next(t)},e}(c);function E(e){return new T(e)}var D=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{providers:[t,{provide:c,useFactory:E,deps:[i.NgZone]}]}]}],e}();e.NgRedux=c,e.NgReduxModule=D,e.DevToolsExtension=t,e.enableFractalReducers=b,e.select=function M(n,r){return function(e,t){j(n||(String(t).lastIndexOf("$")===String(t).length-1?String(t).substring(0,String(t).length-1):t),undefined,r)(e,t)}},e.select$=function A(e,t,n){return j(e,t,n)},e.dispatch=function Z(){return function(e,t,n){var o,r=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=o.apply(this,e);if(n!==undefined){var r=P(this)||c.instance;r&&r.dispatch(n)}return n};if((n=n||Object.getOwnPropertyDescriptor(e,t))!==undefined)return o=n.value,n.value=r,n;var u={get:function(){return r},set:function(e){return o=e}};return Object.defineProperty(e,t,u),u}},e.WithSubStore=function k(e){var n=e.basePathMethodName,r=e.localReducer;return function(e){var t;t={basePathMethodName:n,localReducer:r},e[y]=t}},e.ɵb=T,e.ɵa=E,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=angular-redux-store.umd.min.js.map