feat(demo): add landing page with docs (#1951)

This commit is contained in:
Dmitry Nehaychik 2018-12-26 15:17:57 +03:00 committed by Sergey Andrievskiy
parent 67c9587b87
commit 43cc3a1556
190 changed files with 15425 additions and 21 deletions

View file

@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { publishReplay , refCount } from 'rxjs/operators';
@Injectable()
export class NgxCodeLoaderService {
/**
* Contains cached files by url.
* */
private cache: Map<string, Observable<string>> = new Map();
constructor(private http: HttpClient) {
}
load(path: string): Observable<string> {
const url = this.buildFilePath(path);
const cached = this.cache.get(url);
return cached ? cached : this.buildRequest(url);
}
private buildFilePath(path: string): string {
return `assets/examples/${path}`;
}
private buildRequest(url): Observable<string> {
const request = this.http.get(url, { responseType: 'text' })
.pipe(
publishReplay(1),
refCount(),
);
this.cache.set(url, request);
return request;
}
}