@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.
Files changed (52) hide show
  1. package/CHANGELOG +40 -0
  2. package/CODE_OF_CONDUCT.md +74 -0
  3. package/CONTRIBUTING.md +51 -0
  4. package/LICENSE.txt +33 -0
  5. package/README.md +84 -0
  6. package/package.json +37 -0
  7. package/resources/hmr.js +519 -0
  8. package/src/index.js +6 -0
  9. package/src/inject.js +46 -0
  10. package/test/client.js +63 -0
  11. package/test/fixtures/BrowserApplicationCounter.elm +136 -0
  12. package/test/fixtures/BrowserApplicationCounter.html +22 -0
  13. package/test/fixtures/BrowserApplicationCounterDeepKey.elm +137 -0
  14. package/test/fixtures/BrowserApplicationCounterDeepKey.html +18 -0
  15. package/test/fixtures/BrowserApplicationCounterMultiKey.elm +158 -0
  16. package/test/fixtures/BrowserApplicationCounterMultiKey.html +22 -0
  17. package/test/fixtures/BrowserApplicationMissingNavKeyError.elm +62 -0
  18. package/test/fixtures/BrowserApplicationMissingNavKeyError.html +22 -0
  19. package/test/fixtures/BrowserApplicationNavKeyMoved.elm +159 -0
  20. package/test/fixtures/BrowserApplicationNavKeyMoved.html +22 -0
  21. package/test/fixtures/BrowserApplicationWithNull.elm +142 -0
  22. package/test/fixtures/BrowserApplicationWithNull.html +22 -0
  23. package/test/fixtures/BrowserDocumentCounter.elm +57 -0
  24. package/test/fixtures/BrowserDocumentCounter.html +24 -0
  25. package/test/fixtures/BrowserElementCounter.elm +55 -0
  26. package/test/fixtures/BrowserElementCounter.html +24 -0
  27. package/test/fixtures/BrowserSandboxCounter.elm +48 -0
  28. package/test/fixtures/BrowserSandboxCounter.html +21 -0
  29. package/test/fixtures/DebugBrowserApplication.elm +139 -0
  30. package/test/fixtures/DebugBrowserApplication.html +22 -0
  31. package/test/fixtures/DebugEmbed.elm +48 -0
  32. package/test/fixtures/DebugEmbed.html +21 -0
  33. package/test/fixtures/DebugFullscreen.elm +57 -0
  34. package/test/fixtures/DebugFullscreen.html +22 -0
  35. package/test/fixtures/FullScreenEmptyInit.elm +51 -0
  36. package/test/fixtures/FullScreenEmptyInit.html +19 -0
  37. package/test/fixtures/InitSideEffects.elm +65 -0
  38. package/test/fixtures/InitSideEffects.html +27 -0
  39. package/test/fixtures/MainWithTasks.elm +70 -0
  40. package/test/fixtures/MainWithTasks.html +21 -0
  41. package/test/fixtures/MultiMain.html +21 -0
  42. package/test/fixtures/MultiMain1.elm +48 -0
  43. package/test/fixtures/MultiMain2.elm +48 -0
  44. package/test/fixtures/PortsEmbed.elm +64 -0
  45. package/test/fixtures/PortsEmbed.html +27 -0
  46. package/test/fixtures/PortsFullscreen.elm +70 -0
  47. package/test/fixtures/PortsFullscreen.html +26 -0
  48. package/test/fixtures/build.sh +29 -0
  49. package/test/fixtures/elm.json +24 -0
  50. package/test/server.js +73 -0
  51. package/test/test.js +320 -0
  52. package/test.sh +16 -0
