Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- updateRoute : Route -> Model -> (Model, List (Cmd msg))
- updateRoute route model = (model, [Navigation.newUrl <| path route])
- createPost: Model -> (Model, List (Cmd msg))
- createPost model =
- let
- post = { id = List.length model.posts + 1 |> toString
- , title = model.form.postTitle
- , body = model.form.postBody }
- in
- ({ model | posts = (::) post model.posts}, [Cmd.none])
- resetForm : Model -> (Model, List (Cmd msg))
- resetForm model =
- ({model | form = { email = "", password = "", passwordAgain = "", postTitle = "", postBody = "" }}, [Cmd.none])
- update: Msg -> Model -> (Model, Cmd Msg)
- update msg model =
- case msg of
- OnLocationChange location ->
- ({model| route = parseLocation location}, [Cmd.none])
- |> andThen reroute
- |> Tuple.mapSecond batch
- UpdateRoute route ->
- updateRoute route model
- |> Tuple.mapSecond batch
- OnInput form ->
- ({ model | form = form }, Cmd.none)
- SignUp ->
- updateRoute LoginRoute model
- |> Tuple.mapSecond batch
- Login ->
- ({ model | user = Just { email = model.form.email }}, [Cmd.none])
- |> andThen resetForm
- |> andThen reroute
- |> Tuple.mapSecond batch
- Logout ->
- ({ model | user = Nothing }, [Cmd.none])
- |> andThen (updateRoute HomeRoute)
- |> Tuple.mapSecond batch
- CreatePost ->
- createPost model
- |> andThen resetForm
- |> andThen (updateRoute HomeRoute)
- |> Tuple.mapSecond batch
Add Comment
Please, Sign In to add comment