Created
January 6, 2018 13:40
-
-
Save grrinchas/ffcf23fd6136743b8431149d59c68ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init : Maybe Token -> Location -> ( Model, Cmd Msg ) | |
init token location = | |
let model = | |
{ initialModel | |
| token = Maybe.map RemoteData.succeed token |> Maybe.withDefault RemoteData.NotAsked | |
, route = parseLocation location | |
} | |
in | |
fetchPosts model | |
|> andThen fetchUser | |
|> Tuple.mapSecond batch | |
fetchPosts: Model -> ( Model, List (Cmd Msg) ) | |
fetchPosts model = (model, [Api.fetchPosts]) | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
CreatePost -> | |
( model, RemoteData.map Api.authenticate model.token |> RemoteData.withDefault Cmd.none) | |
OnFetchPosts posts -> | |
({ model | posts = posts }, Cmd.none ) | |
OnCreatePost post -> | |
resetForm model | |
|> andThen fetchPosts | |
|> andThen (updateRoute HomeRoute) | |
|> Tuple.mapSecond batch | |
OnFetchGraphcoolToken token -> | |
(model, RemoteData.map (Api.createPost model.form ) token |> RemoteData.withDefault Cmd.none) | |
--... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment