From 7e49148732c4af21bd98d22b7f00e8aadcf3f98b Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 29 Jan 2018 15:28:28 +0900 Subject: [PATCH] ing --- src/app/app-reducer.module.ts | 61 +++++++++++++++++++ src/app/app-routing.module.ts | 2 +- src/app/app.module.ts | 52 ++-------------- src/app/app.reducers.ts | 6 -- .../commons/router/guards/auth-guard.spec.ts | 15 +++++ src/app/commons/router/guards/auth-guard.ts | 9 +++ 6 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 src/app/app-reducer.module.ts delete mode 100644 src/app/app.reducers.ts create mode 100644 src/app/commons/router/guards/auth-guard.spec.ts create mode 100644 src/app/commons/router/guards/auth-guard.ts diff --git a/src/app/app-reducer.module.ts b/src/app/app-reducer.module.ts new file mode 100644 index 0000000..3e32f74 --- /dev/null +++ b/src/app/app-reducer.module.ts @@ -0,0 +1,61 @@ +import { NgModule } from '@angular/core'; +import { StoreModule } from '@ngrx/store'; +import { StoreDevtoolsModule } from '@ngrx/store-devtools'; +import { + StoreRouterConnectingModule, + RouterStateSerializer, +} from '@ngrx/router-store'; +import { EffectsModule } from '@ngrx/effects'; +import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; + +import { environment } from '../environments/environment'; +import { AppState } from './app.state'; + +import { SimpleRouterStateSerializer } from './commons/router/state/serializer/simple-router-state-serializer'; + +export const reducers: ActionReducerMap = { +}; + +@NgModule({ + exports: [ + StoreModule, + ], + imports: [ + StoreModule.forRoot(reducers), + /** + * @ngrx/router-store keeps router state up-to-date in the store. + */ + StoreRouterConnectingModule.forRoot({ + /* + They stateKey defines the name of the state used by the router-store reducer. + This matches the key defined in the map of reducers + */ + stateKey: 'router', + }), + /** + * Store devtools instrument the store retaining past versions of state + * and recalculating new states. This enables powerful time-travel + * debugging. + * + * To use the debugger, install the Redux Devtools extension for either + * Chrome or Firefox + * + * See: https://github.com/zalmoxisus/redux-devtools-extension + */ + StoreDevtoolsModule.instrument({ + name: 'overFlow WebApp DevTools', + logOnly: environment.production, + }), + EffectsModule.forRoot([]), + ], + providers: [ + /** + * The `RouterStateSnapshot` provided by the `Router` is a large complex structure. + * A custom RouterStateSerializer is used to parse the `RouterStateSnapshot` provided + * by `@ngrx/router-store` to include only the desired pieces of the snapshot. + */ + { provide: RouterStateSerializer, useClass: SimpleRouterStateSerializer }, + ], + +}) +export class AppReducerModule { } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 7fdd553..e3174dd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -10,6 +10,6 @@ const routes: Routes = [ @NgModule({ imports: [RouterModule.forRoot(routes, {useHash: true})], - exports: [RouterModule] + exports: [RouterModule], }) export class AppRoutingModule { } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 42c025a..36fa40e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -3,22 +3,11 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { StoreModule } from '@ngrx/store'; -import { StoreDevtoolsModule } from '@ngrx/store-devtools'; -import { - StoreRouterConnectingModule, - RouterStateSerializer, -} from '@ngrx/router-store'; -import { EffectsModule } from '@ngrx/effects'; - -import { environment } from '../environments/environment'; - import { AppRoutingModule } from './app-routing.module'; -import { AppComponent } from './app.component'; - +import { AppReducerModule } from './app-reducer.module'; import { MaterialModule } from './commons/ui/material/material.module'; -import { SimpleRouterStateSerializer } from './commons/router/state/serializer/simple-router-state-serializer'; -import { reducers } from './app.reducers'; + +import { AppComponent } from './app.component'; @NgModule({ declarations: [ @@ -28,42 +17,9 @@ import { reducers } from './app.reducers'; BrowserModule, BrowserAnimationsModule, AppRoutingModule, - StoreModule.forRoot(reducers), - /** - * @ngrx/router-store keeps router state up-to-date in the store. - */ - StoreRouterConnectingModule.forRoot({ - /* - They stateKey defines the name of the state used by the router-store reducer. - This matches the key defined in the map of reducers - */ - stateKey: 'router', - }), - /** - * Store devtools instrument the store retaining past versions of state - * and recalculating new states. This enables powerful time-travel - * debugging. - * - * To use the debugger, install the Redux Devtools extension for either - * Chrome or Firefox - * - * See: https://github.com/zalmoxisus/redux-devtools-extension - */ - StoreDevtoolsModule.instrument({ - name: 'overFlow WebApp DevTools', - logOnly: environment.production, - }), - EffectsModule.forRoot([]), + AppReducerModule, MaterialModule, ], - providers: [ - /** - * The `RouterStateSnapshot` provided by the `Router` is a large complex structure. - * A custom RouterStateSerializer is used to parse the `RouterStateSnapshot` provided - * by `@ngrx/router-store` to include only the desired pieces of the snapshot. - */ - { provide: RouterStateSerializer, useClass: SimpleRouterStateSerializer }, - ], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/src/app/app.reducers.ts b/src/app/app.reducers.ts deleted file mode 100644 index fb5eba7..0000000 --- a/src/app/app.reducers.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; - -import { AppState } from './app.state'; - -export const reducers: ActionReducerMap = { -}; diff --git a/src/app/commons/router/guards/auth-guard.spec.ts b/src/app/commons/router/guards/auth-guard.spec.ts new file mode 100644 index 0000000..1752942 --- /dev/null +++ b/src/app/commons/router/guards/auth-guard.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { AuthGuard } from './auth-guard'; + +describe('AuthGuardService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [AuthGuard] + }); + }); + + it('should be created', inject([AuthGuard], (service: AuthGuard) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/commons/router/guards/auth-guard.ts b/src/app/commons/router/guards/auth-guard.ts new file mode 100644 index 0000000..57e2b03 --- /dev/null +++ b/src/app/commons/router/guards/auth-guard.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; +import { CanActivate } from '@angular/router'; +import { Store, select } from '@ngrx/store'; +import { Observable } from 'rxjs/Observable'; +import { map, take } from 'rxjs/operators'; + +@Injectable() +export class AuthGuard { +}