JhiEventManager 多个订阅

JhiEventManager multiple subscriptions

JhiEventManager 是否允许多个订阅,或者我应该为每个事件单独订阅吗? destroy() JhiEventManager 的方法是否也会处理多个订阅?

export class SomeComponent implements OnInit, OnDestroy {
  eventSubscriber?: Subscription;
 
  constructor(protected eventManager: JhiEventManager) {
  }

  ngOnInit(): void {
    this.registerChanges();
  }

  registerChanges(): void {
    this.eventSubscriber = this.eventManager.subscribe('first EntityListModification', () => this.someaction());
    // ??? chain this to the same eventSubscriber ???
    this.eventManager.subscribe('secondEntityListModification', () => this.someaction());
  }

  ngOnDestroy(): void {
    if (this.eventSubscriber) {
      this.eventManager.destroy(this.eventSubscriber);
    }
  }

非常感谢

基于 current implementation of JhiEventManager 可以一次处理内容 订阅:

export class SomeComponent implements OnInit, OnDestroy {
  subscription?: Subscription;

  constructor(protected eventManager: JhiEventManager) {}

  ngOnInit(): void {
    this.registerAllEvents();
  }

  registerAllEvents(): void {
    this.subscription = this.eventManager.subscribe('event1', () => this.loadAll());
    this.subscription.add(this.eventManager.subscribe('event2', () => this.loadAll()));
    this.subscription.add(this.eventManager.subscribe('event3', () => this.loadAll()));
    ...
    this.subscription.add(this.eventManager.subscribe('eventN', () => this.loadAll()));
  }

  ngOnDestroy(): void {
    if (this.subscription) {
      this.eventManager.destroy(this.subscription);
    }
  }

详细说明请参考https://rxjs-dev.firebaseapp.com/guide/subscription

call to an unsubscribe() of one Subscription may unsubscribe multiple Subscriptions. You can do this by "adding" one subscription into another: