projects/maplander/core/src/lib/interceptors/state/server-state.interceptor.ts
Methods |
constructor(_transferState: TransferState)
|
||||||
Parameters :
|
intercept | |||||||||
intercept(req: HttpRequest
|
|||||||||
Parameters :
Returns :
Observable<HttpEvent<any>>
|
import {tap} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http';
import { TransferState, makeStateKey } from '@angular/platform-browser';
import { Observable } from 'rxjs';
@Injectable()
export class ServerStateInterceptor implements HttpInterceptor {
constructor(
private _transferState: TransferState,
) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(tap(event => {
if (event instanceof HttpResponse) {
this._transferState.set(makeStateKey(req.url), event.body);
}
}));
}
}