Shamoon
Shamoon

Reputation: 43491

How can I be notified when an ngrx action / effect is complete in Angular5?

In my component, I have

this.uploadService.onUpload({
  some: data
})

In my uploadService, I have

  onUpload($event: SubmissionFileUpload) {
    this.userDetails$ = this.homeService.getUserDetails();
    this.userDetails$.subscribe(
      res => {
        this.userDetails = res;
      });
    this.store.dispatch(new UploadActions.UploadPresignAction(this.userDetails.jwt, $event));
  }

How can my component be notified when the dispatched action is complete?

Upvotes: 1

Views: 2516

Answers (1)

shakeel
shakeel

Reputation: 1695

We designed our app in this way.

Fire an action A -> Reducer or effect X listening to that action. X after finishing the job do the needful or fire another action B(Success case) or action C (failure case) that being listened by reducer or effect Y.

So in your case Reducer or Effect X/Y changes a state in the store that your component is listening to.

In other words, components know only about reading from the store and smart components firing an action too but not taking care of if an action went well or not.

Upvotes: 3

Related Questions