When using ngrx, I am able to retrieve two distinct data sets from storage.
private getCatalog() {
this.catalogStore.select(CatalogStoreSelectors.selectAllCatalogsLoadSuccess)
.pipe(
takeWhile(() => this.alive),
take(1),
filter(loadSuccess => !loadSuccess),
tap(() => this.catalogStore.dispatch(new CatalogStoreActions.LoadAllAction())),
).subscribe();
this.catalogs$ = this.catalogStore.select(CatalogStoreSelectors.selectAllCatalogs);
}
The catalog$
will be of type Observable<ViewCatalog[]>
, representing the first data set.
view-catalog.ts
export declare class ViewCatalog {
code: string;
title: string;
lastModified: string;
}
Additionally, for each of the catalog entries, it is possible to request its individual items by using the respective catalog code.
private getCatalogItems(catalogCode: string) {
this.catalogStore.dispatch(new CatalogStoreActions.GetCatalogItems({catalogCode: catalogCode}));
this.catalogItemsStore.select(CatalogItemStoreSelector.selectLoadingByCatalogSuccess)
.pipe(
takeWhile(() => this.alive),
take(1),
filter(loadSuccess => !loadSuccess),
tap(() => this.catalogItemsStore.dispatch(new CatalogItemStoreAction.LoadByCatalog({catalogCode: catalogCode}))),
).subscribe();
this.catalogItems$ = this.catalogItemsStore.select(CatalogItemStoreSelector.selectByCatalogCode(catalogCode));
}
This represents the second data set.
public catalogItems$: Observable<CatalogItem[]>;
CatalogItem.ts
export class CatalogItem {
constructor(public code: string,
public catalogCode: string,
public title: string,
public data: object) {
}
}
I am looking to merge all this data into a single flat list structure as showcased below:
[
catalog: {
code: "Code 1",
title: "Catalog title 1",
lastModified: "",
parent: null,
hasChildren: true
}
catalog-item: {
code: "CatalogItem 1",
catalogCode: "Code 1",
parent: "Code 1",
hasChildren: false,
title: "CatalogItem title 1"
},
catalog-item: {
code: "CatalogItem 2",
catalogCode: "Code 1",
parent: "Code 1",
hasChildren: false,
title: "CatalogItem title 2"
},
catalog: {
code: "Code 2",
title: "Catalog title 2",
lastModified: "",
parent: null,
hasChildren: true
},
catalog-item: {
code: "CatalogItem 1",
catalogCode: "Code 2",
parent: "Code 2",
hasChildren: false,
title: "CatalogItem title 1"
},
catalog-item: {
code: "CatalogItem 2",
catalogCode: "Code 2",
parent: "Code 2",
hasChildren: false,
title: "CatalogItem title 2"
},
]
Assistance on achieving this would be greatly appreciated!