Actually, I'd probably use a List instead of Maybe on the immediately
returned event(s).
doSideEffects : Act -> Model -> (List Evt, Cmd Evt)
doSideEffects act model =
case act of
UpdateCustomer customer ->
( [ CustomerUpdateRequested ]
, callServerWithCustomer customer
)
...
updateModel : Evt -> Model -> Model
... -- implementation as previous
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Action act ->
let
(events, command) = doSideEffects act model
in
(List.foldr updateModel model events, Cmd.map Evt command)
Event evt ->
(updateModel evt model, Cmd.none)
On Thursday, August 11, 2016 at 4:26:03 PM UTC-5, Kasey Speakman wrote:
>
> Yes, that was the goal. That way the UI state is utterly deterministic /
> reproducible in isolation of all outside services.
>
> That's a good point on the race conditions. I only use Cmd.batch because
> it's the facility that came to mind. (I'm still getting acquainted with
> Elm.) I don't know if Cmd.batch makes any ordering guarantee.
>
> If not we'd be more or less back to square one. Abuse `update` to do both
> things.
>
> doSideEffects: Act -> Model -> (Maybe Evt, Cmd Evt)
> doSideEffects act model =
> case act of
> UpdateCustomer customer ->
> (Just CustomerUpdateRequested, callServerWithCustomer customer)
>
> ...
>
> updateModel: Evt -> Model -> Model
> ... -- implementation as previous
>
> maybeUpdateModel: Maybe Evt -> Model -> Model
> maybeUpdateModel evtOpt model =
> case evtOpt of
> Nothing ->
> model
>
> Just evt ->
> updateModel evt model
>
> update : Msg -> Model -> (Model, Cmd Msg)
> update msg model =
> case msg of
> Action act ->
> let
> (eventNow, command) = doSideEffects act model
> in
> (maybeUpdateModel eventNow model, Cmd.map Evt command)
>
> Event evt ->
> (updateModel evt model, Cmd.none)
>
> So this should apply an event immediately if one is needed for the action.
> But it still keeps the model updating events separate.
>
> These immediate events would be seen by a userland event-store
> implementation (which is underneath updateModel), but I bet the TTD
> wouldn't see it since it doesn't come from Elm.
>
> On Thursday, August 11, 2016 at 3:43:36 PM UTC-5, OvermindDL1 wrote:
>>
>> So you really are wanting to hard device events into two different ones,
>> those that can *only* alter the model, and those that can *only* send
>> commands (which may call ones that alter the model). Unsure if it might
>> actually happen but might have to take into account possible race
>> conditions for if other messages appear before your other expected ones are
>> processed through? Easier to do that atomically all at once?
>>
>>
>> On Thursday, August 11, 2016 at 2:25:22 PM UTC-6, Kasey Speakman wrote:
>>>
>>> doSideEffects above would also have to map Cmd Evt to Cmd Msg.
>>>
>>
--
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.