Hi, I'm a new comer to elm. I try to build application using elm and have 
some problem on component.

Suppose I'm building an BMI calculator, initially I have a model

    type alias Model = { weight:Int, height:Int }

The rendering is just an two input[type=number].
The result is rendered by a pure function at the main app:

    calclulate model = 
      let 
        h = (toFloat model.height) / 100
        w = toFloat model.weight
      in
        toString (round (w / (h*h)))


One day a decision made to change those two inputs into a component of its 
own (BmiConfig). 
So the models become

    --at main app 
    type alias Model = { bmiConfig: BmiConfig.Model ... }

    --at BmiConfig
    type alias Model = {weight:Int, height:Int}

We need to to the work of connecting Msg, etc. The calculate function 
becomes

    calclulate model = 
      let 
        h = (toFloat model.config.height) / 100
        w = toFloat model.config.weight
      in
        toString (round (w / (h*h)))


Another a change comes and requesting add +/- button to the number input. 
We try to make a small generic component NumberInput. Models become:

    --at main app 
    type alias Model = { bmiConfig: BmiConfig.Model ... }

    --at BmiConfig
    type alias Model = {weight:NumberInput.Model, height:NumberInput.Model}
    
    --at NumberInput
     type alias Model = {value:Int, max:Int, min:Int, .... }

The calculate function needs to be changed again:

    calculate model =
      let 
        h = (toFloat model.config.height.value) / 100
        w = toFloat model.config.weight.value
      in
        toString (round (w / (h*h)))

It seems to me that every refactoring to extract component would lead to a 
propagation
of change all the ways from child to its parents. Parents need to know the 
data
structure of child to do calculation too. Is that the correct way of 
applying the elm architecture?
Have I missed something?
     



-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to