{
  "version": 3,
  "sources": ["src/app/content/guards/news.guard.ts"],
  "sourcesContent": ["import { Injectable } from '@angular/core';\r\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\r\n\r\nimport { Store } from '@ngrx/store';\r\nimport { tap, filter, take, switchMap, catchError } from 'rxjs/operators';\r\n\r\nimport * as fromStore from '../store';\r\nimport { Observable, of } from 'rxjs';\r\nimport { NewsOverviewComponent } from '../containers/news-overview/news-overview.component';\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class NewsGuard {\r\n  constructor(private store: Store<fromStore.ContentState>) {}\r\n\r\n  canActivate(route: ActivatedRouteSnapshot): Observable<boolean> {\r\n    return this.checkStore(route).pipe(\r\n      switchMap(() => of(true)),\r\n      catchError(() => of(false))\r\n    );\r\n  }\r\n\r\n  canDeactivate(\r\n    component: any,\r\n    currentRoute: ActivatedRouteSnapshot,\r\n    currentState: RouterStateSnapshot,\r\n    nextState: RouterStateSnapshot\r\n  ): Observable<boolean> {\r\n    return this.checkDeactivateStore(currentRoute).pipe(\r\n      switchMap(() => of(true)),\r\n      catchError(() => of(false))\r\n    );\r\n  }\r\n\r\n  checkDeactivateStore(route: ActivatedRouteSnapshot): Observable<boolean> {\r\n    return this.store.select(fromStore.getNewsLoaded).pipe(\r\n      tap(loaded => {\r\n        if (loaded) {\r\n          this.store.dispatch(fromStore.ClearNews());\r\n        }\r\n      }),\r\n      filter(loaded => !loaded),\r\n      take(1)\r\n    );\r\n  }\r\n\r\n  checkStore(route: ActivatedRouteSnapshot): Observable<boolean> {\r\n    return this.store.select(fromStore.getNewsLoaded).pipe(\r\n      tap(loaded => {\r\n        if (!loaded) {\r\n          this.store.dispatch(fromStore.LoadNews({ top: undefined, skip: undefined, category: route?.queryParams['category'] }));\r\n        }\r\n      }),\r\n      filter(loaded => loaded),\r\n      take(1)\r\n    );\r\n  }\r\n}\r\n"],
  "mappings": "uJAWA,IAAaA,GAAS,IAAA,CAAhB,IAAOA,EAAP,MAAOA,CAAS,CACpBC,YAAoBC,EAAoC,CAApC,KAAAA,MAAAA,CAAuC,CAE3DC,YAAYC,EAA6B,CACvC,OAAO,KAAKC,WAAWD,CAAK,EAAEE,KAC5BC,EAAU,IAAMC,EAAG,EAAI,CAAC,EACxBC,EAAW,IAAMD,EAAG,EAAK,CAAC,CAAC,CAE/B,CAEAE,cACEC,EACAC,EACAC,EACAC,EAA8B,CAE9B,OAAO,KAAKC,qBAAqBH,CAAY,EAAEN,KAC7CC,EAAU,IAAMC,EAAG,EAAI,CAAC,EACxBC,EAAW,IAAMD,EAAG,EAAK,CAAC,CAAC,CAE/B,CAEAO,qBAAqBX,EAA6B,CAChD,OAAO,KAAKF,MAAMc,OAAiBC,CAAa,EAAEX,KAChDY,EAAIC,GAAS,CACPA,GACF,KAAKjB,MAAMkB,SAAmBC,EAAS,CAAE,CAE7C,CAAC,EACDC,EAAOH,GAAU,CAACA,CAAM,EACxBI,EAAK,CAAC,CAAC,CAEX,CAEAlB,WAAWD,EAA6B,CACtC,OAAO,KAAKF,MAAMc,OAAiBC,CAAa,EAAEX,KAChDY,EAAIC,GAAS,CACNA,GACH,KAAKjB,MAAMkB,SAAmBI,EAAS,CAAEC,IAAKC,OAAWC,KAAMD,OAAWE,SAAUxB,GAAOyB,YAAY,QAAW,CAAE,CAAC,CAEzH,CAAC,EACDP,EAAOH,GAAUA,CAAM,EACvBI,EAAK,CAAC,CAAC,CAEX,yCA5CWvB,GAAS8B,EAAAC,CAAA,CAAA,CAAA,wBAAT/B,EAASgC,QAAThC,EAASiC,UAAAC,WADI,MAAM,CAAA,EAC1B,IAAOlC,EAAPmC,SAAOnC,CAAS,GAAA",
  "names": ["NewsGuard", "constructor", "store", "canActivate", "route", "checkStore", "pipe", "switchMap", "of", "catchError", "canDeactivate", "component", "currentRoute", "currentState", "nextState", "checkDeactivateStore", "select", "getNewsLoaded", "tap", "loaded", "dispatch", "ClearNews", "filter", "take", "LoadNews", "top", "undefined", "skip", "category", "queryParams", "\u0275\u0275inject", "Store", "factory", "\u0275fac", "providedIn", "_NewsGuard"]
}