UNPKG

6.91 kBJavaScriptView Raw
1/**
2 * @license NgRx 8.5.2
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("tslib"),require("@angular/core"),require("@angular/router"),require("@ngrx/store"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("@ngrx/router-store",["exports","tslib","@angular/core","@angular/router","@ngrx/store","rxjs/operators"],e):e(((t=t||self).ngrx=t.ngrx||{},t.ngrx.routerStore={}),t.tslib,t.ng.core,t.ng.router,t["@ngrx/store"],t.rxjs.operators)}(this,function(t,e,r,o,i,n){"use strict";var a,u="@ngrx/router-store/error",s=function s(){},c=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}(),l=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 g,p=new r.InjectionToken("@ngrx/router-store Internal Configuration"),f=new r.InjectionToken("@ngrx/router-store Configuration"),h="router";function d(r){return e.__assign({stateKey:h,serializer:c,navigationActionTiming:t.NavigationActionTiming.PreActivation},r)}!function(t){t[t.NONE=1]="NONE",t[t.ROUTER=2]="ROUTER",t[t.STORE=3]="STORE"}(g||(g={}));var R=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=g.NONE,this.stateKey=this.config.stateKey,this.setUpStoreStateListener(),this.setUpRouterEventsListener()}var h;return h=a,a.forRoot=function(t){return void 0===t&&(t={}),{ngModule:h,providers:[{provide:p,useValue:t},{provide:f,useFactory:d,deps:[p]},{provide:s,useClass:t.serializer?t.serializer:1===t.routerState?l:c}]}},a.prototype.setUpStoreStateListener=function(){var t=this;this.store.pipe(i.select(this.stateKey),n.withLatestFrom(this.store)).subscribe(function(r){var o=e.__read(r,2);t.navigateIfNeeded(o[0],o[1])})},a.prototype.navigateIfNeeded=function(t,e){var r=this;if(t&&t.state&&this.trigger!==g.ROUTER&&!(this.lastEvent instanceof o.NavigationStart)){var i=t.state.url;this.router.url!==i&&(this.storeState=e,this.trigger=g.STORE,this.router.navigateByUrl(i).catch(function(t){r.errorHandler.handleError(t)}))}},a.prototype.setUpRouterEventsListener=function(){var r,i=this,a=this.config.navigationActionTiming===t.NavigationActionTiming.PostActivation;this.router.events.pipe(n.withLatestFrom(this.store)).subscribe(function(t){var n=e.__read(t,2),u=n[0],s=n[1];i.lastEvent=u,u instanceof o.NavigationStart?(i.routerState=i.serializer.serialize(i.router.routerState.snapshot),i.trigger!==g.STORE&&(i.storeState=s,i.dispatchRouterRequest(u))):u instanceof o.RoutesRecognized?(r=u,a||i.trigger===g.STORE||i.dispatchRouterNavigation(u)):u instanceof o.NavigationCancel?(i.dispatchRouterCancel(u),i.reset()):u instanceof o.NavigationError?(i.dispatchRouterError(u),i.reset()):u instanceof o.NavigationEnd&&(i.trigger!==g.STORE&&(a&&i.dispatchRouterNavigation(r),i.dispatchRouterNavigated(u)),i.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("@ngrx/router-store/navigation",{routerState:e,event:new o.RoutesRecognized(t.id,t.url,t.urlAfterRedirects,e)})},a.prototype.dispatchRouterCancel=function(t){this.dispatchRouterAction("@ngrx/router-store/cancel",{storeState:this.storeState,event:t})},a.prototype.dispatchRouterError=function(t){this.dispatchRouterAction(u,{storeState:this.storeState,event:new o.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,r){this.trigger=g.ROUTER;try{this.store.dispatch({type:t,payload:e.__assign({routerState:this.routerState},r,{event:1===this.config.routerState?{id:r.event.id,url:r.event.url}:r.event})})}finally{this.trigger=g.NONE}},a.prototype.reset=function(){this.trigger=g.NONE,this.storeState=null,this.routerState=null},h=e.__decorate([r.NgModule({}),e.__param(4,r.Inject(f)),e.__metadata("design:paramtypes",[i.Store,o.Router,s,r.ErrorHandler,Object])],a)}();t.ɵngrx_modules_router_store_router_store_a=p,t.ɵngrx_modules_router_store_router_store_b=d,t.ROUTER_ERROR=u,t.ROUTER_CANCEL="@ngrx/router-store/cancel",t.ROUTER_NAVIGATION="@ngrx/router-store/navigation",t.ROUTER_NAVIGATED="@ngrx/router-store/navigated",t.ROUTER_REQUEST="@ngrx/router-store/request",t.routerReducer=function v(t,e){var r=e;switch(r.type){case"@ngrx/router-store/navigation":case u:case"@ngrx/router-store/cancel":return{state:r.payload.routerState,navigationId:r.payload.event.id};default:return t}},t.StoreRouterConnectingModule=R,t.ROUTER_CONFIG=f,t.DEFAULT_ROUTER_FEATURENAME=h,t.RouterStateSerializer=s,t.DefaultRouterStateSerializer=c,t.MinimalRouterStateSerializer=l,t.getSelectors=function S(t){var e=i.createSelector(t,function(t){return t&&t.state}),r=i.createSelector(e,function(t){if(t){for(var e=t.root;e.firstChild;)e=e.firstChild;return e}}),o=i.createSelector(r,function(t){return t&&t.queryParams}),n=i.createSelector(r,function(t){return t&&t.params}),a=i.createSelector(r,function(t){return t&&t.data}),u=i.createSelector(e,function(t){return t&&t.url});return{selectCurrentRoute:r,selectQueryParams:o,selectQueryParam:function(t){return i.createSelector(o,function(e){return e&&e[t]})},selectRouteParams:n,selectRouteParam:function(t){return i.createSelector(n,function(e){return e&&e[t]})},selectRouteData:a,selectUrl:u}},Object.defineProperty(t,"__esModule",{value:!0})});
\No newline at end of file