aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Update.elm
diff options
context:
space:
mode:
authorJoris2016-01-02 19:07:19 +0100
committerJoris2016-01-02 19:07:19 +0100
commitbb316286b0859b5648c61f44c88399f4c1aad9cd (patch)
treeecbe401c1ff657987b6609997a69775969a317f7 /src/client/elm/Update.elm
parent0d0c99fd28b782c7daf02fb5cc48d3eb252e705d (diff)
downloadbudget-bb316286b0859b5648c61f44c88399f4c1aad9cd.tar.gz
budget-bb316286b0859b5648c61f44c88399f4c1aad9cd.tar.bz2
budget-bb316286b0859b5648c61f44c88399f4c1aad9cd.zip
Use start-app for elm
Diffstat (limited to 'src/client/elm/Update.elm')
-rw-r--r--src/client/elm/Update.elm76
1 files changed, 39 insertions, 37 deletions
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)