oldergod / android-architecture

MVI architecture Implementation of the ToDo app.
Apache License 2.0
669 stars 70 forks source link

Opinion on where to store/update model state #37

Closed Shakezulla57 closed 6 years ago

Shakezulla57 commented 6 years ago

I'm looking for opinions on where to store model state that can't be extracted from the View. Keeping with the tasks example let's add a Tag object to a task. A Tag consists of an Id and a Label. The ViewState only cares about the Label so it can display it, so the Id isn't part of the state. Whose job should it be to actually update the Task object with the correct TagId until we hit save? The action processor, the viewmodel? Would updating our in memory Task just be a side effect of intents, or could we store things in our ViewState that don't necessarily display directly but are need for when the user hits save? That seems messy though because you'd have to store the current state outside of the stream.

oldergod commented 6 years ago

I would keep the whole tag instance inside the state, that doesn't sound like a problem to me.

Shakezulla57 commented 6 years ago

Thanks for getting back to me. So would the current state be stored in the view then as a member? When the user hits a save button for example we get everything we need to pass to our domain layer from that current state member variable?

oldergod commented 6 years ago

Yeah there is definitely the need to store this variable somewhere, the hardest thing is to make it, kind of read only and always in sync with the lastest state so we keep a unique source of truth.