UNPKG

7.25 kBJavaScriptView Raw
1/**
2 * @license NgRx 8.6.1
3 * (c) 2015-2018 Brandon Roberts, Mike Ryan, Rob Wormald, Victor Savkin
4 * License: MIT
5 */
6!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@ngrx/store"),require("tslib"),require("@angular/core"),require("@angular/router"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@ngrx/router-store",["exports","@ngrx/store","tslib","@angular/core","@angular/router","rxjs/operators"],e):e(((t=t||self).ngrx=t.ngrx||{},t.ngrx.routerStore={}),t.ngrx.store,t.tslib,t.ng.core,t.ng.router,t.rxjs.operators)}(this,function(t,e,r,o,i,n){"use strict";var a,u=e.createAction("@ngrx/router-store/request",e.props()),s="@ngrx/router-store/navigation",c=e.createAction(s,e.props()),l="@ngrx/router-store/cancel",p=e.createAction(l,e.props()),g="@ngrx/router-store/error",f=e.createAction(g,e.props()),h=e.createAction("@ngrx/router-store/navigated",e.props()),d=function d(){},R=function(){function t(){}return t.prototype.serialize=function(t){return{root:this.serializeRoute(t.root),url:t.url}},t.prototype.serializeRoute=function(t){var e=this,r=t.children.map(function(t){return e.serializeRoute(t)});return{params:t.params,paramMap:t.paramMap,data:t.data,url:t.url,outlet:t.outlet,routeConfig:t.routeConfig?{component:t.routeConfig.component,path:t.routeConfig.path,pathMatch:t.routeConfig.pathMatch,redirectTo:t.routeConfig.redirectTo,outlet:t.routeConfig.outlet}:null,queryParams:t.queryParams,queryParamMap:t.queryParamMap,fragment:t.fragment,component:t.routeConfig?t.routeConfig.component:void 0,root:void 0,parent:void 0,firstChild:r[0],pathFromRoot:void 0,children:r}},t}(),v=function(){function t(){}return t.prototype.serialize=function(t){return{root:this.serializeRoute(t.root),url:t.url}},t.prototype.serializeRoute=function(t){var e=this,r=t.children.map(function(t){return e.serializeRoute(t)});return{params:t.params,data:t.data,url:t.url,outlet:t.outlet,routeConfig:t.routeConfig?{path:t.routeConfig.path,pathMatch:t.routeConfig.pathMatch,redirectTo:t.routeConfig.redirectTo,outlet:t.routeConfig.outlet}:null,queryParams:t.queryParams,fragment:t.fragment,firstChild:r[0],children:r}},t}();(a=t.NavigationActionTiming||(t.NavigationActionTiming={}))[a.PreActivation=1]="PreActivation",a[a.PostActivation=2]="PostActivation";var S,m=new o.InjectionToken("@ngrx/router-store Internal Configuration"),E=new o.InjectionToken("@ngrx/router-store Configuration"),y="router";function A(e){return r.__assign({stateKey:y,serializer:R,navigationActionTiming:t.NavigationActionTiming.PreActivation},e)}!function(t){t[t.NONE=1]="NONE",t[t.ROUTER=2]="ROUTER",t[t.STORE=3]="STORE"}(S||(S={}));var N=function(){function a(t,e,r,o,i){this.store=t,this.router=e,this.serializer=r,this.errorHandler=o,this.config=i,this.lastEvent=null,this.trigger=S.NONE,this.stateKey=this.config.stateKey,this.setUpStoreStateListener(),this.setUpRouterEventsListener()}var u;return u=a,a.forRoot=function(t){return void 0===t&&(t={}),{ngModule:u,providers:[{provide:m,useValue:t},{provide:E,useFactory:A,deps:[m]},{provide:d,useClass:t.serializer?t.serializer:1===t.routerState?v:R}]}},a.prototype.setUpStoreStateListener=function(){var t=this;this.store.pipe(e.select(this.stateKey),n.withLatestFrom(this.store)).subscribe(function(e){var o=r.__read(e,2);t.navigateIfNeeded(o[0],o[1])})},a.prototype.navigateIfNeeded=function(t,e){var r=this;if(t&&t.state&&this.trigger!==S.ROUTER&&!(this.lastEvent instanceof i.NavigationStart)){var o=t.state.url;(function n(t,e){return _(t)===_(e)})(this.router.url,o)||(this.storeState=e,this.trigger=S.STORE,this.router.navigateByUrl(o).catch(function(t){r.errorHandler.handleError(t)}))}},a.prototype.setUpRouterEventsListener=function(){var e,o=this,a=this.config.navigationActionTiming===t.NavigationActionTiming.PostActivation;this.router.events.pipe(n.withLatestFrom(this.store)).subscribe(function(t){var n=r.__read(t,2),u=n[0],s=n[1];o.lastEvent=u,u instanceof i.NavigationStart?(o.routerState=o.serializer.serialize(o.router.routerState.snapshot),o.trigger!==S.STORE&&(o.storeState=s,o.dispatchRouterRequest(u))):u instanceof i.RoutesRecognized?(e=u,a||o.trigger===S.STORE||o.dispatchRouterNavigation(u)):u instanceof i.NavigationCancel?(o.dispatchRouterCancel(u),o.reset()):u instanceof i.NavigationError?(o.dispatchRouterError(u),o.reset()):u instanceof i.NavigationEnd&&(o.trigger!==S.STORE&&(a&&o.dispatchRouterNavigation(e),o.dispatchRouterNavigated(u)),o.reset())})},a.prototype.dispatchRouterRequest=function(t){this.dispatchRouterAction("@ngrx/router-store/request",{event:t})},a.prototype.dispatchRouterNavigation=function(t){var e=this.serializer.serialize(t.state);this.dispatchRouterAction(s,{routerState:e,event:new i.RoutesRecognized(t.id,t.url,t.urlAfterRedirects,e)})},a.prototype.dispatchRouterCancel=function(t){this.dispatchRouterAction(l,{storeState:this.storeState,event:t})},a.prototype.dispatchRouterError=function(t){this.dispatchRouterAction(g,{storeState:this.storeState,event:new i.NavigationError(t.id,t.url,""+t)})},a.prototype.dispatchRouterNavigated=function(t){var e=this.serializer.serialize(this.router.routerState.snapshot);this.dispatchRouterAction("@ngrx/router-store/navigated",{event:t,routerState:e})},a.prototype.dispatchRouterAction=function(t,e){this.trigger=S.ROUTER;try{this.store.dispatch({type:t,payload:r.__assign({routerState:this.routerState},e,{event:1===this.config.routerState?{id:e.event.id,url:e.event.url}:e.event})})}finally{this.trigger=S.NONE}},a.prototype.reset=function(){this.trigger=S.NONE,this.storeState=null,this.routerState=null},u=r.__decorate([o.NgModule({}),r.__param(4,o.Inject(E)),r.__metadata("design:paramtypes",[e.Store,i.Router,d,o.ErrorHandler,Object])],a)}();function _(t){return t.length>0&&"/"===t[t.length-1]?t.substring(0,t.length-1):t}t.ɵngrx_modules_router_store_router_store_a=m,t.ɵngrx_modules_router_store_router_store_b=A,t.ROUTER_ERROR=g,t.ROUTER_CANCEL=l,t.ROUTER_NAVIGATION=s,t.ROUTER_NAVIGATED="@ngrx/router-store/navigated",t.ROUTER_REQUEST="@ngrx/router-store/request",t.routerCancelAction=p,t.routerErrorAction=f,t.routerNavigatedAction=h,t.routerNavigationAction=c,t.routerRequestAction=u,t.routerReducer=function T(t,e){var r=e;switch(r.type){case s:case g:case l:return{state:r.payload.routerState,navigationId:r.payload.event.id};default:return t}},t.StoreRouterConnectingModule=N,t.ROUTER_CONFIG=E,t.DEFAULT_ROUTER_FEATURENAME=y,t.RouterStateSerializer=d,t.DefaultRouterStateSerializer=R,t.MinimalRouterStateSerializer=v,t.getSelectors=function C(t){var r=e.createSelector(t,function(t){return t&&t.state}),o=e.createSelector(r,function(t){if(t){for(var e=t.root;e.firstChild;)e=e.firstChild;return e}}),i=e.createSelector(o,function(t){return t&&t.queryParams}),n=e.createSelector(o,function(t){return t&&t.params}),a=e.createSelector(o,function(t){return t&&t.data}),u=e.createSelector(r,function(t){return t&&t.url});return{selectCurrentRoute:o,selectQueryParams:i,selectQueryParam:function(t){return e.createSelector(i,function(e){return e&&e[t]})},selectRouteParams:n,selectRouteParam:function(t){return e.createSelector(n,function(e){return e&&e[t]})},selectRouteData:a,selectUrl:u}},Object.defineProperty(t,"__esModule",{value:!0})});
\No newline at end of file