如何在ngrx中获取旧状态,任何发生故障都需要还原代码

问题描述 投票:0回答:2

示例:让用户位于第5页上,然后用户单击下一页,并且api调用失败,那么我必须返回到第5页,所有过滤器选择均保持不变。并显示数据给用户

angular angular8 ngrx ngrx-store
2个回答
0
投票

您需要使页面请求生效。其操作应具有页码。例如loadPage({page: 6})。然后,您需要在this.http.get().pipe中捕获一个错误。并且因为您知道请求的页面,所以可以分派操作以再次加载第5页。

this.http.get().pipe(
  catchError(() => of(loadPage({page: page -1}))), // <- page var should be available from the parent context of the effect.
)

[当页面为0或-1时不要忘记覆盖情况,也许您只是想失败并向用户显示错误消息。


0
投票

您应该看一下https://github.com/Hityy/ngrx-undo-redo,它提供了撤消和重做的功能。

© www.soinside.com 2019 - 2024. All rights reserved.