import { Observable } from 'rxjs/Observable' ; import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , CanActivate , RouterStateSnapshot , Router } from '@angular/router' ; import { select , Store } from '@ngrx/store' ; import { AppState } from '@StoreConfig' ; import { map } from 'rxjs/operators' ; import { selectTodosLoaded$ } from '@Selectors/todo-list.selector' ; import { TodoListModule } from '@Actions/todo-list.action' ; @ Injectable ( ) export class IsTodosLoadedGuard implements CanActivate { constructor ( private store , private router ) { } canActivate ( next , state ) { return this . store . pipe ( select ( selectTodosLoaded$ ) , map ( isLoaded => { if ( ! isLoaded ) { this . store . dispatch ( new TodoListModule . LoadInitTodos ( ) ) ; } return true ; } ) ) ; } }