javascript - ngrx on dispatching an action is it possible to not trigger the associated effect?
问题描述
I dispatch my ngrx action with:
store.dispatch(new MyAction(payload));
MyAction has an associated effect. When I dispatch the action the effect fires. Great!
This works as intended. But I only want the effect to fire sometimes. Can you do something like this?
store.dispatch(new MyAction(payload), {triggerEffect: false});
Or do I need to create a 2nd action that is handled exactly the same as MyAction by the reducers and simply not attach an effect to the 2nd Action? I'd rather not go down this route if I can avoid it. Thx
解决方案
假设您只想在有效负载具有特定属性时触发效果。我会做这样的事情。
@Effect() myEffect$ = this.action$
.ofType('ACTION_TYPE')
.filter(action => action.payload.triggerSideEffect)
.map( () => Observable.of({type: "DO_SIDE_EFFECT"}));
推荐阅读
- mysql - 在sql中使用日期检查特定天数
- sql - 由反斜杠过滤器删除的空值
- filesystems - Reed Solomon 擦除编码和复制因子
- linux - “错误的解释器:没有这样的文件或目录”的原因是什么?
- javascript - 异步等待函数被调用
- azure - 从应用服务访问本地服务器
- javascript - rxjs 流以随机时间(200 毫秒 ... 1500 毫秒)发出随机值,如果时间小于 1000 毫秒,则在该流中发出“无数据”值
- ruby-on-rails - Rails 6 未在开发中使用 Sprocket / Assets 重新编译 SCSS
- javascript - POST 的 Ajax 数据响应
- javascript - 在 Nginx JavaScript 中创建表单数据子请求