To accomplish my task, I must first select from the store and verify if there is no data available. If no data is found, I need to dispatch an action and then re-select from the store once again.
Here is the code snippet that I am currently using:
this.subscriptions.add(
this.store
.select(fromSharedStore.getIbmerEntityByQuery({ q }))
.pipe(debounceTime(250))
.subscribe(x => {
if (x) {
this.flatChildren = x.map(v => ({
...v,
name: v.cn ? v.cn[0] : '',
email: v.emailaddress ? v.emailaddress[0] : '',
short_name: v.cn[0],
parent: 'Author',
search_id: v.cn[0],
}));
this.searching = false;
this.loaded = true;
this.changeDetectorRef.markForCheck();
} else {
this.store.dispatch(fromSharedStore.SearchIbmers({ search: { q } }));
}
})
);
Everything works as expected when a value is returned after selecting from the store. However, in cases where 'x' is undefined, an action is dispatched to retrieve the necessary data at the following line of code:
else {
this.store.dispatch(fromSharedStore.SearchIbmers({ search: { q } }));
}
Currently, I require another selection from the store after obtaining the data.