Skip to content

Instantly share code, notes, and snippets.

@sebastieno
sebastieno / httpRequestLocker.js
Created March 27, 2016 06:26
Http request locker for AngularJS
var IS;
(function (IS) {
var HttpRequestLocker = (function () {
function HttpRequestLocker($http, $q, requestConfig, successCallback) {
this.$http = $http;
this.$q = $q;
this.requestConfig = requestConfig;
this.successCallback = successCallback;
}
HttpRequestLocker.prototype.execute = function () {
@sebastieno
sebastieno / cacheable.ts
Last active May 25, 2018 09:59
Helper function which cache an observable result
import { Observable, ReplaySubject } from 'rxjs';
export function cacheable<T>(observable: Observable<T>): Observable<T> {
const replaySubject = new ReplaySubject<T>(1);
observable.subscribe(x => replaySubject.next(x), x => replaySubject.error(x), () => replaySubject.complete());
return replaySubject.asObservable();
}
import { Observable } from 'rxjs';
import { finalize, share } from 'rxjs/operators';
export function ReusePendingObservable() {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
const pendingObservablePropertyName = `__pendingObservable${propertyKey}`;
target[pendingObservablePropertyName] = null;
descriptor.value = function (...args: any[]) {