Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createAsyncThunk: serializeError option #812

Merged

Conversation

phryneas
Copy link
Member

This would address two requests from #792:

  1. adding a serializeError option to createAsyncThunk
  2. the option to call await dispatch(async(3, { unwrap: true })) and return it with the unwrapped result and otherwise throw an error. So, essentially an inlined version of unwrapResult.

I say would because I'm still not a fan of Nr 2. Even less, after writing all this, tbh.
The amount of code (and especially types) required to support a second way of doing something we already have in the lib makes me uneasy.
Yes, it might be slightly "nicer". But only slightly. And it's a lot of code. And a lot of new behaviour (especially type-wise) that we have to commit to keep running.

So my personal suggestion would be to keep 1. (even though it also does something comparable to rejectWithValue as well) and not merge 2 (no matter the amount of work I put into this).

@phryneas
Copy link
Member Author

Also pinging @nathggns on that one. If you really see any value in this, try to convince me :)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 18, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 32281aa:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration

@phryneas phryneas changed the title cAT: serializeError option & unwrap option at async call createAsyncThunk: serializeError option Nov 27, 2020
@phryneas phryneas force-pushed the asyncThunk-serialize-throw branch 4 times, most recently from ca13a71 to 02c8e04 Compare November 27, 2020 23:27
- name: Prefix `freeze` re-export for pre-3.7 TS versions with @ts-ignore
if: ${{ matrix.ts < 3.7 }}
run: |
sed -i -e "/export .* freeze .* from 'immer'/s/^/\/\/ @ts-ignore\n/" dist/typings.d.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

- name: Prefix `freeze` re-export for pre-3.7 TS versions with @ts-ignore
if: ${{ matrix.ts < 3.7 }}
run: |
sed -i -e "/import .* freeze .* from 'immer'/s/^/\/\/ @ts-ignore\n/" dist/typings.d.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

@markerikson markerikson merged commit 318412e into reduxjs:v1.5.0-integration Nov 27, 2020
@nathggns
Copy link

Thanks for this — sorry I couldn't get around to writing this myself after our conversations. I think this is going to make quite a big difference to removing a lot of complexity in some of our code and I appreciate it.

@OmarShehata
Copy link

Should serializeError be documented on here: https://redux-toolkit.js.org/api/createAsyncThunk ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants