-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add idGenerator
option to createAsyncThunk
(#743)
#976
Add idGenerator
option to createAsyncThunk
(#743)
#976
Conversation
Deploy preview for redux-starter-kit-docs ready! Built with commit 62d1deb https://deploy-preview-976--redux-starter-kit-docs.netlify.app |
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 62d1deb:
|
idGenerator
option to createAsyncThunk
(#743)idGenerator
option to createAsyncThunk
(#743)
* Make `idGenerator` description consistent with other sections of docs for `createAsyncThunk` * Re-arrange tests for `idGenerator`
docs/api/createAsyncThunk.mdx
Outdated
@@ -89,6 +89,7 @@ An object with the following optional fields: | |||
|
|||
- `condition`: a callback that can be used to skip execution of the payload creator and all action dispatches, if desired. See [Canceling Before Execution](#canceling-before-execution) for a complete description. | |||
- `dispatchConditionRejection`: if `condition()` returns `false`, the default behavior is that no actions will be dispatched at all. If you still want a "rejected" action to be dispatched when the thunk was canceled, set this flag to `true`. | |||
- `idGenerator`: a function to use when generating the `requestId` for the request sequence. Defaults to use [nanoid](https://www.npmjs.com/package/nanoid). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋ Let's point this to ./otherExports.mdx#nanoid
instead, and maybe also tweak the wording of the nanoid
paragraph to say it's the "default" instead of "automatically used"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both points now addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised I made a sentence for the nanoid
description incorrect when I adjusted it, but tweaked it to make sense again this time.
src/createAsyncThunk.ts
Outdated
@@ -392,7 +399,7 @@ If you want to use the AbortController to react to \`abort\` events, please cons | |||
arg: ThunkArg | |||
): AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> { | |||
return (dispatch, getState, extra) => { | |||
const requestId = nanoid() | |||
const requestId = (options?.idGenerator || nanoid)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋ We can use nullish coalescing here instead of ||
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exactly are you thinking? As in options?.idGenerator?.() || nanoid()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(options?.idGenerator ?? nanoid)()
just swapping ||
for ??
. same behavior, slightly more semantically correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry just realised you said nullish coalescing (??). Definitely makes more sense, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just have a few comments.
docs/api/createAsyncThunk.mdx
Outdated
@@ -89,6 +89,7 @@ An object with the following optional fields: | |||
|
|||
- `condition`: a callback that can be used to skip execution of the payload creator and all action dispatches, if desired. See [Canceling Before Execution](#canceling-before-execution) for a complete description. | |||
- `dispatchConditionRejection`: if `condition()` returns `false`, the default behavior is that no actions will be dispatched at all. If you still want a "rejected" action to be dispatched when the thunk was canceled, set this flag to `true`. | |||
- `idGenerator`: a function to use when generating the `requestId` for the request sequence. Defaults to use [nanoid](https://www.npmjs.com/package/nanoid). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `idGenerator`: a function to use when generating the `requestId` for the request sequence. Defaults to use [nanoid](https://www.npmjs.com/package/nanoid). | |
- `idGenerator`: a function to use when generating the `requestId` for the request sequence. Defaults to use [nanoid](./otherExports.mdx#nanoid). |
We don't use all of nanoid, so we should just link back specifically to what we inline and re-export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but the link should go to the sibling Markdown file instead of the website directly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm fired 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now addressed
I'm struggling to understand why the
As far as I'm aware I added Does anyone have any insight as to what might be causing this error? Have I missed something somewhere? |
I think I saw the compressed size check also failing on some TS type changes with one of my other PRs this week. Not sure what's causing that. |
* Link to local documentation for nanoid rather than npm package * Update local docs for `nanoid` to reflect changes to `createAsyncThunk` options * Use nullish coalescing operator when getting requestId generator
This line in the cAT docs will also need to be updated:
|
Eh, I think that line's fine. There's still a |
idGenerator
option to createAsyncThunk
(#743)idGenerator
option to createAsyncThunk
(#743)
Regarding the Regarding the Regarding comment threads, do you folks prefer:
|
Y'know what, this looks good. Let's put it in. |
Closes #743
This PR adds an optional
idGenerator
option to thecreateAsyncThunk
options to allow specifying how request IDs are generated rather than using nanoid.