@curtissimo/elm-hot 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +40 -0
- package/CODE_OF_CONDUCT.md +74 -0
- package/CONTRIBUTING.md +51 -0
- package/LICENSE.txt +33 -0
- package/README.md +84 -0
- package/package.json +37 -0
- package/resources/hmr.js +519 -0
- package/src/index.js +6 -0
- package/src/inject.js +46 -0
- package/test/client.js +63 -0
- package/test/fixtures/BrowserApplicationCounter.elm +136 -0
- package/test/fixtures/BrowserApplicationCounter.html +22 -0
- package/test/fixtures/BrowserApplicationCounterDeepKey.elm +137 -0
- package/test/fixtures/BrowserApplicationCounterDeepKey.html +18 -0
- package/test/fixtures/BrowserApplicationCounterMultiKey.elm +158 -0
- package/test/fixtures/BrowserApplicationCounterMultiKey.html +22 -0
- package/test/fixtures/BrowserApplicationMissingNavKeyError.elm +62 -0
- package/test/fixtures/BrowserApplicationMissingNavKeyError.html +22 -0
- package/test/fixtures/BrowserApplicationNavKeyMoved.elm +159 -0
- package/test/fixtures/BrowserApplicationNavKeyMoved.html +22 -0
- package/test/fixtures/BrowserApplicationWithNull.elm +142 -0
- package/test/fixtures/BrowserApplicationWithNull.html +22 -0
- package/test/fixtures/BrowserDocumentCounter.elm +57 -0
- package/test/fixtures/BrowserDocumentCounter.html +24 -0
- package/test/fixtures/BrowserElementCounter.elm +55 -0
- package/test/fixtures/BrowserElementCounter.html +24 -0
- package/test/fixtures/BrowserSandboxCounter.elm +48 -0
- package/test/fixtures/BrowserSandboxCounter.html +21 -0
- package/test/fixtures/DebugBrowserApplication.elm +139 -0
- package/test/fixtures/DebugBrowserApplication.html +22 -0
- package/test/fixtures/DebugEmbed.elm +48 -0
- package/test/fixtures/DebugEmbed.html +21 -0
- package/test/fixtures/DebugFullscreen.elm +57 -0
- package/test/fixtures/DebugFullscreen.html +22 -0
- package/test/fixtures/FullScreenEmptyInit.elm +51 -0
- package/test/fixtures/FullScreenEmptyInit.html +19 -0
- package/test/fixtures/InitSideEffects.elm +65 -0
- package/test/fixtures/InitSideEffects.html +27 -0
- package/test/fixtures/MainWithTasks.elm +70 -0
- package/test/fixtures/MainWithTasks.html +21 -0
- package/test/fixtures/MultiMain.html +21 -0
- package/test/fixtures/MultiMain1.elm +48 -0
- package/test/fixtures/MultiMain2.elm +48 -0
- package/test/fixtures/PortsEmbed.elm +64 -0
- package/test/fixtures/PortsEmbed.html +27 -0
- package/test/fixtures/PortsFullscreen.elm +70 -0
- package/test/fixtures/PortsFullscreen.html +26 -0
- package/test/fixtures/build.sh +29 -0
- package/test/fixtures/elm.json +24 -0
- package/test/server.js +73 -0
- package/test/test.js +320 -0
- package/test.sh +16 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
module BrowserApplicationNavKeyMoved exposing
|
|
2
|
+
( Model
|
|
3
|
+
, Msg(..)
|
|
4
|
+
, Page(..)
|
|
5
|
+
, getKey
|
|
6
|
+
, init
|
|
7
|
+
, loadPage
|
|
8
|
+
, main
|
|
9
|
+
, update
|
|
10
|
+
, view
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
import Browser exposing (UrlRequest)
|
|
14
|
+
import Browser.Navigation as Nav
|
|
15
|
+
import Html exposing (a, button, div, h1, p, span, text)
|
|
16
|
+
import Html.Attributes exposing (href, id)
|
|
17
|
+
import Html.Events exposing (onClick)
|
|
18
|
+
import Url exposing (Url)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
main : Program () Model Msg
|
|
22
|
+
main =
|
|
23
|
+
Browser.application
|
|
24
|
+
{ init = init
|
|
25
|
+
, view = view
|
|
26
|
+
, update = update
|
|
27
|
+
, subscriptions = \_ -> Sub.none
|
|
28
|
+
, onUrlRequest = LinkClicked
|
|
29
|
+
, onUrlChange = UrlChanged
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
type alias Model =
|
|
34
|
+
{ count : Int
|
|
35
|
+
, page : Page
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
{-| IMPORTANT: store the Nav.Key in the variants of a union type to make sure that we can restore it during HMR and nest the navigation key in one variant so that we can handle cases where the "shape"
|
|
40
|
+
of a page varies (see <https://github.com/klazuka/elm-hot/issues/35>)
|
|
41
|
+
-}
|
|
42
|
+
type Page
|
|
43
|
+
= NotFound Nav.Key
|
|
44
|
+
| Incrementer Nav.Key
|
|
45
|
+
| Decrementer { navKey : Nav.Key }
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
|
49
|
+
init _ url key =
|
|
50
|
+
( loadPage url
|
|
51
|
+
{ count = 0
|
|
52
|
+
, page = NotFound key
|
|
53
|
+
}
|
|
54
|
+
, Cmd.none
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
type Msg
|
|
59
|
+
= Increment
|
|
60
|
+
| Decrement
|
|
61
|
+
| LinkClicked UrlRequest
|
|
62
|
+
| UrlChanged Url
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
66
|
+
update msg model =
|
|
67
|
+
case msg of
|
|
68
|
+
Increment ->
|
|
69
|
+
( { model | count = model.count + 1 }
|
|
70
|
+
, Cmd.none
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
Decrement ->
|
|
74
|
+
( { model | count = model.count - 1 }
|
|
75
|
+
, Cmd.none
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
LinkClicked req ->
|
|
79
|
+
case req of
|
|
80
|
+
Browser.Internal url ->
|
|
81
|
+
( model, Nav.pushUrl (getKey model.page) (Url.toString url) )
|
|
82
|
+
|
|
83
|
+
Browser.External href ->
|
|
84
|
+
( model, Nav.load href )
|
|
85
|
+
|
|
86
|
+
UrlChanged url ->
|
|
87
|
+
( loadPage url model
|
|
88
|
+
, Cmd.none
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
getKey : Page -> Nav.Key
|
|
93
|
+
getKey page =
|
|
94
|
+
case page of
|
|
95
|
+
NotFound key ->
|
|
96
|
+
key
|
|
97
|
+
|
|
98
|
+
Incrementer key ->
|
|
99
|
+
key
|
|
100
|
+
|
|
101
|
+
Decrementer { navKey } ->
|
|
102
|
+
navKey
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
loadPage : Url -> Model -> Model
|
|
106
|
+
loadPage url model =
|
|
107
|
+
{ model
|
|
108
|
+
| page =
|
|
109
|
+
case url.fragment of
|
|
110
|
+
Nothing ->
|
|
111
|
+
Incrementer (getKey model.page)
|
|
112
|
+
|
|
113
|
+
Just "/incrementer" ->
|
|
114
|
+
Incrementer (getKey model.page)
|
|
115
|
+
|
|
116
|
+
Just "/decrementer" ->
|
|
117
|
+
Decrementer { navKey = getKey model.page }
|
|
118
|
+
|
|
119
|
+
_ ->
|
|
120
|
+
NotFound (getKey model.page)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
view : Model -> Browser.Document Msg
|
|
125
|
+
view model =
|
|
126
|
+
let
|
|
127
|
+
pageBody =
|
|
128
|
+
case model.page of
|
|
129
|
+
Incrementer _ ->
|
|
130
|
+
div [ id "incrementer" ]
|
|
131
|
+
[ h1 [] [ text "Incrementer" ]
|
|
132
|
+
, p []
|
|
133
|
+
[ text "Counter value is: "
|
|
134
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
135
|
+
]
|
|
136
|
+
, button [ onClick Increment, id "counter-button" ] [ text "+" ]
|
|
137
|
+
, p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
Decrementer _ ->
|
|
141
|
+
div [ id "decrementer" ]
|
|
142
|
+
[ h1 [] [ text "Decrementer" ]
|
|
143
|
+
, p []
|
|
144
|
+
[ text "Counter value is: "
|
|
145
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
146
|
+
]
|
|
147
|
+
, button [ onClick Decrement, id "counter-button" ] [ text "-" ]
|
|
148
|
+
, p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
NotFound _ ->
|
|
152
|
+
text "Page not found"
|
|
153
|
+
in
|
|
154
|
+
{ title = "BrowserApplicationCounterMultiKey"
|
|
155
|
+
, body =
|
|
156
|
+
[ span [ id "code-version" ] [ text "code: v1" ]
|
|
157
|
+
, pageBody
|
|
158
|
+
]
|
|
159
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Main</title>
|
|
7
|
+
<script type="text/javascript" src="client.js"></script>
|
|
8
|
+
<script type="text/javascript" src="build/BrowserApplicationNavKeyMoved.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<script>
|
|
13
|
+
connect("BrowserApplicationNavKeyMoved");
|
|
14
|
+
Elm.BrowserApplicationNavKeyMoved.init({
|
|
15
|
+
flags: {
|
|
16
|
+
n: 0
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
module BrowserApplicationWithNull exposing (..)
|
|
2
|
+
|
|
3
|
+
import Browser exposing (UrlRequest)
|
|
4
|
+
import Browser.Navigation as Nav
|
|
5
|
+
import Html exposing (a, button, div, h1, p, span, text)
|
|
6
|
+
import Html.Attributes exposing (href, id)
|
|
7
|
+
import Html.Events exposing (onClick)
|
|
8
|
+
import Json.Encode
|
|
9
|
+
import Url exposing (Url)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
main : Program Flags Model Msg
|
|
13
|
+
main =
|
|
14
|
+
Browser.application
|
|
15
|
+
{ init = init
|
|
16
|
+
, view = view
|
|
17
|
+
, update = update
|
|
18
|
+
, subscriptions = \_ -> Sub.none
|
|
19
|
+
, onUrlRequest = LinkClicked
|
|
20
|
+
, onUrlChange = UrlChanged
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
type alias Flags =
|
|
25
|
+
{ n : Int }
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
type alias Model =
|
|
29
|
+
{ count : Int
|
|
30
|
+
, foo : Json.Encode.Value
|
|
31
|
+
, nav : { key : Nav.Key }
|
|
32
|
+
, page : Page
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
type Page
|
|
37
|
+
= NotFound
|
|
38
|
+
| Incrementer
|
|
39
|
+
| Decrementer
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
|
43
|
+
init flags url key =
|
|
44
|
+
( loadPage url
|
|
45
|
+
{ count = flags.n
|
|
46
|
+
, foo = Json.Encode.null
|
|
47
|
+
, nav = { key = key }
|
|
48
|
+
, page = NotFound
|
|
49
|
+
}
|
|
50
|
+
, Cmd.none
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
type Msg
|
|
55
|
+
= Increment
|
|
56
|
+
| Decrement
|
|
57
|
+
| LinkClicked UrlRequest
|
|
58
|
+
| UrlChanged Url
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
62
|
+
update msg model =
|
|
63
|
+
case msg of
|
|
64
|
+
Increment ->
|
|
65
|
+
( { model | count = model.count + 1 }
|
|
66
|
+
, Cmd.none
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
Decrement ->
|
|
70
|
+
( { model | count = model.count - 1 }
|
|
71
|
+
, Cmd.none
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
LinkClicked req ->
|
|
75
|
+
case req of
|
|
76
|
+
Browser.Internal url ->
|
|
77
|
+
( model, Nav.pushUrl model.nav.key (Url.toString url) )
|
|
78
|
+
|
|
79
|
+
Browser.External href ->
|
|
80
|
+
( model, Nav.load href )
|
|
81
|
+
|
|
82
|
+
UrlChanged url ->
|
|
83
|
+
( loadPage url model
|
|
84
|
+
, Cmd.none
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
loadPage : Url -> Model -> Model
|
|
89
|
+
loadPage url model =
|
|
90
|
+
{ model
|
|
91
|
+
| page =
|
|
92
|
+
case url.fragment of
|
|
93
|
+
Nothing ->
|
|
94
|
+
Incrementer
|
|
95
|
+
|
|
96
|
+
Just "/incrementer" ->
|
|
97
|
+
Incrementer
|
|
98
|
+
|
|
99
|
+
Just "/decrementer" ->
|
|
100
|
+
Decrementer
|
|
101
|
+
|
|
102
|
+
_ ->
|
|
103
|
+
NotFound
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
view : Model -> Browser.Document Msg
|
|
108
|
+
view model =
|
|
109
|
+
let
|
|
110
|
+
pageBody =
|
|
111
|
+
case model.page of
|
|
112
|
+
Incrementer ->
|
|
113
|
+
div [ id "incrementer" ]
|
|
114
|
+
[ h1 [] [ text "Incrementer" ]
|
|
115
|
+
, p []
|
|
116
|
+
[ text "Counter value is: "
|
|
117
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
118
|
+
]
|
|
119
|
+
, button [ onClick Increment, id "counter-button" ] [ text "+" ]
|
|
120
|
+
, p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
Decrementer ->
|
|
124
|
+
div [ id "decrementer" ]
|
|
125
|
+
[ h1 [] [ text "Decrementer" ]
|
|
126
|
+
, p []
|
|
127
|
+
[ text "Counter value is: "
|
|
128
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
129
|
+
]
|
|
130
|
+
, button [ onClick Decrement, id "counter-button" ] [ text "-" ]
|
|
131
|
+
, p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
NotFound ->
|
|
135
|
+
text "Page not found"
|
|
136
|
+
in
|
|
137
|
+
{ title = "BrowserApplicationCounter"
|
|
138
|
+
, body =
|
|
139
|
+
[ span [ id "code-version" ] [ text "code: v1" ]
|
|
140
|
+
, pageBody
|
|
141
|
+
]
|
|
142
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Main</title>
|
|
7
|
+
<script type="text/javascript" src="client.js"></script>
|
|
8
|
+
<script type="text/javascript" src="build/BrowserApplicationWithNull.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<script>
|
|
13
|
+
connect("BrowserApplicationWithNull");
|
|
14
|
+
Elm.BrowserApplicationWithNull.init({
|
|
15
|
+
flags: {
|
|
16
|
+
n: 0
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module BrowserDocumentCounter exposing (..)
|
|
2
|
+
|
|
3
|
+
import Browser
|
|
4
|
+
import Html exposing (button, h1, p, span, text)
|
|
5
|
+
import Html.Attributes exposing (id)
|
|
6
|
+
import Html.Events exposing (onClick)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
main : Program Flags Model Msg
|
|
10
|
+
main =
|
|
11
|
+
Browser.document
|
|
12
|
+
{ init = init
|
|
13
|
+
, view = view
|
|
14
|
+
, update = update
|
|
15
|
+
, subscriptions = \_ -> Sub.none
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type alias Flags =
|
|
20
|
+
{ n : Int }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
type alias Model =
|
|
24
|
+
{ count : Int }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
init : Flags -> ( Model, Cmd Msg )
|
|
28
|
+
init flags =
|
|
29
|
+
( { count = flags.n }, Cmd.none )
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
type Msg
|
|
33
|
+
= Increment
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
37
|
+
update msg model =
|
|
38
|
+
case msg of
|
|
39
|
+
Increment ->
|
|
40
|
+
( { model | count = model.count + 1 }
|
|
41
|
+
, Cmd.none
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
view : Model -> Browser.Document Msg
|
|
46
|
+
view model =
|
|
47
|
+
{ title = "BrowserDocumentCounter"
|
|
48
|
+
, body =
|
|
49
|
+
[ h1 [] [ text "BrowserDocumentCounter" ]
|
|
50
|
+
, span [ id "code-version" ] [ text "code: v1" ]
|
|
51
|
+
, p []
|
|
52
|
+
[ text "Counter value is: "
|
|
53
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
54
|
+
]
|
|
55
|
+
, button [ onClick Increment, id "counter-button" ] [ text "+" ]
|
|
56
|
+
]
|
|
57
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Main</title>
|
|
7
|
+
<script type="text/javascript" src="client.js"></script>
|
|
8
|
+
<script type="text/javascript" src="build/BrowserDocumentCounter.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div id="ignored"></div>
|
|
13
|
+
<script>
|
|
14
|
+
connect("BrowserDocumentCounter");
|
|
15
|
+
Elm.BrowserDocumentCounter.init({
|
|
16
|
+
node: "ignored", // this should be ignored by HMR: see https://github.com/klazuka/elm-hot/issues/14
|
|
17
|
+
flags: {
|
|
18
|
+
n: 0
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
</body>
|
|
23
|
+
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module BrowserElementCounter exposing (..)
|
|
2
|
+
|
|
3
|
+
import Browser
|
|
4
|
+
import Html exposing (Html, button, div, h1, p, span, text)
|
|
5
|
+
import Html.Attributes exposing (id)
|
|
6
|
+
import Html.Events exposing (onClick)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
main : Program Flags Model Msg
|
|
10
|
+
main =
|
|
11
|
+
Browser.element
|
|
12
|
+
{ init = init
|
|
13
|
+
, view = view
|
|
14
|
+
, update = update
|
|
15
|
+
, subscriptions = \_ -> Sub.none
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type alias Flags =
|
|
20
|
+
{ n : Int }
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
type alias Model =
|
|
24
|
+
{ count : Int }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
init : Flags -> ( Model, Cmd Msg )
|
|
28
|
+
init flags =
|
|
29
|
+
( { count = flags.n }, Cmd.none )
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
type Msg
|
|
33
|
+
= Increment
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
37
|
+
update msg model =
|
|
38
|
+
case msg of
|
|
39
|
+
Increment ->
|
|
40
|
+
( { model | count = model.count + 1 }
|
|
41
|
+
, Cmd.none
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
view : Model -> Html Msg
|
|
46
|
+
view model =
|
|
47
|
+
div []
|
|
48
|
+
[ h1 [] [ text "BrowserElementCounter" ]
|
|
49
|
+
, span [ id "code-version" ] [ text "code: v1" ]
|
|
50
|
+
, p []
|
|
51
|
+
[ text "Counter value is: "
|
|
52
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
53
|
+
]
|
|
54
|
+
, button [ onClick Increment, id "counter-button" ] [ text "+" ]
|
|
55
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Main</title>
|
|
7
|
+
<script type="text/javascript" src="client.js"></script>
|
|
8
|
+
<script type="text/javascript" src="build/BrowserElementCounter.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div id="embed">to be filled out later</div>
|
|
13
|
+
<script>
|
|
14
|
+
connect("BrowserElementCounter");
|
|
15
|
+
Elm.BrowserElementCounter.init({
|
|
16
|
+
node: document.getElementById('embed'),
|
|
17
|
+
flags: {
|
|
18
|
+
n: 0
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
</body>
|
|
23
|
+
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module BrowserSandboxCounter exposing (..)
|
|
2
|
+
|
|
3
|
+
import Browser
|
|
4
|
+
import Html exposing (Html, button, div, h1, p, span, text)
|
|
5
|
+
import Html.Attributes exposing (id)
|
|
6
|
+
import Html.Events exposing (onClick)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
main : Program () Model Msg
|
|
10
|
+
main =
|
|
11
|
+
Browser.sandbox
|
|
12
|
+
{ init = init
|
|
13
|
+
, view = view
|
|
14
|
+
, update = update
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
type alias Model =
|
|
19
|
+
{ count : Int }
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
init : Model
|
|
23
|
+
init =
|
|
24
|
+
{ count = 0 }
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
type Msg
|
|
28
|
+
= Increment
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
update : Msg -> Model -> Model
|
|
32
|
+
update msg model =
|
|
33
|
+
case msg of
|
|
34
|
+
Increment ->
|
|
35
|
+
{ model | count = model.count + 1 }
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
view : Model -> Html Msg
|
|
39
|
+
view model =
|
|
40
|
+
div []
|
|
41
|
+
[ h1 [] [ text "BrowserSandboxCounter" ]
|
|
42
|
+
, span [ id "code-version" ] [ text "code: v1" ]
|
|
43
|
+
, p []
|
|
44
|
+
[ text "Counter value is: "
|
|
45
|
+
, span [ id "counter-value" ] [ text (String.fromInt model.count) ]
|
|
46
|
+
]
|
|
47
|
+
, button [ onClick Increment, id "counter-button" ] [ text "+" ]
|
|
48
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Main</title>
|
|
7
|
+
<script type="text/javascript" src="client.js"></script>
|
|
8
|
+
<script type="text/javascript" src="build/BrowserSandboxCounter.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div id="embed">to be filled out later</div>
|
|
13
|
+
<script>
|
|
14
|
+
connect("BrowserSandboxCounter");
|
|
15
|
+
Elm.BrowserSandboxCounter.init({
|
|
16
|
+
node: document.getElementById('embed')
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|