@@ -0,0 +1,139 @@
1
+ module DebugBrowserApplication 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 Url exposing (Url)
9
+
10
+
11
+ main : Program Flags Model Msg
12
+ main =
13
+ Browser.application
14
+ { init = init
15
+ , view = view
16
+ , update = update
17
+ , subscriptions = \_ -> Sub.none
18
+ , onUrlRequest = LinkClicked
19
+ , onUrlChange = UrlChanged
20
+ }
21
+
22
+
23
+ type alias Flags =
24
+ { n : Int }
25
+
26
+
27
+ type alias Model =
28
+ { count : Int
29
+ , myNavKey : Nav.Key
30
+ , page : Page
31
+ }
32
+
33
+
34
+ type Page
35
+ = NotFound
36
+ | Incrementer
37
+ | Decrementer
38
+
39
+
40
+ init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
41
+ init flags url key =
42
+ ( loadPage url
43
+ { count = flags.n
44
+ , myNavKey = key
45
+ , page = NotFound
46
+ }
47
+ , Cmd.none
48
+ )
49
+
50
+
51
+ type Msg
52
+ = Increment
53
+ | Decrement
54
+ | LinkClicked UrlRequest
55
+ | UrlChanged Url
56
+
57
+
58
+ update : Msg -> Model -> ( Model, Cmd Msg )
59
+ update msg model =
60
+ case msg of
61
+ Increment ->
62
+ ( { model | count = model.count + 1 }
63
+ , Cmd.none
64
+ )
65
+
66
+ Decrement ->
67
+ ( { model | count = model.count - 1 }
68
+ , Cmd.none
69
+ )
70
+
71
+ LinkClicked req ->
72
+ case req of
73
+ Browser.Internal url ->
74
+ ( model, Nav.pushUrl model.myNavKey (Url.toString url) )
75
+
76
+ Browser.External href ->
77
+ ( model, Nav.load href )
78
+
79
+ UrlChanged url ->
80
+ ( loadPage url model
81
+ , Cmd.none
82
+ )
83
+
84
+
85
+ loadPage : Url -> Model -> Model
86
+ loadPage url model =
87
+ { model
88
+ | page =
89
+ case url.fragment of
90
+ Nothing ->
91
+ Incrementer
92
+
93
+ Just "/incrementer" ->
94
+ Incrementer
95
+
96
+ Just "/decrementer" ->
97
+ Decrementer
98
+
99
+ _ ->
100
+ NotFound
101
+ }
102
+
103
+
104
+ view : Model -> Browser.Document Msg
105
+ view model =
106
+ let
107
+ pageBody =
108
+ case model.page of
109
+ Incrementer ->
110
+ div [ id "incrementer" ]
111
+ [ h1 [] [ text "Incrementer" ]
112
+ , p []
113
+ [ text "Counter value is: "
114
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
115
+ ]
116
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
117
+ , p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
118
+ ]
119
+
120
+ Decrementer ->
121
+ div [ id "decrementer" ]
122
+ [ h1 [] [ text "Decrementer" ]
123
+ , p []
124
+ [ text "Counter value is: "
125
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
126
+ ]
127
+ , button [ onClick Decrement, id "counter-button" ] [ text "-" ]
128
+ , p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
129
+ ]
130
+
131
+ NotFound ->
132
+ text "Page not found"
133
+ in
134
+ { title = "DebugBrowserApplication"
135
+ , body =
136
+ [ span [ id "code-version" ] [ text "code: v1" ]
137
+ , pageBody
138
+ ]
139
+ }
@@ -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/DebugBrowserApplication.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("DebugBrowserApplication");
14
+ Elm.DebugBrowserApplication.init({
15
+ flags: {
16
+ n: 0
17
+ }
18
+ });
19
+ </script>
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,48 @@
1
+ module DebugEmbed 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 "DebugEmbed" ]
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/DebugEmbed.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="embed">to be filled out later</div>
13
+ <script>
14
+ connect("DebugEmbed");
15
+ Elm.DebugEmbed.init({
16
+ node: document.getElementById('embed')
17
+ });
18
+ </script>
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,57 @@
1
+ module DebugFullscreen 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 = "DebugFullscreen"
48
+ , body =
49
+ [ h1 [] [ text "DebugFullscreen" ]
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,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/DebugFullscreen.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("DebugFullscreen");
14
+ Elm.DebugFullscreen.init({
15
+ flags: {
16
+ n: 0
17
+ }
18
+ });
19
+ </script>
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,51 @@
1
+ module FullScreenEmptyInit 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 () 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 Model =
20
+ { count : Int }
21
+
22
+
23
+ init : () -> ( Model, Cmd Msg )
24
+ init _ =
25
+ ( { count = 0 }, Cmd.none )
26
+
27
+
28
+ type Msg
29
+ = Increment
30
+
31
+
32
+ update msg model =
33
+ case msg of
34
+ Increment ->
35
+ ( { model | count = model.count + 1 }
36
+ , Cmd.none
37
+ )
38
+
39
+
40
+ view model =
41
+ { title = "FullScreenEmptyInit"
42
+ , body =
43
+ [ h1 [] [ text "FullScreenEmptyInit" ]
44
+ , span [ id "code-version" ] [ text "code: v1" ]
45
+ , p []
46
+ [ text "Counter value is: "
47
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
48
+ ]
49
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
50
+ ]
51
+ }
@@ -0,0 +1,19 @@
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/FullScreenEmptyInit.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("FullScreenEmptyInit");
14
+ Elm.FullScreenEmptyInit.init(); // IMPORTANT: we pass NOTHING to `init()`
15
+ // this is allowed for `Browser.document` and `Browser.application`
16
+ </script>
17
+ </body>
18
+
19
+ </html>
@@ -0,0 +1,65 @@
1
+ port module InitSideEffects exposing (main)
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 =
10
+ Browser.element
11
+ { init = init
12
+ , view = view
13
+ , update = update
14
+ , subscriptions = subscriptions
15
+ }
16
+
17
+
18
+ port toJavaScript : Int -> Cmd msg
19
+
20
+
21
+ port fromJavaScript : (Int -> msg) -> Sub msg
22
+
23
+
24
+ type alias Model =
25
+ { count : Int }
26
+
27
+
28
+ init : () -> ( Model, Cmd Msg )
29
+ init _ =
30
+ -- start with -1 so that after the port is called from init, the count will be 0
31
+ -- and we can use the unmodified integration test counter sequence.
32
+ ( { count = -1 }, toJavaScript -1 )
33
+
34
+
35
+ type Msg
36
+ = Increment
37
+ | GotNewValue Int
38
+
39
+
40
+ update : Msg -> Model -> ( Model, Cmd msg )
41
+ update msg model =
42
+ case msg of
43
+ Increment ->
44
+ ( model, toJavaScript model.count )
45
+
46
+ GotNewValue _ ->
47
+ ( { model | count = model.count + 1 }, Cmd.none )
48
+
49
+
50
+ subscriptions : Model -> Sub Msg
51
+ subscriptions _ =
52
+ fromJavaScript GotNewValue
53
+
54
+
55
+ view : Model -> Html Msg
56
+ view model =
57
+ div []
58
+ [ h1 [] [ text "InitSideEffects" ]
59
+ , span [ id "code-version" ] [ text "code: v1" ]
60
+ , p []
61
+ [ text "Counter value is: "
62
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
63
+ ]
64
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
65
+ ]
@@ -0,0 +1,27 @@
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/InitSideEffects.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="embed">to be filled out later</div>
13
+ <script>
14
+ connect("InitSideEffects");
15
+ var app = Elm.InitSideEffects.init({
16
+ node: document.getElementById('embed'),
17
+ flags: {}
18
+ });
19
+
20
+ app.ports.toJavaScript.subscribe(function (n) {
21
+ console.log("received " + n + " from Elm");
22
+ app.ports.fromJavaScript.send(n);
23
+ });
24
+ </script>
25
+ </body>
26
+
27
+ </html>
@@ -0,0 +1,70 @@
1
+ module MainWithTasks exposing (..)
2
+
3
+ import Browser
4
+ import Html exposing (button, div, h1, p, span, text)
5
+ import Html.Attributes exposing (id)
6
+ import Html.Events exposing (onClick)
7
+ import Process
8
+ import Task
9
+
10
+
11
+ main : Program () Model Msg
12
+ main =
13
+ Browser.element
14
+ { init = init
15
+ , view = view
16
+ , update = update
17
+ , subscriptions = \_ -> Sub.none
18
+ }
19
+
20
+
21
+ type alias Model =
22
+ { count : Int }
23
+
24
+
25
+ init : () -> ( Model, Cmd Msg )
26
+ init _ =
27
+ ( { count = 0 }, Cmd.none )
28
+
29
+
30
+ type Msg
31
+ = Increment
32
+ | FinishedSleeping (Result String ())
33
+
34
+
35
+ millisToSleep : number
36
+ millisToSleep =
37
+ {- IMPORTANT: this MUST be in sync with the integration test -}
38
+ 5000
39
+
40
+
41
+ update : Msg -> Model -> ( Model, Cmd Msg )
42
+ update msg model =
43
+ case msg of
44
+ Increment ->
45
+ ( model
46
+ , Task.attempt FinishedSleeping (Process.sleep millisToSleep)
47
+ )
48
+
49
+ FinishedSleeping result ->
50
+ case result of
51
+ Ok _ ->
52
+ ( { model | count = model.count + 1 }
53
+ , Cmd.none
54
+ )
55
+
56
+ Err _ ->
57
+ ( model, Cmd.none )
58
+
59
+
60
+ view : Model -> Html.Html Msg
61
+ view model =
62
+ div []
63
+ [ h1 [] [ text "MainWithTasks" ]
64
+ , span [ id "code-version" ] [ text "code: v1" ]
65
+ , p []
66
+ [ text "Counter value is: "
67
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
68
+ ]
69
+ , button [ onClick Increment, id "counter-button" ] [ text "+ (delayed)" ]
70
+ ]
@@ -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/MainWithTasks.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="embed">to be filled out later</div>
13
+ <script>
14
+ connect("MainWithTasks");
15
+ Elm.MainWithTasks.init({
16
+ node: document.getElementById('embed')
17
+ });
18
+ </script>
19
+ </body>
20
+
21
+ </html>
@@ -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/MultiMain.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <div id="embed1">to be filled out later</div>
13
+ <div id="embed2">to be filled out later</div>
14
+ <script>
15
+ connect("MultiMain");
16
+ Elm.MultiMain1.init({ node: document.getElementById('embed1') });
17
+ Elm.MultiMain2.init({ node: document.getElementById('embed2') });
18
+ </script>
19
+ </body>
20
+
21
+ </html>
@@ -0,0 +1,48 @@
1
+ module MultiMain1 exposing (..)
2
+
3
+ import Browser
4
+ import Html exposing (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.Html Msg
39
+ view model =
40
+ div [ id "incrementer" ]
41
+ [ h1 [] [ text "MultiMain1" ]
42
+ , span [ id "code-version" ] [ text "code: inc-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,48 @@
1
+ module MultiMain2 exposing (..)
2
+
3
+ import Browser
4
+ import Html exposing (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
+ = Decrement
29
+
30
+
31
+ update : Msg -> Model -> Model
32
+ update msg model =
33
+ case msg of
34
+ Decrement ->
35
+ { model | count = model.count - 1 }
36
+
37
+
38
+ view : Model -> Html.Html Msg
39
+ view model =
40
+ div [ id "decrementer" ]
41
+ [ h1 [] [ text "MultiMain2" ]
42
+ , span [ id "code-version" ] [ text "code: dec-v1" ]
43
+ , p []
44
+ [ text "Counter value is: "
45
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
46
+ ]
47
+ , button [ onClick Decrement, id "counter-button" ] [ text "-" ]
48
+ ]