-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
RFC: Add reducer factory to Store #1724
Comments
To play the devils advocate here, what benefits would This is my list:
|
my list would include the ability to drop Action unions entirely 🎉
We discussed this during Firebase's design review and came to the conclusion that it is not the problem that needs fixing. It would cause a lot more friction with little benefit. On top of that, with action union dropped there would be no 'intended' actions :) |
To tack on here, re: #1734 it may be nice for |
We've discussed this in other places, and was mentioned here with the introduction of action creators. https://blog.angularindepth.com/ngrx-action-creators-redesigned-d396960e46da
This is to open up the discussion about rationale. We've introduced two functions recently:
createAction
andcreateEffect
, both with the purpose of preserving the type-safety of the things they create, while making them easier to use and consume. This lines up with what we already have increateSelector
andcreateEntityAdapter
from Store and Entity respectively. Naturally, next up would becreateReducer
that might make handling creating a reducer to handle state changes somewhat less verbose.What we promote today:
All current proposals include generating a reducer function using a map, array, etc. This does not include or make use of decorators to create them. Examples
https://github.com/reduxjs/redux-starter-kit/blob/master/src/createReducer.ts
https://github.com/cartant/ts-action/blob/master/source/reducer.ts
https://redux.js.org/recipes/reducing-boilerplate#generating-reducers
I still like using the switch statement. Its less magical, somewhat easier to glance at. That being said, at this point I think we're at least looking at having a
createReducer
function. Upfront I'll say that using it with AOT is gonna be a pain because you can't use generated functions within NgModule metadata without workarounds. I've tested this usingts-action
and thecreateReducer
method. You end up having to wrap the generated reducer in an exported function to be compliant.As mentioned, there are AOT workarounds to that approach, but it would add complexity to registering state with generated reducers. Ideally, we want the best of both worlds. Easy to use APIs that provide the same level of type safety and flexibility.
Feel free to comment with other proposals/suggestions.
The text was updated successfully, but these errors were encountered: