rx-smart-subscribe
v0.0.4
Published
Simple class to help prevent subscribing to an observable more than once.
Downloads
4
Readme
RxSmartSubscribe
Simple class to help prevent subscribing to an observable more than once.
Usage
Use in your DI class to act as a cache
In this example, this.$http.get(...) will only ever be subscribed to once, yet getStaticOptions() will always return an observable with the response, even if getStaticOptions() is subscribed to many times in quick succession.
class SomeSingleton {
private readonly cache = new SmartSubscribe(this.$http.get(...));
public getStaticOptions() {
return this.cache.go();
}
}
Or if you don't know the exact source on instantiation
class SomeSingleton {
private readonly cache = new SmartSubscribe();
public getStaticOptions(arg: string) {
this.cache.init(this.$http.get(arg));
return this.cache.go();
}
}