Skip to content

Instantly share code, notes, and snippets.

@grrinchas
Created January 6, 2018 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grrinchas/ffcf23fd6136743b8431149d59c68ac0 to your computer and use it in GitHub Desktop.
Save grrinchas/ffcf23fd6136743b8431149d59c68ac0 to your computer and use it in GitHub Desktop.
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