Description
Sometimes general modifications of JSON Forms behavior would be useful. For example to listen on update events and to modify errors and data before they are set.
Solution
Similar to the middleware concept in Redux, the JsonForms component could accept a middleware function.
Conceptually the API could look like this
const loggerMiddleware = (previousState, dispatch, action) => {
console.log('dispatching', action)
// here you could modify the action or dispatch multiple ones
const nextState = dispatch(previousState, action)
// here you could modify the resulting state
console.log('next state', nextState)
return nextState;
}
On JSON Forms side this can be implemented by handling the core state via useState instead of useReducer.
Alternatives
- Instead of adding yet another parameter to the
JsonForms component the middleware could also be provided by another context, similar to the JsonFormsStyleContext.
- Instead of the
JsonForms component only the JsonFormsStateProvider component is enhanced. In that case the advanced use case of adding a middleware can be done by manually creating the JsonFormsStateProvider instead of using the JsonForms component.
Describe for which setup you like to have the improvement
Framework: [React]
Could also be implemented for Angular
Description
Sometimes general modifications of JSON Forms behavior would be useful. For example to listen on update events and to modify errors and data before they are set.
Solution
Similar to the middleware concept in Redux, the
JsonFormscomponent could accept a middleware function.Conceptually the API could look like this
On JSON Forms side this can be implemented by handling the
corestate viauseStateinstead ofuseReducer.Alternatives
JsonFormscomponent the middleware could also be provided by another context, similar to theJsonFormsStyleContext.JsonFormscomponent only theJsonFormsStateProvidercomponent is enhanced. In that case the advanced use case of adding a middleware can be done by manually creating theJsonFormsStateProviderinstead of using theJsonFormscomponent.Describe for which setup you like to have the improvement
Framework: [React]
Could also be implemented for Angular