Roque Orts
Roque Orts

Reputation: 360

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

)

Upvotes: 0

Views: 44

Answers (1)

satanTime
satanTime

Reputation: 13539

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?

Upvotes: 1

Related Questions