Skip to content

Commit

Permalink
fix(scully-routes.service): fix missing return type (#172)
Browse files Browse the repository at this point in the history
* 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

* Adding extra types to this file.

Co-authored-by: Aaron Frost <hi@frosty.io>
  • Loading branch information
SanderElias and aaronfrost committed Jan 10, 2020
1 parent c1e6bf4 commit 925bcb4
Showing 1 changed file with 8 additions and 9 deletions.
@@ -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;
Expand All @@ -15,18 +16,16 @@ export interface ScullyRoute {
})
export class ScullyRoutesService {
private refresh = new ReplaySubject<void>(1);
available$ = this.refresh.pipe(
available$: Observable<ScullyRoute[]> = this.refresh.pipe(
switchMap(() => this.http.get<ScullyRoute[]>('/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})
);

topLevel$ = this.available$.pipe(
topLevel$: Observable<ScullyRoute[]> = this.available$.pipe(
map(routes => routes.filter((r: ScullyRoute) => !r.route.slice(1).includes('/'))),
shareReplay({refCount: false, bufferSize: 1})
);
Expand All @@ -36,10 +35,10 @@ export class ScullyRoutesService {
this.reload();
}

getCurrent() {
getCurrent(): Observable<ScullyRoute> {
if (!location) {
/** probably not in a browser, no current location available */
return of([]);
return of();
}
const curLocation = location.pathname;
return this.available$.pipe(
Expand All @@ -55,7 +54,7 @@ export class ScullyRoutesService {
);
}

reload() {
reload(): void {
this.refresh.next();
}
}

0 comments on commit 925bcb4

Please sign in to comment.