【发布时间】:2020-10-28 20:43:35
【问题描述】:
我可以观察到每 N 秒发出一次值,而且我有。 我想进行第一次发射并在其上触发一个函数。
我有这个代码:
sideEffect = false;
observable$
.pipe(
tap((data) => {
// executing this only for the first emission
if (!sideEffect) {
this.sideEffect(data.props);
sideEffect = true;
}
})
)
.subscribe((data) => {
// process all upcoming emissions
});
有没有办法在不定义任何局部变量的情况下使用 RxJS 运算符使这段代码更好?
【问题讨论】:
-
这能回答你的问题吗? rxjs execute tap only at the first time
标签: rxjs observable