Mohamed Ibrahim
Mohamed Ibrahim

Reputation: 85

I want to select from store after dispatching an action

I need to select from store and check if there is no data then dispatch an action then re-select from store again

this is my current code

      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 } }));
            }
          })
      );

every thing is okay when selecting from store returns a value but when x is undefined it dispatches an action to get the data in this line

else {
              this.store.dispatch(fromSharedStore.SearchIbmers({ search: { q } }));
            }

for now i need to re-select again after getting the data.

Upvotes: 0

Views: 83

Answers (1)

Jamil
Jamil

Reputation: 193

The question is not clear enough. Does your current code works fine now and you need to add a new calling to "re-select" or you have a problem with the mentioned code?

Upvotes: 0

Related Questions