-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
replaceReducer eliminates enhancer #4127
Comments
That isn't an enhancer. It's just a wrapper function on |
Mmm... it looks like a valid enhancer in terms of syntax, at least. But yeah, the real point of an enhancer is to override one of the actual store methods. All this is doing is wrapping the original reducer function. So yes, if you replace that reducer, you've... replaced the reducer :) |
This is actually a bug in your enhancer. If your enhancer messes with the reducer, it needs to re-implement the |
P.S. @timdorr @markerikson It would be great to get #3776 (and #3772 🤞) merged, so that the folks using TypeScript will catch this bug in their enhancers sooner. |
@antontsvil Here's a fiddle showing how it should be implemented: https://jsfiddle.net/nk3bqcfv/. |
@Methuselah96 the issue with those PRs is that they're against In order to actually be releasable any time soon, we'd need updates made to the TS typedefs in the |
@markerikson I understand, I can re-implement #3776 for |
That's sorta the issue - we're not sure what the breaking changes are, it's likely the types would benefit from more changes, and there's not enough reason to push it live and cause churn in the ecosystem atm :) The conversion work was actually done in... late 2019, I think? And it's been sitting there in Basically, the community contributed the work after we asked for it, and then the whole effort just stalled. There's also some tie-in to Basically, what's live in 4.x right now works well enough, and especially with RTK now being the default, that there just isn't enough pressing reason to try to push through a 5.0 release any time soon. |
Yeah, makes sense. Sorry to derail this issue. FWIW I have annoying casts in my code that could be removed if reduxjs/redux-thunk#255 were released. It's frustrating seeing completed work from 2 years ago that fixes issues that I'm dealing with that has no timeline for a release. (I could potentially augment the interface, but I was kinda hoping it would just get released at some point.) These situations make DT seem a lot more appealing so the types lifecycle don't have to be as tightly coupled to the JS releases, but I understand that decision has a lot of pros/cons and has been hashed and rehashed many times and frankly I'm not sure which I prefer. But I also understand that keeping churn down is valuable, so thanks for the hard work in that regard. |
(And I'm also not on RTK yet, as noted in reduxjs/redux-thunk#299 which contributes to the problem on my end.) |
Yeah, I'd like to see 5.0 released too, but it needs some meaningful attention to figure out what other types changes might be necessary, and given everything else going on it's just at the bottom of the priority list for us right now. If someone else with serious TS knowledge wants to help us out and try to push the current TS port forward by evaluating it and seeing where things stand and how it can be improved, I'd love it. |
Opened up #4129 to cover that topic. |
Thanks for pointing out what I figured was the initial issue, was that I wasn't understanding enhancers 100%. And thank you for your helpful solution @Methuselah96. I do have to note that I had to modify it because your solution never actually uses This seems to fix my issue (enhancer which supports replaceReducer AND operates using the new reducer) but I'm not sure if it's an antipattern, looks a bit weird tbh. Just leaving the solution here for anyone else encountering the same problem. |
Good catch. It is a bit odd looking. I would go with a slightly different implementation to avoid the |
What is the current behavior?
If you use an enhancer when creating your Redux store, the first subsequent call to
replaceReducer
on the store seems to remove the enhancer.Steps to Reproduce
Run this JSFiddle and observe the console
The enhancer will stop logging actions following the call to
replaceReducer
What is the expected behavior?
Not sure if what I'm reporting is not a bug and I'm misunderstanding the usage of enhancers; But seems to me enhancers should persist for the lifetime of the store, regardless of which reducers are being used.
The text was updated successfully, but these errors were encountered: