Skip to content

Instantly share code, notes, and snippets.

@drathier
Forked from owanturist/Main.elm
Last active June 29, 2019 13:34
Show Gist options
  • Select an option

  • Save drathier/5e200f1534bf2059f4074cf8c633aa16 to your computer and use it in GitHub Desktop.

Select an option

Save drathier/5e200f1534bf2059f4074cf8c633aa16 to your computer and use it in GitHub Desktop.

Revisions

  1. drathier revised this gist Jun 29, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions Main.elm
    Original file line number Diff line number Diff line change
    @@ -25,12 +25,15 @@ update msg model =
    , Cmd.none
    )

    updateFromBackend : ToFrontend -> Model -> ( Model, Cmd FrontendMsg )
    updateFromBackend toFrontend model =
    update (OnBackendMsg toFrontend) model

    app =
    Lamdera.Frontend.application
    { init = \_ _ -> init
    , update = update
    , onBackendMsg = OnBackendMsg
    , onBackendMsg = updateFromBackend
    , view =
    \model ->
    { title = "Lamdera board app"
    @@ -39,4 +42,4 @@ app =
    , subscriptions = \_ -> Sub.none
    , onUrlChange = \_ -> FNoop
    , onUrlRequest = \_ -> FNoop
    }
    }
  2. @owanturist owanturist created this gist Jun 28, 2019.
    42 changes: 42 additions & 0 deletions Main.elm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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
    )


    app =
    Lamdera.Frontend.application
    { init = \_ _ -> init
    , update = update
    , onBackendMsg = OnBackendMsg
    , view =
    \model ->
    { title = "Lamdera board app"
    , body = [ view model ]
    }
    , subscriptions = \_ -> Sub.none
    , onUrlChange = \_ -> FNoop
    , onUrlRequest = \_ -> FNoop
    }