【发布时间】:2018-08-16 12:10:08
【问题描述】:
考虑这个来自 Angular 6 组件的代码:
class AppComponent {
subject = new Subject<any>();
one = this.subject.pipe(share(), tap(e => log('one emits')));
two = this.one.pipe(tap(e => log('two emits')));
three = this.one.pipe(delay(500), tap(e => log('three emits')));
ngOnInit() {
this.two.subscribe(e => log('two received'));
this.three.subscribe(e => log('three received'));
this.subject.next();
}
}
ngOnInit 执行时,会记录以下内容:
一个发射
两次发射
收到两个
一个发射
三个发射
收到三个
我不明白:为什么one 会发出两次?管道中的share 运算符不应该使two 和three 订阅相同的共享源吗?
【问题讨论】: