rx-smart-subscribe
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

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();
  }
}

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i rx-smart-subscribe

    Weekly Downloads

    8

    Version

    0.0.4

    License

    none

    Unpacked Size

    13.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • enesien