Created
June 4, 2016 22:46
-
-
Save manuscrypt/0d82e5e610949357ab0d0ad6a9a64a88 to your computer and use it in GitHub Desktop.
Shows how to perform a Task when the Success-Handler does not need any payload (empty tuple -> unit)
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
-- Check out: http://elm-community.github.io/elm-faq/#what-does--mean-1 | |
module Main exposing (..) | |
import Html exposing (..) | |
import Html.App as App exposing (..) | |
import Task exposing (..) | |
type alias Model = | |
{ result : String } | |
type Msg | |
= Error String | |
| Success () | |
execute : String -> Cmd Msg | |
execute str = | |
Task.perform Error Success (Task.fail str) | |
init : ( Model, Cmd Msg ) | |
init = | |
( Model "", execute "noooo" ) | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Error str -> | |
( { model | result = str }, Cmd.none ) | |
Success () -> | |
( { model | result = "Too sexy for my exclamation mark" }, Cmd.none ) | |
view : Model -> Html Msg | |
view model = | |
div [] [ Html.text model.result ] | |
main : Program Never | |
main = | |
App.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = (\_ -> Sub.none) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment