实际上,是因为
first
是的。当您第一次运行函数时,它正在创建流并订阅
BehaviorSubject
是的。当它收到第一个事件时,它将它转发给
行为主体
然后它就完成了
行为主体
是的。第二次运行时
行为主体
已关闭,因此它会立即取消对它的任何新订阅。
在不太了解你的实际目标的情况下,我的建议是
行为主体
在管道的底部,你把它放在顶部。
// You don't actually need the caching behavior yet so just use a `Subject`
private _filters$ = new Subject<Filter>()
// Hook this up to whatever is going to be using these filters
private _pipeline$ = this._filters.pipe(
// Use scan instead mapping back into self
scan((filters, newFilter) => ([...filters, newFilter]), []),
// Store the latest value for new subscribers
shareReplay(1)
);
// Now this method is just pushing into the `Subject` and the pipeline never has to be torn down
addFilter(added: Filter) {
debugger
this._filters$.next(added);
}