rxjs#Unsubscribable TypeScript Examples

The following examples show how to use rxjs#Unsubscribable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auto-unsubscribe.ts    From observer-spy with MIT License 5 votes vote down vote up
export function queueForAutoUnsubscribe(subscription: Unsubscribable): void {
  if (isAutoUnsubscribeSet) {
    subscribers.push(subscription);
  }
}
Example #2
Source File: auto-unsubscribe.ts    From observer-spy with MIT License 5 votes vote down vote up
subscribers: Unsubscribable[] = []
Example #3
Source File: subscription-manager.ts    From s-libs with MIT License 5 votes vote down vote up
/**
 * Mixes in {@link SubscriptionManager} as an additional superclass.
 *
 * ```ts
 * class MySubclass extends mixInSubscriptionManager(MyOtherSuperclass) {
 *   subscribeAndManage(observable: Observable<any>) {
 *     this.subscribeTo(observable);
 *   }
 * }
 * ```
 */
// eslint-disable-next-line max-lines-per-function,@typescript-eslint/explicit-function-return-type
export function mixInSubscriptionManager<B extends Constructor>(Base: B) {
  return class extends Base implements Unsubscribable {
    #subscriptions = new Subscription();

    // eslint-disable-next-line max-params
    subscribeTo<T>(
      observable: Observable<T>,
      next?: (value: T) => void,
      error?: (error: any) => void,
      complete?: () => void,
    ): void {
      this.#subscriptions.add(
        observable.subscribe({
          next: next?.bind(this),
          error: error?.bind(this),
          complete: complete?.bind(this),
        }),
      );
    }

    manage(subscription: Subscription): void {
      this.#subscriptions.add(subscription);
    }

    unsubscribe(): void {
      this.#subscriptions.unsubscribe();
      this.#subscriptions = new Subscription();
    }
  };
}
Example #4
Source File: explore.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
stopQueryState = (querySubscription: Unsubscribable) => {
  if (querySubscription) {
    querySubscription.unsubscribe();
  }
}
Example #5
Source File: PanelEditor.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription: Unsubscribable;
Example #6
Source File: PanelChrome.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription: Unsubscribable;
Example #7
Source File: PanelChromeAngular.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription: Unsubscribable;
Example #8
Source File: QueriesTab.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription: Unsubscribable;
Example #9
Source File: VisualizationTab.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription: Unsubscribable;
Example #10
Source File: PanelQueryRunner.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
private subscription?: Unsubscribable;
Example #11
Source File: metrics_panel_ctrl.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
querySubscription?: Unsubscribable;