Search code examples
ngrx

dispatch action twice with different props


Good afternoon,

Id like to know if i can dispatch the same action two times with different params.

Doing this, in the effect I receive twice value2:

    this.store.dispatch(xRequest({ filter: value1 }))
    this.store.dispatch(xRequest({ filter: value2 }))

xRequest$ = createEffect(() => {
        return this.actions$.pipe(
            ofType(xRequest),
            concatMap(({ filter }) => {
                return this.http.getResult(filter).pipe(
                    map((result: any) => {
                        return xRequestSuccess({ result, filter })
                    })
                )
            })
        )
    })
export const xRequest = createAction('[x] x request', props<{ filter: IFilter }>())

const xReducer = createReducer(
initialState,
on(xRequest, (state, { filter }) => {
    return { ...state, filter }
})

)


Solution

  • Yes, you can, if there's no mutation it works as you expect.

    The code sample looks fine. Might you share the declaration of IFilter? Then I can test it locally and give you an update.

    In the reducer I would suggest to handle xRequestSuccess instead of xRequest. What is the purpose to handle xRequest there?