@ngxs-labs/data / @angular-ru/ngxs one to many relationship architecture

Viewed 71

Does anyone have a example of using NGXS or event better @ngxs-labs/data package which is now located at @angular-ru/ngxs with related data coming from N different API calls but which need to be queried with a single ID ?

The parent / main model that i received from the back end looks like this :

Application
-Id
-Name
-Etc...

But on the same page as the application page, i also have to query commits or logs that are received like this from the API :

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

My problem is to be able to select those commits or logs given an application id with the benefits of still using entities state operators helpers (like in any entity state manager like @ngrx/entity package) from NGXS data like addOne, removeOne etc etc... I do not want to fall into the trap of having to do all those operations by myself like i did in the past with spread operators and stuff.

Currently my commit state looks like this :

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

How would you architecture the store given such models, knowing that the application models has more than 20 API calls related to it ?

0 Answers
Related