首页 > 解决方案 > @ngxs-labs/data / @angular-ru/ngxs 一对多关系架构

问题描述

有没有人有使用 NGXS 或事件更好的示例 @ngxs-labs/data 包,现在位于 @angular-ru/ngxs 相关数据来自 N 个不同的 API 调用,但需要使用单个 ID 进行查询?

我从后端收到的父/主模型如下所示:

Application
-Id
-Name
-Etc...

但是在与应用程序页面相同的页面上,我还必须查询从 API 接收到的提交或日志:

Commits
-Id
-ContributorName
-Etc...
Logs
-Id
-Format
-Etc...

我的问题是能够在给定应用程序 ID 的情况下选择那些提交或日志,其好处是仍然使用来自 NGXS 数据等的实体状态运算符助手(如在任何实体状态管理器中,如 @ngrx/entity 包addOneremoveOne......我不想陷入不得不自己完成所有这些操作的陷阱,就像我过去对扩展运算符和其他东西所做的那样。

目前我的提交状态如下所示:

export interface EntityStateDictionnary<T> {
  [key: string]: Dictionary<T>
}
const applicationCommitsInitialState: EntityStateDictionnary<ApplicationCommit[]> = {
  commits: null,
}
  this.patchState({
    commits: {
      ...this.getState().commits,
      [`${appId}`]: applicationCommits,
    },
  })

知道应用程序模型有 20 多个与之相关的 API 调用,您将如何构建给定这些模型的商店?

标签: angularreduxngxs

解决方案


推荐阅读