rxjs - 将 WithLatestFrom 中的值传递给另一个运算符 - Rxjs,Ngrx 效果
问题描述
我有这个 ngrx 效果,我想使用我所在州的数据withLatestFrom
。
$loadProduct = createEffect(() =>
this.actions$.pipe(
ofType(fromActions.loadProduct),
withLatestFrom(this.store.select(fromSelectors.debounceTime)),
delay(debounceTime), // how can I get the debounceTime value up here?
map(_ => fromActions.foo())
)
)
如何在延迟范围内获得这个 debounceTime 值?
解决方案
由于delay
is just delayWhen(() => timer(duration));
,我认为您可以使用它delayWhen
来解决问题:
$loadProduct = createEffect(() =>
this.actions$.pipe(
ofType(fromActions.loadProduct),
withLatestFrom(this.store.select(fromSelectors.debounceTime)),
delayWhen(([, debounceTimeVal]) => timer(debounceTimeVal)),
map(_ => fromActions.foo())
)
)
作为旁注,delayWhen
这只是一个有趣的用例mergeMap
:而不是发出内部值,而是发出外部值。
推荐阅读
- git - 在我使用 VS Code 进行 Git Push/Pull 之前,无法看到 Vue.JS 开发服务器中的变化
- javascript - 鼠标在 HTML 文件中的颜色
- google-cloud-platform - 将数据从存储加载到 bigquery 时解析数据类型时出错
- r - R中小于87的孪生素数
- python - 我的代码正确执行布尔操作并限制操作中定义的变量值时遇到问题
- sql - SQL 每周数据更新
- javascript - 根据用户输入显示 Div
- html - 如何完美地水平对齐标志和导航栏?
- javascript - JavaScript 中的浏览器特定行为和触发级别
- r - 使用 R 函数创建序列