-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathreducer.ts
35 lines (33 loc) · 1.03 KB
/
reducer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { Action } from '@ngrx/store';
import {
ROUTER_CANCEL,
ROUTER_ERROR,
ROUTER_NAVIGATION,
RouterAction,
} from './actions';
import { BaseRouterStoreState } from './serializers/base';
import { SerializedRouterStateSnapshot } from './serializers/full_serializer';
export type RouterReducerState<
T extends BaseRouterStoreState = SerializedRouterStateSnapshot
> = {
state: T;
navigationId: number;
};
export function routerReducer<
RouterState extends BaseRouterStoreState = SerializedRouterStateSnapshot,
Result = RouterReducerState<RouterState>
>(state: Result | undefined, action: Action): Result {
// Allow compilation with strictFunctionTypes - ref: #1344
const routerAction = action as RouterAction<any, RouterState>;
switch (routerAction.type) {
case ROUTER_NAVIGATION:
case ROUTER_ERROR:
case ROUTER_CANCEL:
return {
state: routerAction.payload.routerState,
navigationId: routerAction.payload.event.id,
} as unknown as Result;
default:
return state as Result;
}
}