【发布时间】:2017-12-04 09:45:57
【问题描述】:
当我从 BehaviorSubject 实例 (t) 订阅共享映射时,只执行第一个订阅。
当原始BehaviorSubject (obj) 发出第二个值时,仅打印最新值,并且两个订阅都已执行。
让我们检查一下我的代码
const obj = new Rx.BehaviorSubject(1)
obj.subscribe(console.log)
const t = obj.map(u => {
console.log("mapped")
return u * 10
}).share()
t.subscribe(x => console.log("subscribe 1 " + x))
t.subscribe(x => console.log("subscribe 2 " + x))
//with the following line un-commented, both subscriptions print out new value
//obj.next(2)
我的预期结果是
1
mapped
subscribe 1 10
subscribe 2 10
但实际结果是
1
mapped
subscribe 1 10
抱歉这个幼稚的问题。有谁能给我解释一下吗?
非常感谢
【问题讨论】:
标签: rxjs behaviorsubject