Updated ngrx to 6.0.0-beta.1

This commit is contained in:
Sercan Yemen 2018-05-09 14:50:30 +03:00
parent a2187e0134
commit 6bf2fe0b17
5 changed files with 3351 additions and 3299 deletions

6505
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,22 +20,22 @@
"dependencies": { "dependencies": {
"@agm/core": "1.0.0-beta.2", "@agm/core": "1.0.0-beta.2",
"@angular/animations": "6.0.0", "@angular/animations": "6.0.0",
"@angular/cdk": "6.0.0", "@angular/cdk": "6.0.1",
"@angular/common": "6.0.0", "@angular/common": "6.0.0",
"@angular/compiler": "6.0.0", "@angular/compiler": "6.0.0",
"@angular/core": "6.0.0", "@angular/core": "6.0.0",
"@angular/flex-layout": "6.0.0-beta.15", "@angular/flex-layout": "6.0.0-beta.15",
"@angular/forms": "6.0.0", "@angular/forms": "6.0.0",
"@angular/http": "6.0.0", "@angular/http": "6.0.0",
"@angular/material": "6.0.0", "@angular/material": "6.0.1",
"@angular/material-moment-adapter": "6.0.0", "@angular/material-moment-adapter": "6.0.1",
"@angular/platform-browser": "6.0.0", "@angular/platform-browser": "6.0.0",
"@angular/platform-browser-dynamic": "6.0.0", "@angular/platform-browser-dynamic": "6.0.0",
"@angular/router": "6.0.0", "@angular/router": "6.0.0",
"@ngrx/effects": "5.2.0", "@ngrx/effects": "6.0.0-beta.1",
"@ngrx/router-store": "5.2.0", "@ngrx/router-store": "6.0.0-beta.1",
"@ngrx/store": "5.2.0", "@ngrx/store": "6.0.0-beta.1",
"@ngrx/store-devtools": "5.2.0", "@ngrx/store-devtools": "6.0.0-beta.1",
"@ngx-translate/core": "10.0.1", "@ngx-translate/core": "10.0.1",
"@swimlane/ngx-charts": "7.3.0", "@swimlane/ngx-charts": "7.3.0",
"@swimlane/ngx-datatable": "11.3.2", "@swimlane/ngx-datatable": "11.3.2",

View File

@ -5,22 +5,28 @@ export const GO = '[Router] Go';
export const BACK = '[Router] Back'; export const BACK = '[Router] Back';
export const FORWARD = '[Router] Forward'; export const FORWARD = '[Router] Forward';
export class Go implements Action { export class Go implements Action
{
readonly type = GO; readonly type = GO;
constructor( constructor(
public payload: { public payload: {
path: any[]; path: any[];
query?: object; query?: object;
extras?: NavigationExtras; extras?: NavigationExtras;
} }
) {} )
{
}
} }
export class Back implements Action { export class Back implements Action
{
readonly type = BACK; readonly type = BACK;
} }
export class Forward implements Action { export class Forward implements Action
{
readonly type = FORWARD; readonly type = FORWARD;
} }

View File

@ -8,27 +8,30 @@ import * as RouterActions from '../actions/router.action';
import { tap, map } from 'rxjs/operators'; import { tap, map } from 'rxjs/operators';
@Injectable() @Injectable()
export class RouterEffects { export class RouterEffects
{
constructor( constructor(
private actions$: Actions, private actions$: Actions,
private router: Router, private router: Router,
private location: Location private location: Location
) {} )
{
}
@Effect({ dispatch: false }) @Effect({dispatch: false})
navigate$ = this.actions$.ofType(RouterActions.GO).pipe( navigate$ = this.actions$.ofType(RouterActions.GO).pipe(
map((action: RouterActions.Go) => action.payload), map((action: RouterActions.Go) => action.payload),
tap(({ path, query: queryParams, extras }) => { tap(({path, query: queryParams, extras}) => {
this.router.navigate(path, { queryParams, ...extras }); this.router.navigate(path, {queryParams, ...extras});
}) })
); );
@Effect({ dispatch: false }) @Effect({dispatch: false})
navigateBack$ = this.actions$ navigateBack$ = this.actions$
.ofType(RouterActions.BACK) .ofType(RouterActions.BACK)
.pipe(tap(() => this.location.back())); .pipe(tap(() => this.location.back()));
@Effect({ dispatch: false }) @Effect({dispatch: false})
navigateForward$ = this.actions$ navigateForward$ = this.actions$
.ofType(RouterActions.FORWARD) .ofType(RouterActions.FORWARD)
.pipe(tap(() => this.location.forward())); .pipe(tap(() => this.location.forward()));

View File

@ -1,42 +1,48 @@
import { import {
ActivatedRouteSnapshot, ActivatedRouteSnapshot,
RouterStateSnapshot, RouterStateSnapshot,
Params, Params
} from '@angular/router'; } from '@angular/router';
import { createFeatureSelector, ActionReducerMap } from '@ngrx/store'; import { createFeatureSelector, ActionReducerMap } from '@ngrx/store';
import * as fromRouter from '@ngrx/router-store'; import * as fromRouter from '@ngrx/router-store';
export interface RouterStateUrl { export interface RouterStateUrl
{
url: string; url: string;
queryParams: Params; queryParams: Params;
params: Params; params: Params;
} }
export interface State { export interface State
{
routerReducer: fromRouter.RouterReducerState<RouterStateUrl>; routerReducer: fromRouter.RouterReducerState<RouterStateUrl>;
} }
export const reducers: ActionReducerMap<State> = { export const reducers: ActionReducerMap<State> = {
routerReducer: fromRouter.routerReducer, routerReducer: fromRouter.routerReducer
}; };
export const getRouterState = createFeatureSelector< export const getRouterState = createFeatureSelector<fromRouter.RouterReducerState<RouterStateUrl>>('routerReducer');
fromRouter.RouterReducerState<RouterStateUrl>
>('routerReducer');
export class CustomSerializer export class CustomSerializer implements fromRouter.RouterStateSerializer<RouterStateUrl>
implements fromRouter.RouterStateSerializer<RouterStateUrl> { {
serialize(routerState: RouterStateSnapshot): RouterStateUrl { serialize(routerState: RouterStateSnapshot): RouterStateUrl
const { url } = routerState; {
const { queryParams } = routerState.root; const {url} = routerState;
const {queryParams} = routerState.root;
let state: ActivatedRouteSnapshot = routerState.root; let state: ActivatedRouteSnapshot = routerState.root;
while (state.firstChild) { while ( state.firstChild )
{
state = state.firstChild; state = state.firstChild;
} }
const { params } = state; const {params} = state;
return { url, queryParams, params }; return {
url,
queryParams,
params
};
} }
} }