module Update ( Action(..) , actions , updateModel ) where import Time exposing (Time) import Model exposing (Model) import Model.Payment exposing (Payments) import Model.Payers exposing (Payers) import Model.View as V import Model.View.SignInView exposing (..) import Model.View.PaymentView exposing (..) import Update.SignIn exposing (..) import Update.Payment exposing (..) type Action = NoOp | UpdateTime Time | GoSignInView | SignInError String | UpdateSignIn SignInAction | GoPaymentView String Payments Payers | UpdatePayment PaymentAction actions : Signal.Mailbox Action actions = Signal.mailbox NoOp updateModel : Action -> Model -> Model updateModel action model = case action of NoOp -> model UpdateTime time -> { model | currentTime <- time } GoSignInView -> { model | view <- V.SignInView initSignInView } GoPaymentView userName payments payers -> { model | view <- V.PaymentView (initPaymentView userName payments payers) } SignInError msg -> let signInView = { initSignInView | result <- Just (Err msg) } in { model | view <- V.SignInView signInView } UpdateSignIn signInAction -> case model.view of V.SignInView signInView -> { model | view <- V.SignInView (updateSignIn signInAction signInView) } _ -> model UpdatePayment paymentAction -> case model.view of V.PaymentView paymentView -> { model | view <- V.PaymentView (updatePayment model paymentAction paymentView) } _ -> model