mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-17 16:00:14 +01:00
feat: docs app
This commit is contained in:
parent
713aff561e
commit
2129689f98
203 changed files with 15927 additions and 5 deletions
39
docs/app/@theme/services/code-loader.service.ts
Normal file
39
docs/app/@theme/services/code-loader.service.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue