mercredi 29 novembre 2017

Translating wrapper-/proxy- pattern to redux

I am currently investigating reduxjs as a viable framework for an upcoming project. There, we migrate from an old solution, which makes heavy use of the proxy/wrapper pattern.

i.e.:

  • there are models which are kept dumb (pojo) intentionally. They only carry data. Let's assume these are tasks

  • Now these tasks are wrapped dynamically with objects that add cross-cutting features like validation and change tracking to them.

Now: Whenever the property is changed, in effect, 3 changes to the application state may happen. E.g.:

  1. the "title" property of the task is changed
  2. as this change is done throught the wrapper/proxy, it detects the change and
    1. a) updates the "haschagnes" field to "true"
    2. b) and (potentially) adds a validation error to the "validationErrors" list

As far as I understand, in Redux, every action should only be handled once and lead to 1 atomic state change. However, in this case, it would be up to three changes.

So my question is: Is it possible to translate this wrapper/proxy- pattern based approach to a redux style one? And if so, how? (Middleware, WrapperReducer, ...?)

Thank you guys!

Aucun commentaire:

Enregistrer un commentaire