@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,136 @@
1
+ module BrowserApplicationCounter 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 =
12
+ Browser.application
13
+ { init = init
14
+ , view = view
15
+ , update = update
16
+ , subscriptions = \_ -> Sub.none
17
+ , onUrlRequest = LinkClicked
18
+ , onUrlChange = UrlChanged
19
+ }
20
+
21
+
22
+ type alias Flags =
23
+ { n : Int }
24
+
25
+
26
+ type alias Model =
27
+ { count : Int
28
+ , myNavKey : Nav.Key
29
+ , page : Page
30
+ }
31
+
32
+
33
+ type Page
34
+ = NotFound
35
+ | Incrementer
36
+ | Decrementer
37
+
38
+
39
+ init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
40
+ init flags url key =
41
+ ( loadPage url
42
+ { count = flags.n
43
+ , myNavKey = key
44
+ , page = NotFound
45
+ }
46
+ , Cmd.none
47
+ )
48
+
49
+
50
+ type Msg
51
+ = Increment
52
+ | Decrement
53
+ | LinkClicked UrlRequest
54
+ | UrlChanged Url
55
+
56
+
57
+ update msg model =
58
+ case msg of
59
+ Increment ->
60
+ ( { model | count = model.count + 1 }
61
+ , Cmd.none
62
+ )
63
+
64
+ Decrement ->
65
+ ( { model | count = model.count - 1 }
66
+ , Cmd.none
67
+ )
68
+
69
+ LinkClicked req ->
70
+ case req of
71
+ Browser.Internal url ->
72
+ ( model, Nav.pushUrl model.myNavKey (Url.toString url) )
73
+
74
+ Browser.External href ->
75
+ ( model, Nav.load href )
76
+
77
+ UrlChanged url ->
78
+ ( loadPage url model
79
+ , Cmd.none
80
+ )
81
+
82
+
83
+ loadPage : Url -> Model -> Model
84
+ loadPage url model =
85
+ { model
86
+ | page =
87
+ case url.fragment of
88
+ Nothing ->
89
+ Incrementer
90
+
91
+ Just "/incrementer" ->
92
+ Incrementer
93
+
94
+ Just "/decrementer" ->
95
+ Decrementer
96
+
97
+ _ ->
98
+ NotFound
99
+ }
100
+
101
+
102
+ view model =
103
+ let
104
+ pageBody =
105
+ case model.page of
106
+ Incrementer ->
107
+ div [ id "incrementer" ]
108
+ [ h1 [] [ text "Incrementer" ]
109
+ , p []
110
+ [ text "Counter value is: "
111
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
112
+ ]
113
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
114
+ , p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
115
+ ]
116
+
117
+ Decrementer ->
118
+ div [ id "decrementer" ]
119
+ [ h1 [] [ text "Decrementer" ]
120
+ , p []
121
+ [ text "Counter value is: "
122
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
123
+ ]
124
+ , button [ onClick Decrement, id "counter-button" ] [ text "-" ]
125
+ , p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
126
+ ]
127
+
128
+ NotFound ->
129
+ text "Page not found"
130
+ in
131
+ { title = "BrowserApplicationCounter"
132
+ , body =
133
+ [ span [ id "code-version" ] [ text "code: v1" ]
134
+ , pageBody
135
+ ]
136
+ }
@@ -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/BrowserApplicationCounter.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("BrowserApplicationCounter");
14
+ Elm.BrowserApplicationCounter.init({
15
+ flags: {
16
+ n: 0
17
+ }
18
+ });
19
+ </script>
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,137 @@
1
+ module BrowserApplicationCounterDeepKey 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 () 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 Model =
24
+ { count : Int
25
+
26
+ -- IMPORTANT: store the Nav.Key in a nested record to make sure that we an recover it during HMR
27
+ , keyHolder : { navKey : Nav.Key }
28
+ , page : Page
29
+ }
30
+
31
+
32
+ type Page
33
+ = NotFound
34
+ | Incrementer
35
+ | Decrementer
36
+
37
+
38
+ init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
39
+ init _ url key =
40
+ ( loadPage url
41
+ { count = 0
42
+ , keyHolder = { navKey = key }
43
+ , page = NotFound
44
+ }
45
+ , Cmd.none
46
+ )
47
+
48
+
49
+ type Msg
50
+ = Increment
51
+ | Decrement
52
+ | LinkClicked UrlRequest
53
+ | UrlChanged Url
54
+
55
+
56
+ update : Msg -> Model -> ( Model, Cmd msg )
57
+ update msg model =
58
+ case msg of
59
+ Increment ->
60
+ ( { model | count = model.count + 1 }
61
+ , Cmd.none
62
+ )
63
+
64
+ Decrement ->
65
+ ( { model | count = model.count - 1 }
66
+ , Cmd.none
67
+ )
68
+
69
+ LinkClicked req ->
70
+ case req of
71
+ Browser.Internal url ->
72
+ ( model, Nav.pushUrl model.keyHolder.navKey (Url.toString url) )
73
+
74
+ Browser.External href ->
75
+ ( model, Nav.load href )
76
+
77
+ UrlChanged url ->
78
+ ( loadPage url model
79
+ , Cmd.none
80
+ )
81
+
82
+
83
+ loadPage : Url -> Model -> Model
84
+ loadPage url model =
85
+ { model
86
+ | page =
87
+ case url.fragment of
88
+ Nothing ->
89
+ Incrementer
90
+
91
+ Just "/incrementer" ->
92
+ Incrementer
93
+
94
+ Just "/decrementer" ->
95
+ Decrementer
96
+
97
+ _ ->
98
+ NotFound
99
+ }
100
+
101
+
102
+ view : Model -> Browser.Document Msg
103
+ view model =
104
+ let
105
+ pageBody =
106
+ case model.page of
107
+ Incrementer ->
108
+ div [ id "incrementer" ]
109
+ [ h1 [] [ text "Incrementer" ]
110
+ , p []
111
+ [ text "Counter value is: "
112
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
113
+ ]
114
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
115
+ , p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
116
+ ]
117
+
118
+ Decrementer ->
119
+ div [ id "decrementer" ]
120
+ [ h1 [] [ text "Decrementer" ]
121
+ , p []
122
+ [ text "Counter value is: "
123
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
124
+ ]
125
+ , button [ onClick Decrement, id "counter-button" ] [ text "-" ]
126
+ , p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
127
+ ]
128
+
129
+ NotFound ->
130
+ text "Page not found"
131
+ in
132
+ { title = "BrowserApplicationCounterDeepKey"
133
+ , body =
134
+ [ span [ id "code-version" ] [ text "code: v1" ]
135
+ , pageBody
136
+ ]
137
+ }
@@ -0,0 +1,18 @@
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/BrowserApplicationCounterDeepKey.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("BrowserApplicationCounterDeepKey");
14
+ Elm.BrowserApplicationCounterDeepKey.init({});
15
+ </script>
16
+ </body>
17
+
18
+ </html>
@@ -0,0 +1,158 @@
1
+ module BrowserApplicationCounterMultiKey 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
40
+ -}
41
+ type Page
42
+ = NotFound Nav.Key
43
+ | Incrementer Nav.Key
44
+ | Decrementer Nav.Key
45
+
46
+
47
+ init : () -> Url -> Nav.Key -> ( Model, Cmd Msg )
48
+ init _ url key =
49
+ ( loadPage url
50
+ { count = 0
51
+ , page = NotFound key
52
+ }
53
+ , Cmd.none
54
+ )
55
+
56
+
57
+ type Msg
58
+ = Increment
59
+ | Decrement
60
+ | LinkClicked UrlRequest
61
+ | UrlChanged Url
62
+
63
+
64
+ update : Msg -> Model -> ( Model, Cmd Msg )
65
+ update msg model =
66
+ case msg of
67
+ Increment ->
68
+ ( { model | count = model.count + 1 }
69
+ , Cmd.none
70
+ )
71
+
72
+ Decrement ->
73
+ ( { model | count = model.count - 1 }
74
+ , Cmd.none
75
+ )
76
+
77
+ LinkClicked req ->
78
+ case req of
79
+ Browser.Internal url ->
80
+ ( model, Nav.pushUrl (getKey model.page) (Url.toString url) )
81
+
82
+ Browser.External href ->
83
+ ( model, Nav.load href )
84
+
85
+ UrlChanged url ->
86
+ ( loadPage url model
87
+ , Cmd.none
88
+ )
89
+
90
+
91
+ getKey : Page -> Nav.Key
92
+ getKey page =
93
+ case page of
94
+ NotFound key ->
95
+ key
96
+
97
+ Incrementer key ->
98
+ key
99
+
100
+ Decrementer key ->
101
+ key
102
+
103
+
104
+ loadPage : Url -> Model -> Model
105
+ loadPage url model =
106
+ { model
107
+ | page =
108
+ case url.fragment of
109
+ Nothing ->
110
+ Incrementer (getKey model.page)
111
+
112
+ Just "/incrementer" ->
113
+ Incrementer (getKey model.page)
114
+
115
+ Just "/decrementer" ->
116
+ Decrementer (getKey model.page)
117
+
118
+ _ ->
119
+ NotFound (getKey model.page)
120
+ }
121
+
122
+
123
+ view : Model -> Browser.Document Msg
124
+ view model =
125
+ let
126
+ pageBody =
127
+ case model.page of
128
+ Incrementer _ ->
129
+ div [ id "incrementer" ]
130
+ [ h1 [] [ text "Incrementer" ]
131
+ , p []
132
+ [ text "Counter value is: "
133
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
134
+ ]
135
+ , button [ onClick Increment, id "counter-button" ] [ text "+" ]
136
+ , p [] [ text "Switch to ", a [ id "nav-decrement", href "#/decrementer" ] [ text "decrementer" ] ]
137
+ ]
138
+
139
+ Decrementer _ ->
140
+ div [ id "decrementer" ]
141
+ [ h1 [] [ text "Decrementer" ]
142
+ , p []
143
+ [ text "Counter value is: "
144
+ , span [ id "counter-value" ] [ text (String.fromInt model.count) ]
145
+ ]
146
+ , button [ onClick Decrement, id "counter-button" ] [ text "-" ]
147
+ , p [] [ text "Switch to ", a [ id "nav-increment", href "#/incrementer" ] [ text "incrementer" ] ]
148
+ ]
149
+
150
+ NotFound _ ->
151
+ text "Page not found"
152
+ in
153
+ { title = "BrowserApplicationCounterMultiKey"
154
+ , body =
155
+ [ span [ id "code-version" ] [ text "code: v1" ]
156
+ , pageBody
157
+ ]
158
+ }
@@ -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/BrowserApplicationCounterMultiKey.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("BrowserApplicationCounterMultiKey");
14
+ Elm.BrowserApplicationCounterMultiKey.init({
15
+ flags: {
16
+ n: 0
17
+ }
18
+ });
19
+ </script>
20
+ </body>
21
+
22
+ </html>
@@ -0,0 +1,62 @@
1
+ module BrowserApplicationMissingNavKeyError exposing
2
+ ( Model
3
+ , Msg(..)
4
+ , init
5
+ , main
6
+ , update
7
+ , view
8
+ )
9
+
10
+ import Browser
11
+ import Browser.Navigation
12
+ import Html exposing (text)
13
+ import Url
14
+
15
+
16
+
17
+ {-
18
+
19
+ This example is only intended to verify that we gracefully handle
20
+ the case where the `Browser.Navigation.Key` cannot be found in the model.
21
+
22
+ See https://github.com/klazuka/elm-hot/issues/15 for more details.
23
+
24
+ -}
25
+
26
+
27
+ main : Program () Model Msg
28
+ main =
29
+ Browser.application
30
+ { view = view
31
+ , init = init
32
+ , update = update
33
+ , subscriptions = always Sub.none
34
+ , onUrlChange = always NoOp
35
+ , onUrlRequest = always NoOp
36
+ }
37
+
38
+
39
+ type Model
40
+ = FooBar
41
+
42
+
43
+ init : () -> Url.Url -> Browser.Navigation.Key -> ( Model, Cmd Msg )
44
+ init _ _ _ =
45
+ -- IMPORTANT: do not store the nav key in the model
46
+ ( FooBar, Cmd.none )
47
+
48
+
49
+ type Msg
50
+ = NoOp
51
+
52
+
53
+ update : Msg -> Model -> ( Model, Cmd Msg )
54
+ update _ model =
55
+ ( model, Cmd.none )
56
+
57
+
58
+ view : Model -> Browser.Document Msg
59
+ view _ =
60
+ { title = ""
61
+ , body = [ text "hi" ]
62
+ }
@@ -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/BrowserApplicationMissingNavKeyError.js"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <script>
13
+ connect("BrowserApplicationMissingNavKeyError");
14
+ Elm.BrowserApplicationMissingNavKeyError.init({
15
+ flags: {
16
+ n: 0
17
+ }
18
+ });
19
+ </script>
20
+ </body>
21
+
22
+ </html>