UNPKG

ngrx-reducer-effects

Version:

Return side-effects as data from your NgRx reducers

17 lines (15 loc) 5.71 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core"),require("@ngrx/store"),require("rxjs")):"function"==typeof define&&define.amd?define("ngrx-reducer-effects",["exports","@angular/core","@ngrx/store","rxjs"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self)["ngrx-reducer-effects"]={},e.ng.core,e.store,e.rxjs)}(this,(function(e,r,t,n){"use strict";var o="StateWithEffects";var c="Unsubscribe"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var i=function(e,r){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(e,r)};Object.create;function u(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,c=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=c.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=c.return)&&t.call(c)}finally{if(o)throw o.error}}return i}function s(){for(var e=[],r=0;r<arguments.length;r++)e=e.concat(u(arguments[r]));return e}Object.create;var a=new Proxy({},{get:function(){return a}});function f(e){return void 0!==e.next}function d(e){return void 0!==e.error}function l(e){return void 0!==e.complete}function p(e){return void 0!==e.subscribe}function b(e){return void 0!==e.resolve}function v(e){return void 0!==e.reject}function y(e){return void 0!==e.unsubscribe}function g(e,r){return function(e){var r,t=o(e);for(var n in t)t=Object.assign(Object.assign({},t),((r={})[n]=o(t[n]),r));return t};function o(o){return"StateWithEffects"===(null==(c=o)?void 0:c.__brand)?(o.effects.forEach((function(o){return function(e,r,t,o){var c=e.operation(o.get.bind(o));if(function(e,r){return n.isObservable(r)}(0,c)){var i=Math.max.apply(Math,s(r.keys()))+1,u=c.subscribe({next:function(r){return e.next&&t.dispatch(e.next(r))},error:function(r){return e.error&&t.dispatch(e.error(r))},complete:function(){return e.complete&&t.dispatch(e.complete())}});r.set(i,u),e.subscribe&&t.dispatch(e.subscribe(i))}else!function(e,r){return r instanceof Promise}(0,c)?function(e,r){return"Unsubscribe"===r.__brand}(0,c)&&function(e,r,t,o){var c=t.get(e.subscriptionToken);c instanceof n.Subscription?(t.delete(e.subscriptionToken),c.unsubscribe()):c instanceof AbortController?(t.delete(e.subscriptionToken),c.abort()):console.warn("SubscriptionToken "+e.subscriptionToken+" not recognized. Did you cancel this already?");r.unsubscribe&&o.dispatch(r.unsubscribe(0))}(c,e,r,t):c.then((function(r){return e.resolve&&t.dispatch(e.resolve(r))}),(function(r){return e.reject&&t.dispatch(e.reject(r))}))}(o,r,e.get(t.Store),e)})),function(e,r){var t=r.map((function(e){return{type:e.type,params:e.params,nextAction:f(e)?e.next(a).type:void 0,errorAction:d(e)?e.error(a).type:void 0,completeAction:l(e)?e.complete().type:void 0,subscribeAction:p(e)?e.subscribe(0).type:void 0,resolveAction:b(e)?e.resolve(a).type:void 0,rejectAction:v(e)?e.reject(a).type:void 0,unsubscribeAction:y(e)?e.unsubscribe(0).type:void 0}}));return Object.assign(e,{__effects__:t})}(o.state,o.effects)):o;var c}}function h(e,r,o){var c=new Map;return c.set(31415,new n.Subscription),Array.isArray(o)&&o.length>0&&(e=t.compose.apply(null,s(o,[e]))),function(t,n){var o=e(t);return function(e,t){return e=void 0===e?n:e,g(r,c)(o(e,t))}}}var _=new r.InjectionToken("ngrx-reducer-effects Internal Reducer Factory Provider"),j=new r.InjectionToken("ngrx-reducer-effects Internal Resolved Meta Reducers"),m=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function t(){this.constructor=e}i(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}(n,e),n.forRoot=function(e,n){var o;void 0===n&&(n={});var c=t.StoreModule.forRoot(e,Object.assign(Object.assign({},n),{runtimeChecks:Object.assign(Object.assign({},n.runtimeChecks),{strictStateImmutability:!1})}));return{ngModule:c.ngModule,providers:s(null!==(o=c.providers)&&void 0!==o?o:[],[{provide:j,deps:[t.META_REDUCERS,t.USER_PROVIDED_META_REDUCERS],useFactory:x},{provide:_,useValue:n.reducerFactory?n.reducerFactory:t.combineReducers},{provide:t.REDUCER_FACTORY,deps:[_,r.Injector,j],useFactory:h}])}},n}(t.StoreModule);function x(e,r){return e.concat(r)}m.decorators=[{type:r.NgModule,args:[{}]}],e.EffectStoreModule=m,e.createReducerEffect=function(e){return function(r){return Object.assign("function"==typeof e?e(r):e,{params:r})}},e.unsubscribe=function(e){return{__brand:c,subscriptionToken:e}},e.withEffects=function(e){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];return{__brand:o,state:e,effects:r}},e.ɵa=c,e.ɵb=o,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngrx-reducer-effects.umd.min.js.map