【发布时间】:2017-10-04 08:37:52
【问题描述】:
我正在尝试在我使用 @ngrx/store 的 Angular 应用程序中实现撤消操作。我想要做的是调度 UNDO 动作,然后一旦动作被处理,数据已经被 reducer 更新并被推送到 store,我想对更新的数据做一些事情。
这就是我目前正在尝试解决的问题。基本上,因为 records$ 来自 BehaviorSubject,所以我最初会在订阅时获得一个值。然后我发送操作并等待更新通过。必须有更好的方法,对吧?
undoRecords() {
let count = 1;
// The records$ observable comes from the ngrx store
let obs = this.records$.take(2).subscribe(records => {
if(count == 1) {
this.store.dispatch({type: UNDO_RECORDS, payload: undefined}); // this will change the records
count++;
}
else {
this.someService.doSomething(records);
}
});
}
【问题讨论】:
标签: javascript angular redux rxjs ngrx