Skip to content

Commit

Permalink
fix(router-store): Added new imports to index.ts, codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored and brandonroberts committed Aug 24, 2018
1 parent 11d3b9f commit 293f960
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
3 changes: 2 additions & 1 deletion modules/router-store/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
StoreRouterConfig,
ROUTER_REQUEST,
ROUTER_NAVIGATED,
NavigationActionTiming,
} from '../src/router_store_module';

describe('integration spec', () => {
Expand Down Expand Up @@ -655,7 +656,7 @@ describe('integration spec', () => {

createTestModule({
reducers: { reducer },
config: { dispatchNavActionOnEnd: true },
config: { navigationActionTiming: NavigationActionTiming.PostActivation },
});

const router: Router = TestBed.get(Router);
Expand Down
8 changes: 8 additions & 0 deletions modules/router-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ export {
ROUTER_ERROR,
ROUTER_CANCEL,
ROUTER_NAVIGATION,
ROUTER_REQUEST,
ROUTER_NAVIGATED,
RouterNavigationAction,
RouterCancelAction,
RouterErrorAction,
RouterRequestAction,
RouterNavigatedAction,
RouterAction,
routerReducer,
RouterErrorPayload,
RouterReducerState,
RouterCancelPayload,
RouterNavigationPayload,
RouterRequestPayload,
RouterNavigatedPayload,
StoreRouterConnectingModule,
StoreRouterConfig,
StoreRouterConfigFunction,
NavigationActionTiming,
ROUTER_CONFIG,
DEFAULT_ROUTER_FEATURENAME,
} from './router_store_module';
Expand All @@ -22,4 +29,5 @@ export {
RouterStateSerializer,
DefaultRouterStateSerializer,
SerializedRouterStateSnapshot,
SimpleRouterState,
} from './serializer';
42 changes: 25 additions & 17 deletions modules/router-store/src/router_store_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
DefaultRouterStateSerializer,
RouterStateSerializer,
SerializedRouterStateSnapshot,
RouterState,
SimpleRouterState,
} from './serializer';

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ export const ROUTER_NAVIGATION = 'ROUTER_NAVIGATION';
/**
* Payload of ROUTER_NAVIGATION.
*/
export type RouterNavigationPayload<T extends RouterState> = {
export type RouterNavigationPayload<T extends SimpleRouterState> = {
routerState: T;
event: RoutesRecognized;
};
Expand All @@ -58,7 +58,7 @@ export type RouterNavigationPayload<T extends RouterState> = {
* An action dispatched when the router navigates.
*/
export type RouterNavigationAction<
T extends RouterState = SerializedRouterStateSnapshot
T extends SimpleRouterState = SerializedRouterStateSnapshot
> = {
type: typeof ROUTER_NAVIGATION;
payload: RouterNavigationPayload<T>;
Expand All @@ -72,7 +72,7 @@ export const ROUTER_CANCEL = 'ROUTER_CANCEL';
/**
* Payload of ROUTER_CANCEL.
*/
export type RouterCancelPayload<T, V extends RouterState> = {
export type RouterCancelPayload<T, V extends SimpleRouterState> = {
routerState: V;
storeState: T;
event: NavigationCancel;
Expand All @@ -83,7 +83,7 @@ export type RouterCancelPayload<T, V extends RouterState> = {
*/
export type RouterCancelAction<
T,
V extends RouterState = SerializedRouterStateSnapshot
V extends SimpleRouterState = SerializedRouterStateSnapshot
> = {
type: typeof ROUTER_CANCEL;
payload: RouterCancelPayload<T, V>;
Expand All @@ -97,7 +97,7 @@ export const ROUTER_ERROR = 'ROUTE_ERROR';
/**
* Payload of ROUTER_ERROR.
*/
export type RouterErrorPayload<T, V extends RouterState> = {
export type RouterErrorPayload<T, V extends SimpleRouterState> = {
routerState: V;
storeState: T;
event: NavigationError;
Expand All @@ -108,7 +108,7 @@ export type RouterErrorPayload<T, V extends RouterState> = {
*/
export type RouterErrorAction<
T,
V extends RouterState = SerializedRouterStateSnapshot
V extends SimpleRouterState = SerializedRouterStateSnapshot
> = {
type: typeof ROUTER_ERROR;
payload: RouterErrorPayload<T, V>;
Expand Down Expand Up @@ -139,7 +139,7 @@ export type RouterNavigatedAction = {
*/
export type RouterAction<
T,
V extends RouterState = SerializedRouterStateSnapshot
V extends SimpleRouterState = SerializedRouterStateSnapshot
> =
| RouterRequestAction
| RouterNavigationAction<V>
Expand All @@ -148,14 +148,14 @@ export type RouterAction<
| RouterNavigatedAction;

export type RouterReducerState<
T extends RouterState = SerializedRouterStateSnapshot
T extends SimpleRouterState = SerializedRouterStateSnapshot
> = {
state: T;
navigationId: number;
};

export function routerReducer<
T extends RouterState = SerializedRouterStateSnapshot
T extends SimpleRouterState = SerializedRouterStateSnapshot
>(
state: RouterReducerState<T> | undefined,
action: RouterAction<any, T>
Expand All @@ -180,9 +180,15 @@ export interface StoreRouterConfig {
* By default, ROUTER_NAVIGATION is dispatched before guards and resolvers run.
* Therefore, the action could run too soon, for example
* there may be a navigation cancel due to a guard saying the navigation is not allowed.
* To run ROUTER_NAVIGATION after guards and resolvers, set this property to true.
* To run ROUTER_NAVIGATION after guards and resolvers,
* set this property to NavigationActionTiming.PostActivation.
*/
dispatchNavActionOnEnd?: boolean;
navigationActionTiming?: NavigationActionTiming;
}

export enum NavigationActionTiming {
PreActivation = 1,
PostActivation = 2,
}

export const _ROUTER_CONFIG = new InjectionToken(
Expand All @@ -207,7 +213,7 @@ export function _createRouterConfig(
return {
stateKey: DEFAULT_ROUTER_FEATURENAME,
serializer: DefaultRouterStateSerializer,
dispatchNavActionOnEnd: false,
navigationActionTiming: NavigationActionTiming.PreActivation,
..._config,
};
}
Expand All @@ -223,9 +229,9 @@ export function _createSerializer(
export type StoreRouterConfigFunction = () => StoreRouterConfig;

enum RouterTrigger {
NONE,
ROUTER,
STORE,
NONE = 1,
ROUTER = 2,
STORE = 3,
}

/**
Expand Down Expand Up @@ -350,7 +356,9 @@ export class StoreRouterConnectingModule {
}

private setUpRouterEventsListener(): void {
const dispatchNavLate = this.config.dispatchNavActionOnEnd;
const dispatchNavLate =
this.config.navigationActionTiming ===
NavigationActionTiming.PostActivation;
let routesRecognized: RoutesRecognized;

this.router.events.subscribe(event => {
Expand Down
8 changes: 5 additions & 3 deletions modules/router-store/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
* Simple router state.
* All custom router states / state serializers should have at least this property.
*/
export interface RouterState {
export interface SimpleRouterState {
url: string;
}

export abstract class RouterStateSerializer<T extends RouterState = RouterState> {
export abstract class RouterStateSerializer<
T extends SimpleRouterState = SimpleRouterState
> {
abstract serialize(routerState: RouterStateSnapshot): T;
}

export interface SerializedRouterStateSnapshot extends RouterState {
export interface SerializedRouterStateSnapshot extends SimpleRouterState {
root: ActivatedRouteSnapshot;
url: string;
}
Expand Down

0 comments on commit 293f960

Please sign in to comment.