Skip to content

Commit ba412fc

Browse files
e-schultzsmithad15
authored andcommitted
Merge branch 'master' of github.com:angular-redux/router
1 parent 3df28c3 commit ba412fc

File tree

3 files changed

+928
-63
lines changed

3 files changed

+928
-63
lines changed

packages/router/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"redux": "^3.6.0",
3737
"rimraf": "^2.5.4",
3838
"rxjs": "^5.0.1",
39-
"typescript": "^2.4.1",
39+
"typescript": "2.4.2",
4040
"zone.js": "^0.8.4"
4141
},
4242
"author": "Dag Stuan",

packages/router/src/router.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
import 'rxjs/add/operator/filter';
22
import 'rxjs/add/operator/map';
3+
import 'rxjs/add/operator/distinctUntilChanged';
34
import { Injectable, ApplicationRef } from '@angular/core';
45
import { Location } from '@angular/common';
5-
import { Router, NavigationEnd, NavigationCancel, DefaultUrlSerializer } from '@angular/router';
6+
import {
7+
Router,
8+
NavigationEnd,
9+
NavigationCancel,
10+
DefaultUrlSerializer
11+
} from '@angular/router';
612
import { NgRedux } from '@angular-redux/store';
713
import { Observable } from 'rxjs/Observable';
8-
import { ISubscription } from 'rxjs/Subscription'
14+
import { ISubscription } from 'rxjs/Subscription';
915
import { UPDATE_LOCATION } from './actions';
10-
import {
11-
RouterAction,
12-
DefaultRouterState
13-
} from './reducer';
16+
import { RouterAction, DefaultRouterState } from './reducer';
1417

1518
@Injectable()
1619
export class NgReduxRouter {
1720
private initialized = false;
1821
private currentLocation: string;
1922
private initialLocation: string;
2023

21-
private selectLocationFromState: (state: any) => string = (state) => state.router;
24+
private selectLocationFromState: (state: any) => string = state =>
25+
state.router;
2226
private urlState: Observable<string>;
2327

2428
private urlStateSubscription: ISubscription;
@@ -64,14 +68,16 @@ export class NgReduxRouter {
6468
* you can supply this argument as an Observable of the current url state.
6569
*/
6670
initialize(
67-
selectLocationFromState: (state: any) => string = (state) => state.router,
71+
selectLocationFromState: (state: any) => string = state => state.router,
6872
urlState$: Observable<string> | undefined = undefined
6973
) {
7074
if (this.initialized) {
71-
throw new Error('@angular-redux/router already initialized! If you meant to re-initialize, call destroy first.');
75+
throw new Error(
76+
'@angular-redux/router already initialized! If you meant to re-initialize, call destroy first.'
77+
);
7278
}
7379

74-
this.selectLocationFromState = selectLocationFromState
80+
this.selectLocationFromState = selectLocationFromState;
7581

7682
this.urlState = urlState$ || this.getDefaultUrlStateObservable();
7783

@@ -82,19 +88,21 @@ export class NgReduxRouter {
8288

8389
private getDefaultUrlStateObservable() {
8490
return this.router.events
85-
.filter(event => event instanceof NavigationEnd)
86-
.map(event => this.location.path())
87-
.distinctUntilChanged()
91+
.filter(event => event instanceof NavigationEnd)
92+
.map(event => this.location.path())
93+
.distinctUntilChanged();
8894
}
8995

9096
private getLocationFromStore(useInitial: boolean = false) {
91-
return this.selectLocationFromState(this.ngRedux.getState()) ||
92-
(useInitial ? this.initialLocation : '');
97+
return (
98+
this.selectLocationFromState(this.ngRedux.getState()) ||
99+
(useInitial ? this.initialLocation : '')
100+
);
93101
}
94102

95103
private listenToRouterChanges() {
96104
const handleLocationChange = (location: string) => {
97-
if(this.currentLocation === location) {
105+
if (this.currentLocation === location) {
98106
// Dont dispatch changes if we haven't changed location.
99107
return;
100108
}
@@ -107,7 +115,7 @@ export class NgReduxRouter {
107115
// we dont dispath an event if the current url equals
108116
// the initial url.
109117
let locationFromStore = this.getLocationFromStore();
110-
if(locationFromStore === this.currentLocation) {
118+
if (locationFromStore === this.currentLocation) {
111119
return;
112120
}
113121
}
@@ -116,7 +124,7 @@ export class NgReduxRouter {
116124
type: UPDATE_LOCATION,
117125
payload: location
118126
});
119-
}
127+
};
120128

121129
this.urlStateSubscription = this.urlState.subscribe(handleLocationChange);
122130
}
@@ -134,9 +142,9 @@ export class NgReduxRouter {
134142
return;
135143
}
136144

137-
this.currentLocation = location
145+
this.currentLocation = location;
138146
this.router.navigateByUrl(location);
139-
}
147+
};
140148

141149
this.reduxSubscription = this.ngRedux
142150
.select(state => this.selectLocationFromState(state))

0 commit comments

Comments
 (0)