From 1ffccaf52360dea58cf396d31a80742487e8cb5e Mon Sep 17 00:00:00 2001 From: Sander Elias Date: Fri, 10 Jan 2020 08:12:42 +0100 Subject: [PATCH 1/2] fix(scully-routes.service): fix missing return type Put in the correct type for the return of the getCurrent function. In some cases TS inferrrence is off otherwise closes #171 --- .../src/lib/route-service/scully-routes.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts index 8fc0f7be1..e65a02dbf 100644 --- a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts +++ b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts @@ -1,7 +1,8 @@ import {HttpClient} from '@angular/common/http'; import {Injectable} from '@angular/core'; -import {of, ReplaySubject} from 'rxjs'; +import {of, ReplaySubject, Observable} from 'rxjs'; import {catchError, shareReplay, switchMap, map, tap} from 'rxjs/operators'; +import {HandledRoute} from 'dist/scully'; export interface ScullyRoute { route: string; @@ -18,9 +19,7 @@ export class ScullyRoutesService { available$ = this.refresh.pipe( switchMap(() => this.http.get('/assets/scully-routes.json')), catchError(() => { - console.warn( - 'Scully routes file not found, are you running the in static version of your site?' - ); + console.warn('Scully routes file not found, are you running the in static version of your site?'); return of([] as ScullyRoute[]); }), shareReplay({refCount: false, bufferSize: 1}) @@ -36,10 +35,10 @@ export class ScullyRoutesService { this.reload(); } - getCurrent() { + getCurrent(): Observable { if (!location) { /** probably not in a browser, no current location available */ - return of([]); + return of(); } const curLocation = location.pathname; return this.available$.pipe( From be9089efad357604ef0148532a9ffee80e6f0300 Mon Sep 17 00:00:00 2001 From: frosty Date: Fri, 10 Jan 2020 00:39:34 -0700 Subject: [PATCH 2/2] Adding extra types to this file. --- .../ng-lib/src/lib/route-service/scully-routes.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts index e65a02dbf..21718282c 100644 --- a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts +++ b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts @@ -16,7 +16,7 @@ export interface ScullyRoute { }) export class ScullyRoutesService { private refresh = new ReplaySubject(1); - available$ = this.refresh.pipe( + available$: Observable = this.refresh.pipe( switchMap(() => this.http.get('/assets/scully-routes.json')), catchError(() => { console.warn('Scully routes file not found, are you running the in static version of your site?'); @@ -25,7 +25,7 @@ export class ScullyRoutesService { shareReplay({refCount: false, bufferSize: 1}) ); - topLevel$ = this.available$.pipe( + topLevel$: Observable = this.available$.pipe( map(routes => routes.filter((r: ScullyRoute) => !r.route.slice(1).includes('/'))), shareReplay({refCount: false, bufferSize: 1}) ); @@ -54,7 +54,7 @@ export class ScullyRoutesService { ); } - reload() { + reload(): void { this.refresh.next(); } }