suzaku-io/diode

Better name for model in Circuit object

khanetor opened this issue · 1 comments

In this code

object AppCircuit extends Circuit[RootModel] {
  var model = RootModel(0)
  val actionHandler: PartialFunction[AnyRef, ActionResult[RootModel]] = {
    case Increase(a) => ModelUpdate(model.copy(counter = model.counter + a))
    case Decrease(a) => ModelUpdate(model.copy(counter = model.counter - a))
    case Reset => ModelUpdate(model.copy(counter = 0))
  }

I think the model variable should be rename initialState, and changed to a value (val) instead. There should be a private model variable (var model) in the Circuit object that subsequence inheritant cannot access and change. This is to avoid misunderstanding that model is something that can be modify if see fit.

Sounds good, but the initialState must be a method so that it can be used to initialize the internal var model, because the model comes before initialState in the constructor code when you override it.