jeudi 21 avril 2016

From Event driven OO to Redux architecture

I have a structure that is pretty much OO and I am about to migrate to React/Redux due to event mess. I am curious what to do with current modules, I have objects that have schema like:

User {
  getName()
  getSurname()
  etc...
}

And there are lots of these, they were used as fasade/factories for raw json data as I used to pass json and manipulate it (mutable data)

Now how to solve this in redux?

I get to the part where I have an async action call, I recieve raw data from api and than what? Should I pass 'complex' object with their getters/setters to state? Its said to be immutable so it doesnt seem well with redux recomendations.

Or maybe convert the class-like elements to accessors like:

function getName(rawJson) {
  return rawJson.name
}
function setName(rawJson, name) {
  return Object.assign({}, rawJson, {name})
}

parse it in action and return a rawJSON chunk from action to reducer and than stick it to the new state?

Aucun commentaire:

Enregistrer un commentaire