lundi 1 mars 2021

How to wait for two actions in NGXS

I am trying to execute some code after two actions completed in Angular using NGXS. The code would look something like this:

this._subscription.add(
      this._actions$
        .pipe(
          ofActionCompleted(Actions.action1),
          map(({ action1 }) => action1 as Actions.action1),
          ofActionCompleted(Actions.action2),
          map(({ action2 }) => action2 as Actions.action2)
        )
        .subscribe({
          next: ({ payload1, payload2 }) => {
              // execute code using payload1
              // execute code using payload2
          }
        })
    );

What would be the proper way to do this?




Aucun commentaire:

Enregistrer un commentaire