Allow providing custom slice creators when calling createSlice#4348
Allow providing custom slice creators when calling createSlice#4348EskiMojo14 wants to merge 26 commits intoentity-methods-creatorfrom
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
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 c7c88f2:
|
ed623ac to
11b873c
Compare
| reducers: (create) => ({ | ||
| addLoader: create.loader({}), | ||
| }), |
There was a problem hiding this comment.
Could you please explain the differences between this and the traditional builder pattern? Also, would you mind clarifying the purpose of the custom loadCreator?
There was a problem hiding this comment.
what traditional builder pattern are you referring to?
There was a problem hiding this comment.
My reference was to the action builder pattern in Redux Toolkit, where we use methods like addCase and addMatcher in createSlice to dynamically build actions and reducers. With this PR allowing custom slice creators, I wonder if there are potential issues when multiple creators are provided for the same slice. Could this lead to naming conflicts or unexpected behavior if two creators define overlapping functionality for the same action or state? I might be missing something though haha
There was a problem hiding this comment.
extraReducers has a different builder pattern, because we don't need a return value from it. for reducers we need the returned object to infer slice actions and case reducers from, similar to how you're required to return build.query when building an RTKQ API.
There's handling for overlaps, this is the third PR in a set of three. See #3837 for the base logic.
Uh oh!
There was an error while loading. Please reload this page.