-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.elm
45 lines (32 loc) · 1.13 KB
/
Update.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Update exposing (Msg(..), update)
import Http exposing (Error, send)
import Model exposing (Model)
import Rest exposing (DogsType, dogsRequest)
type Msg
= Inc
| Dec
| Reset
| Add Int
| InputName String
| DogsResponse (Result Error DogsType)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Inc ->
( { model | counter = model.counter + 1 }, Cmd.none )
Dec ->
( { model | counter = model.counter - 1 }, Cmd.none )
Reset ->
( { model | counter = 0 }, Cmd.none )
Add i ->
( { model | counter = model.counter + i }, Cmd.none )
InputName "Gato" ->
( { model | counter = model.counter + 100, name = "Gato!" }, Cmd.none )
InputName "Cachorro" ->
( { model | name = "Cachorro!" }, send DogsResponse dogsRequest )
InputName name ->
( { model | name = name }, Cmd.none )
DogsResponse (Ok response) ->
( { model | image = Just response.message }, Cmd.none )
DogsResponse _ ->
( { model | image = Nothing }, Cmd.none )