immer-adapter icon indicating copy to clipboard operation
immer-adapter copied to clipboard

dispatch in state

Open chestongo opened this issue 4 years ago • 0 comments

For the @ImmutableContext() you can use setState, but if you want to use dispatch as well... how do you combine this?

  @Action(SetAutocompleteRequest, { cancelUncompleted: true })
  @ImmutableContext()
  setAutocompleteRequest({setState, dispatch}: StateContext<ITrialState>, {payload}: SetAutocompleteRequest) {
    return this.autocompleteService.postAutocomplete(payload, 5).pipe(
      tap(response => {
        setState((state: ITrialState) => {
          state.autocompleteRequest = {...payload};
          return state;
        });
        // dispatch(
        //   new SetAutocompleteResponse(response)
        // );
      })
    )
  }

chestongo avatar Nov 11 '20 13:11 chestongo