NGRX 中的多参考注释

Multi reference notes in NGRX

我有一个应用程序可以保存人物和关于他们的笔记。这些注释可能与许多人相关(例如,注释 1 将出现在人物 1 和人物 3 中)。

我正在使用 NGRX 将我的状态保存在内存中。

现在查看 ngrx 示例应用程序,您可以获得 collection 书籍的一个很好的示例。他们在那里使用一个状态,该状态包含由 bookId 索引的 objects 数组(用于快速检索)。

当 collection 中的项目(在我的例子中是笔记)可能与很多人相关时,人们会怎么做?

我开始用这个人的 uid 索引 objects 的数组:

export interface NoteCollection {
    [uid: string]: Note[];
}

考虑:

 export const getPersonNotes: any = createSelector(getNotes, 
    getSelectedPerson, (notes: any, selectedPersonId: string) => {
      return notes.filter((note: Note) => note.refUid === selectedId);
    });

备选:

有什么建议吗?另一种感觉很奇怪,因为当一半的状态不在 redux 中时,为什么还要使用 ngrx?

您可以这样做来解决注释冗余问题:

interface NoteCollection {
    [noteId: string]: Note[];
}

interface PersonCollection {
    [personId: string]: Person;
}

interface Person {
    noteIds: string[];  // an array of noteIds. 
}