wait two async calls to complete using NGXS dispatch

Discussão em 'Angular' iniciado por carlos, Novembro 28, 2024.

  1. carlos

    carlos Guest

    When you pass an array of actions (both an async call to an API) to the dispatch method in NGXS, does the dispatch method in NGXS internally use the forkJoin operator from RxJS to process the actions?

    Given the example below, will the map operator be triggered when both actions complete?

    @Action(User.Get)
    public get(ctx: StateContext<UserStateInterface>) {
    return ctx.dispatch([new User.GetUserAccount(), new User.GetUserAddress()])
    .pipe(
    map(([userAccount, userAddress]) => {
    return {
    userAccount: userAccount,
    userAddress: userAddress
    }
    })
    )
    }


    Is there a better aproach?

    Continue reading...

Compartilhe esta Página