UNPKG

4.82 kBTypeScriptView Raw
1import { InjectionToken, ModuleWithProviders, ErrorHandler } from '@angular/core';
2import { Router } from '@angular/router';
3import { RuntimeChecks, Selector, Store } from '@ngrx/store';
4import { RouterReducerState } from './reducer';
5import { RouterStateSerializer, BaseRouterStoreState } from './serializers/base';
6import { SerializedRouterStateSnapshot } from './serializers/full_serializer';
7import * as i0 from "@angular/core";
8export declare type StateKeyOrSelector<T extends BaseRouterStoreState = SerializedRouterStateSnapshot> = string | Selector<any, RouterReducerState<T>>;
9/**
10 * Minimal = Serializes the router event with MinimalRouterStateSerializer
11 * Full = Serializes the router event with FullRouterStateSerializer
12 */
13export declare const enum RouterState {
14 Full = 0,
15 Minimal = 1
16}
17export interface StoreRouterConfig<T extends BaseRouterStoreState = SerializedRouterStateSnapshot> {
18 stateKey?: StateKeyOrSelector<T>;
19 serializer?: new (...args: any[]) => RouterStateSerializer;
20 /**
21 * By default, ROUTER_NAVIGATION is dispatched before guards and resolvers run.
22 * Therefore, the action could run too soon, for example
23 * there may be a navigation cancel due to a guard saying the navigation is not allowed.
24 * To run ROUTER_NAVIGATION after guards and resolvers,
25 * set this property to NavigationActionTiming.PostActivation.
26 */
27 navigationActionTiming?: NavigationActionTiming;
28 /**
29 * Decides which router serializer should be used, if there is none provided, and the metadata on the dispatched @ngrx/router-store action payload.
30 * Set to `Minimal` to use the `MinimalRouterStateSerializer` and to set a minimal router event with the navigation id and url as payload.
31 * Set to `Full` to use the `FullRouterStateSerializer` and to set the angular router events as payload.
32 */
33 routerState?: RouterState;
34}
35export declare enum NavigationActionTiming {
36 PreActivation = 1,
37 PostActivation = 2
38}
39export declare const _ROUTER_CONFIG: InjectionToken<unknown>;
40export declare const ROUTER_CONFIG: InjectionToken<unknown>;
41export declare const DEFAULT_ROUTER_FEATURENAME = "router";
42export declare function _createRouterConfig(config: StoreRouterConfig): StoreRouterConfig;
43/**
44 * Connects RouterModule with StoreModule.
45 *
46 * During the navigation, before any guards or resolvers run, the router will dispatch
47 * a ROUTER_NAVIGATION action, which has the following signature:
48 *
49 * ```
50 * export type RouterNavigationPayload = {
51 * routerState: SerializedRouterStateSnapshot,
52 * event: RoutesRecognized
53 * }
54 * ```
55 *
56 * Either a reducer or an effect can be invoked in response to this action.
57 * If the invoked reducer throws, the navigation will be canceled.
58 *
59 * If navigation gets canceled because of a guard, a ROUTER_CANCEL action will be
60 * dispatched. If navigation results in an error, a ROUTER_ERROR action will be dispatched.
61 *
62 * Both ROUTER_CANCEL and ROUTER_ERROR contain the store state before the navigation
63 * which can be used to restore the consistency of the store.
64 *
65 * Usage:
66 *
67 * ```typescript
68 * @NgModule({
69 * declarations: [AppCmp, SimpleCmp],
70 * imports: [
71 * BrowserModule,
72 * StoreModule.forRoot(mapOfReducers),
73 * RouterModule.forRoot([
74 * { path: '', component: SimpleCmp },
75 * { path: 'next', component: SimpleCmp }
76 * ]),
77 * StoreRouterConnectingModule.forRoot()
78 * ],
79 * bootstrap: [AppCmp]
80 * })
81 * export class AppModule {
82 * }
83 * ```
84 */
85export declare class StoreRouterConnectingModule {
86 private store;
87 private router;
88 private serializer;
89 private errorHandler;
90 private readonly config;
91 private readonly activeRuntimeChecks;
92 private lastEvent;
93 private routerState;
94 private storeState;
95 private trigger;
96 private readonly stateKey;
97 static forRoot<T extends BaseRouterStoreState = SerializedRouterStateSnapshot>(config?: StoreRouterConfig<T>): ModuleWithProviders<StoreRouterConnectingModule>;
98 constructor(store: Store<any>, router: Router, serializer: RouterStateSerializer<SerializedRouterStateSnapshot>, errorHandler: ErrorHandler, config: StoreRouterConfig, activeRuntimeChecks: RuntimeChecks);
99 private setUpStoreStateListener;
100 private navigateIfNeeded;
101 private setUpRouterEventsListener;
102 private dispatchRouterRequest;
103 private dispatchRouterNavigation;
104 private dispatchRouterCancel;
105 private dispatchRouterError;
106 private dispatchRouterNavigated;
107 private dispatchRouterAction;
108 private reset;
109 static ɵfac: i0.ɵɵFactoryDeclaration<StoreRouterConnectingModule, never>;
110 static ɵmod: i0.ɵɵNgModuleDeclaration<StoreRouterConnectingModule, never, never, never>;
111 static ɵinj: i0.ɵɵInjectorDeclaration<StoreRouterConnectingModule>;
112}