-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.elm
54 lines (41 loc) · 1.49 KB
/
App.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
46
47
48
49
50
51
52
53
module App where
import Effects exposing (Never, Effects)
import Giffy exposing (init, update, view, angularActions, Action,Model)
import StartApp
import Task
import Json.Encode as Json
import Json.Decode exposing (decodeValue)
import Signal exposing ((<~),Address,forwardTo,Signal)
import Html exposing (Html)
import Debug exposing (crash)
app =
StartApp.start
{ init = init'
, update = update'
, view = view'
, inputs = [ decodeAction <~ actions ]
}
init' : (Model, Effects (Maybe Action))
init' = let (m,e) = init "funny cats" in (m, Effects.map Just e)
view' : Address (Maybe Action) -> Model -> Html
view' a m = view (forwardTo a Just) m
update' : Maybe Action -> Model -> (Model, Effects (Maybe Action))
update' a m = case a of
Just a' -> let (m',e) = update a' m in (m', Effects.map Just e)
Nothing -> (m, Effects.none)
main = app.html
port tasks : Signal (Task.Task Never ())
port tasks = app.tasks
port spec : Json.Value
port spec = snd angularActions
port model : Signal Model
port model = app.model
port actions : Signal (Json.Value)
decodeAction : Json.Value -> Maybe Action
decodeAction js = case decodeValue (fst angularActions |> Json.Decode.maybe) js of
Result.Ok v -> v
Result.Err e -> e
|> Debug.log "error decoding action"
|> always (Json.encode 0 js)
|> Debug.log "JSON was"
|> always Nothing