-
-
Save drathier/5e200f1534bf2059f4074cf8c633aa16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FrontendMsg | |
= FNoop | |
| Increment | |
| Decrement | |
| OnBackendMsg ToFrontend | |
update : FrontendMsg -> Model -> ( Model, Cmd FrontendMsg ) | |
update msg model = | |
case msg of | |
FNoop -> | |
( model, Cmd.none ) | |
Increment -> | |
( { model | counter = model.counter + 1 } | |
, sendToBackend CounterIncremented | |
) | |
Decrement -> | |
( { model | counter = model.counter - 1 } | |
, sendToBackend CounterDecremented | |
) | |
OnBackendMsg (CounterNewValue newValue) -> | |
( { model | counter = newValue } | |
, Cmd.none | |
) | |
updateFromBackend : ToFrontend -> Model -> ( Model, Cmd FrontendMsg ) | |
updateFromBackend toFrontend model = | |
update (OnBackendMsg toFrontend) model | |
app = | |
Lamdera.Frontend.application | |
{ init = \_ _ -> init | |
, update = update | |
, onBackendMsg = updateFromBackend | |
, view = | |
\model -> | |
{ title = "Lamdera board app" | |
, body = [ view model ] | |
} | |
, subscriptions = \_ -> Sub.none | |
, onUrlChange = \_ -> FNoop | |
, onUrlRequest = \_ -> FNoop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This shows how to reroute msgs from the updateFromBackend function into the normal update function, in case someone wants to do that.