From bb316286b0859b5648c61f44c88399f4c1aad9cd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 19:07:19 +0100 Subject: Use start-app for elm --- src/client/elm/Update.elm | 76 ++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/client/elm/Update.elm') diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm index 62782a3..c955f8c 100644 --- a/src/client/elm/Update.elm +++ b/src/client/elm/Update.elm @@ -1,60 +1,62 @@ module Update - ( Action(..) - , actions - , updateModel + ( update ) where -import Time exposing (Time) +import Task + +import Effects exposing (Effects) + +import ServerCommunication exposing (sendRequest) import Model exposing (Model) -import Model.User exposing (Users, UserId) -import Model.Payment exposing (Payments) -import Model.Payer exposing (Payers) +import Model.Action exposing (..) import Model.View as V import Model.View.SignInView exposing (..) import Model.View.LoggedInView exposing (..) +import Model.Communication exposing (Communication) -import Update.SignIn exposing (..) -import Update.LoggedIn exposing (..) - -type Action = - NoOp - | UpdateTime Time - | GoLoadingView - | GoSignInView - | GoLoggedInView Users UserId Payments Payments Int Payers - | SignInError String - | UpdateSignIn SignInAction - | UpdateLoggedIn LoggedAction +import Update.LoggedIn exposing (updateLoggedIn) +import Update.SignIn exposing (updateSignIn) -actions : Signal.Mailbox Action -actions = Signal.mailbox NoOp - -updateModel : Action -> Model -> Model -updateModel action model = +update : Action -> Model -> (Model, Effects Action) +update action model = case action of + NoOp -> - model + (model, Effects.none) + + ServerCommunication communication -> + ( model + , sendRequest communication + |> flip Task.onError (always <| Task.succeed NoOp) + |> Effects.task + ) + UpdateTime time -> - { model | currentTime = time } - GoLoadingView -> - { model | view = V.LoadingView } + ({ model | currentTime = time }, Effects.none) + GoSignInView -> - { model | view = V.SignInView initSignInView } + ({ model | view = V.SignInView initSignInView }, Effects.none) + GoLoggedInView users me monthlyPayments payments paymentsCount payers -> - { model | view = V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) } - SignInError msg -> - let signInView = { initSignInView | result = Just (Err msg) } - in { model | view = V.SignInView signInView } + ( { model | view = V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) } + , Effects.none + ) + UpdateSignIn signInAction -> case model.view of V.SignInView signInView -> - { model | view = V.SignInView (updateSignIn signInAction signInView) } + ( { model | view = V.SignInView (updateSignIn signInAction signInView) } + , Effects.none + ) _ -> - model + (model, Effects.none) + UpdateLoggedIn loggedAction -> case model.view of V.LoggedInView loggedInView -> - { model | view = V.LoggedInView (updateLoggedIn model loggedAction loggedInView) } + ( { model | view = V.LoggedInView (updateLoggedIn model loggedAction loggedInView) } + , Effects.none + ) _ -> - model + (model, Effects.none) -- cgit v1.2.3