angular-l10n
Version:
An Angular library to translate messages, dates and numbers
40 lines • 1.07 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import { Injectable } from "@angular/core";
import { ReplaySubject } from "rxjs";
export class Caching {
constructor() {
this.cache = {};
}
/**
* @param {?} key
* @param {?} request
* @return {?}
*/
read(key, request) {
/** @type {?} */
const cached = this.cache[key];
if (cached)
return cached;
/** @type {?} */
const buffer = new ReplaySubject(1);
request.subscribe((value) => buffer.next(value), (error) => {
buffer.error(error);
this.cache[key] = undefined;
}, () => buffer.complete());
/** @type {?} */
const response = buffer.asObservable();
this.cache[key] = response;
return response;
}
}
Caching.decorators = [
{ type: Injectable }
];
if (false) {
/** @type {?} */
Caching.prototype.cache;
}
//# sourceMappingURL=caching.js.map