JhiEventManager是允许多个订阅,还是应该对每个事件都有专门的订阅?JhiEventManager的well ()方法也会处理多个订阅吗?
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);
}
}事先非常感谢
发布于 2020-10-16 13:13:55
基于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:
对一个订阅的取消订阅()的调用可以取消订阅多个订阅。您可以通过将一个订阅“添加”到另一个订阅中来做到这一点:
https://stackoverflow.com/questions/64371612
复制相似问题