react-redux-form
react-redux-form copied to clipboard
Decoupling UI definition from state definition
Is there a way for the model referenced in Form to not be predefined in createForms/combineForms?
Current Situation:
const store = createStore(combineForms({
user: initialUser,
}));
...
<Form model="user">
...
</Form>
Desired Situation:
const store = createStore(combineForms());
...
<Form model="user" initialModel={initialUser}>
...
</Form>
Currently, specific definitions of UI components are directly coupled with a 1-to-1 definition in state. There will always need to be a reducer in the state, but all the concerns of this library are UI related except having state via redux. There's no reason to have the UI's form model be defined away from the UI. Form could check the state and it's component-defined default to determine what the current model is. The reducer can simply populate a specific model when something actually occurs.
I see two issues with this:
- Two different forms use the same model. This can be mitigated. Either each could define a default (maybe they'd be different?) or you could still put a model definition in the state as we currently do.
Formwould know to use the stored model, it's component default (if it's defined), and the state's default (if it's defined), in that order of priority. - Something outside of the usual Form flow relies on the model existing. Those use cases can check for existence or the state could still have a definition for the model in there, if the use case fits doing that.
Depending on the use case, putting the model definition in the state takes a UI concern and puts it somewhere else. And in other use cases, that's the right call. Supporting both allows a whole concern to live in one place rather than in two separate places. This essentially adds support for dynamically defined models.
It also reduces the learning curve of react-redux-form substantially. If you enter a codebase with knowledge of react, everything is immediately clear. Currently, a new developer eventually has to open the documentation to understand where the defaults are coming from.
I'm in a somewhat similar boat and have posted my issue here, in case that helps.