如何管理处于 Redux/ngrx 状态的实体?

How to manage entities in Redux/ngrx state?

我们一直在使用 ngrx 在我们的应用程序中进行状态管理。由于 ngrxredux 遵循相同的状态管理原则,所以这个问题对两者都适用。

对于状态管理,我们一直在使用 normalizr 库来规范化来自服务器的任何传入数据。关于如何在不同状态切片之间共享 entities,我们有以下问题。例如,

// app state
{
  sliceA: sliceAState, // corresponds to feature module A, handled by reducerA
  sliceA: sliceBState, // corresponds feature module B, handled by reducerB
}

sliceA 和 sliceB 都包含一个名为 locationlist 特定实体。现在这里的正确方法是什么

谢谢。

Maintain the same state slice but this would require cross referencing across modules - also note that we use lazy loading to load different feature modules.

为了遵守 single source of truth 的原则,这将是您最好的选择。

如果您开始在多个位置维护相同的数据,则每次数据更改时都需要更新多个数据源。如果只有一个真实来源,您就可以消除商店中出现不一致的可能性。