【问题标题】:How do I synchronize local store with Firestore using ngrx entity?如何使用 ngrx 实体将本地存储与 Firestore 同步?
【发布时间】:2020-02-16 06:34:02
【问题描述】:

我正在使用 NgRx 和 Firestore,我正在尝试想办法让本地存储与 Firestore 集合保持同步。我有一个可观察的设置,在更新 firestore 集合时会触发,但在我的减速器中,我不确定如何使用 NgRx 实体适配器将存储中的内容替换为新数据。我已经尝试过 addMany 和 upsertMany 但如果在用户刷新之前删除项目,它们不会删除它。

我的 loadUsers Success Action 的 Reducer 如下所示

on(fromBatch.loadBatchesSuccess, (state: any, action: any) => ({...userAdapter.upsertMany(action.users, state), loaded: true, loading: false}))

【问题讨论】:

    标签: angular google-cloud-firestore ngrx ngrx-entity


    【解决方案1】:

    原来它一直就在我面前。 userAdapter.addAll() 将使用来自数据库的数组替换当前状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      相关资源
      最近更新 更多