-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
NodeTemplate.elm
81 lines (51 loc) · 1.29 KB
/
NodeTemplate.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
port module Year201X.DayXX exposing (..)
import Json.Decode
port elmAsks : String -> Cmd msg
port jsAnswers : (String -> msg) -> Sub msg
main : Program Never Model Msg
main =
Platform.program
{ init = init1
, update = update1
-- { init = init2
-- , update = update2
, subscriptions = subscriptions
}
type alias Model =
Int
type Msg
= JsAnswers String
init1 : ( Model, Cmd Msg )
init1 =
( initModel1, elmAsks (makeString initModel.id initModel.counter) )
initModel1 : Model
initModel1 =
0
init2 : ( Model, Cmd Msg )
init2 =
( initModel2, elmAsks (makeString initModel.id initModel.counter) )
initModel2 : Model
initModel2 =
0
update1 : Msg -> Model -> ( Model, Cmd Msg )
update1 msg model =
case msg of
JsAnswers hash ->
( model, Cmd.none )
toInt : String -> Int
toInt string =
string
|> String.toInt
|> Result.mapError (\_ -> Debug.crash "Wrong input!")
|> Result.withDefault 0
update2 : Msg -> Model -> ( Model, Cmd Msg )
update2 msg model =
case msg of
JsAnswers hash ->
( model, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions model =
jsAnswers JsAnswers
prepareForPort : String -> String
prepareForPort string =
string