首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JhiEventManager多订阅

JhiEventManager多订阅
EN

Stack Overflow用户
提问于 2020-10-15 12:30:42
回答 1查看 292关注 0票数 1

JhiEventManager是允许多个订阅,还是应该对每个事件都有专门的订阅?JhiEventManager的well ()方法也会处理多个订阅吗?

代码语言:javascript
运行
复制
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);
    }
  }

事先非常感谢

EN

Stack Overflow用户

回答已采纳

发布于 2020-10-16 13:13:55

基于JhiEventManager的当前实现,可以处理一个订阅中的内容

代码语言:javascript
运行
复制
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

对一个订阅的取消订阅()的调用可以取消订阅多个订阅。您可以通过将一个订阅“添加”到另一个订阅中来做到这一点:

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64371612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档