-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Re-export cast utility functions from immer #2308
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
Re-export cast utility functions from immer #2308
Conversation
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 49e1882:
|
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Yo! Any particular reason we need to re-export these specifically? |
They're necessary to make reducers type-safe in the situations mentioned here (most commonly if there's a |
I can't think of a situation where I would use |
Mark, Matt and I just discussed this a bit - we feel like this just doesn't happen often enough to add it as a re-export, and if it actually happens, adding |
How much it's used is highly dependent on how often one uses read-only arrays in their state. For me this comes up quite frequently since I use read-only arrays for all the arrays that are in state, which means any usage of the part of state that includes arrays needs to use |
I'd be happy to just cut it down to just re-exporting |
@markerikson @phryneas Any more thoughts on what the concerns are for adding the export? Am I right in thinking that most people don't run into this because they're not using readonly arrays? I made a TS playground demonstrating the issue. If you make the array non-readonly you'll see that it makes it possible to mutate it when using the state somewhere else in the app. I run into the need to use |
It's a combination of a few things:
|
Yeah, I get that, but this function is so simple that it seems like the danger of re-exporting it and it causing problems in the future it is extremely low. Out of curiosity, do you use readonly arrays when typing arrays that live in state? |
It's not about the complexity of the function - but what if There are things that are central to RTK where we can't be picky, and then there is stuff like this where risks like that have to be weighed a bit more. Also, it's not free - if the consumer's bundler doesn't tree-shake well, it adds another 10 bytes to the library - no matter if actually used or not. |
Honestly, you're the first person I've seen doing that. I get that it could be a "better practice", but with |
Seems like you would need a major release in that case whether you exported
To each their own, I agree that the ecosystem does not support readonly arrays well. Thanks for you responses, I appreciate your time. |
We have gone from immer 2 or so to currently immer 9 without the need for a bump - because the features we use & expose of it are stable "enough" (not 100% unfortunately, but nothing really breaking). But the more we start pulling in external dependencies that we have no control of (afaik we control every other dependency), the flakier it gets. That's just why we have a bad feeling adding more - especially since this is essentially a type helper and those patterns do change over time. |
As it was, when Immer changed its built-in "enable the ES5 fallback by default" behavior to make it be a plugin instead, we had to switch to calling |
Yeah, I understand that re-exporting any function from a dependency inherently increases risk and so its just a judgment call of whether the likelihood of the function changing is worth the gain in exporting the function. I see both the likelihood of the function changing and the impact that it would have if it did change to be very small, so it seems worth it to me, but it probably always seems worth it to the person who "really needs this one feature pls." :) It is not hard for me to implement the function myself since RTK (thankfully) already exports the Again, I appreciate your time and responses. |
No description provided.