Development: Sharing state between reducers

I’m looking into using ajv-i18n to localise the validation errors. I’d like to extend the validate function in the core reducer to take a locale parameter. I’d like to take this from the parameter that is stored in the i18n reducer.

What’s the best way to access this?

I tried adding it as part of the UPDATE_DATA, INIT, and SET_AJV action but this meant every onChange handler would then need to be updated with this. A massive breaking change.

I looked at wrapping the reducer as described by reduce-reducers but this broke the example and seems also like a breaking change. Beyond combineReducers | Redux

I think I’d like to use redux thunk, what do you think about this? Is there a better approach to this?

[original thread by Lily]

[Edgar Müller]

This requirement brings up multiple issues at once, but I think those could be addressed in the following way:

  1. Provide a way to react to any data updates in order to localize any errors, something like proposed in Can we get an onChange prop for the JsonForms component? · Issue #1271 · eclipsesource/jsonforms · GitHub

  2. Retrieve the AJV instance from the core state

  3. Provide an additional action in order to re-set the errors state with the localized errors. Such an action does not exist atm.
    I probably didn’t think this through entirely, but this is the cleanest approach I can think of. What do you think? Would that work for you?

[Lily]

Hi Edgar, are you talking about a way the library user could add their own localisation? I was suggesting this as a feature JSON Forms could have. I have an open draft PR here Add ajv-i18n by Lily418 · Pull Request #1416 · eclipsesource/jsonforms · GitHub

[Lily]

Apologies, I made that PR after I wrote this question here. The problem I was having is at the moment I use navigator.languages but I would want to use the locale which is stored in the i18n reducer.

[Edgar Müller]

Yes, kinda. The problem is, as you already pointed out, accessing state across reducers, which I think is not so easily doable. This is why I think that we’ll need some way of first extracting the state (e.g. current i18n) and then re-set the errors state after updating the validation messages. This could be probably also be embedded within the framework itself (as it would just use the same mechanics) but I’m unsure where we could hook things up. Does this make sense?