Guest User

Untitled

a guest
Dec 27th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. updateRoute : Route -> Model -> (Model, List (Cmd msg))
  2. updateRoute route model = (model, [Navigation.newUrl <| path route])
  3.  
  4. createPost: Model -> (Model, List (Cmd msg))
  5. createPost model =
  6. let
  7. post = { id = List.length model.posts + 1 |> toString
  8. , title = model.form.postTitle
  9. , body = model.form.postBody }
  10. in
  11. ({ model | posts = (::) post model.posts}, [Cmd.none])
  12.  
  13. resetForm : Model -> (Model, List (Cmd msg))
  14. resetForm model =
  15. ({model | form = { email = "", password = "", passwordAgain = "", postTitle = "", postBody = "" }}, [Cmd.none])
  16.  
  17. update: Msg -> Model -> (Model, Cmd Msg)
  18. update msg model =
  19. case msg of
  20. OnLocationChange location ->
  21. ({model| route = parseLocation location}, [Cmd.none])
  22. |> andThen reroute
  23. |> Tuple.mapSecond batch
  24.  
  25. UpdateRoute route ->
  26. updateRoute route model
  27. |> Tuple.mapSecond batch
  28.  
  29. OnInput form ->
  30. ({ model | form = form }, Cmd.none)
  31.  
  32. SignUp ->
  33. updateRoute LoginRoute model
  34. |> Tuple.mapSecond batch
  35.  
  36. Login ->
  37. ({ model | user = Just { email = model.form.email }}, [Cmd.none])
  38. |> andThen resetForm
  39. |> andThen reroute
  40. |> Tuple.mapSecond batch
  41.  
  42. Logout ->
  43. ({ model | user = Nothing }, [Cmd.none])
  44. |> andThen (updateRoute HomeRoute)
  45. |> Tuple.mapSecond batch
  46.  
  47. CreatePost ->
  48. createPost model
  49. |> andThen resetForm
  50. |> andThen (updateRoute HomeRoute)
  51. |> Tuple.mapSecond batch
Add Comment
Please, Sign In to add comment