--
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 elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
update msg model = case msg of
Increment -> (model + 1, Cmd.none)
Decrement -> (model - 1, someEffect)
updateModel msg model = case msg of
Increment -> model + 1
Decrement -> model - 1
makeActions model =
if model == 1 then someEffect else Cmd.none
-- the same signature as my last example so it wires
-- into the elm architecture exactly as it would have before:
update model =
let newModel = updateModel model
in (newModel, makeActions newModel)
- SAM decouples the code that decides what effects to produce from the message. This would basically mean splitting the update function into two parts; update the model first, and then inspect the new model only to decide which effect to run.
- SAM also allows you to completely ignore model updates if you like. Building on the above this would mean the function that updates the model retuning a book denoting whether it changed anything, so that the function responsible for running effect based on the model can be told not to bother.
I think it's all possible in Elm basically, and when I was working on code snippets I found times when I really wanted effects based on messages as well and it seemed to simplify things, and I struggled to see the concrete benefits of forcing a decoupling from the POV of implementing SAM in Elm.