elm-pages 3.0.0-beta.1 → 3.0.0-beta.12

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 (103) hide show
  1. package/README.md +10 -1
  2. package/codegen/elm-pages-codegen.js +803 -284
  3. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
  4. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
  5. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
  6. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  7. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  8. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  9. package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
  10. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
  11. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15368 -13272
  12. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  13. package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  14. package/generator/dead-code-review/elm.json +6 -5
  15. package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +141 -17
  16. package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +218 -0
  17. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
  18. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
  19. package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
  20. package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
  21. package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1326 -121
  22. package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14574 -12631
  23. package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
  24. package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
  25. package/generator/review/elm.json +6 -6
  26. package/generator/src/SharedTemplate.elm +1 -1
  27. package/generator/src/build.js +81 -51
  28. package/generator/src/cli.js +120 -42
  29. package/generator/src/codegen.js +11 -10
  30. package/generator/src/compatibility-key.js +1 -0
  31. package/generator/src/config.js +41 -0
  32. package/generator/src/dev-server.js +36 -56
  33. package/generator/src/elm-codegen.js +3 -0
  34. package/generator/src/generate-template-module-connector.js +0 -28
  35. package/generator/src/pre-render-html.js +31 -17
  36. package/generator/src/render-worker.js +1 -1
  37. package/generator/src/render.js +224 -37
  38. package/generator/src/request-cache.js +1 -0
  39. package/generator/src/rewrite-elm-json.js +3 -3
  40. package/generator/src/seo-renderer.js +11 -4
  41. package/generator/src/vite-utils.js +78 -0
  42. package/generator/template/app/Api.elm +1 -1
  43. package/generator/template/app/Site.elm +6 -1
  44. package/package.json +12 -13
  45. package/src/ApiRoute.elm +146 -11
  46. package/src/DataSource/Env.elm +27 -3
  47. package/src/DataSource/File.elm +1 -1
  48. package/src/DataSource/Internal/Request.elm +0 -5
  49. package/src/DataSource.elm +50 -53
  50. package/src/Form/Field.elm +1 -1
  51. package/src/Form.elm +33 -33
  52. package/src/Head/Seo.elm +16 -27
  53. package/src/Head.elm +237 -7
  54. package/src/HtmlPrinter.elm +7 -3
  55. package/src/MultiDict.elm +49 -0
  56. package/src/Pages/Generate.elm +548 -103
  57. package/src/Pages/GeneratorProgramConfig.elm +15 -0
  58. package/src/Pages/Internal/NotFoundReason.elm +3 -2
  59. package/src/Pages/Internal/Platform/Cli.elm +91 -27
  60. package/src/Pages/Internal/Platform/Cli.elm.bak +1276 -0
  61. package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
  62. package/src/Pages/Internal/Platform/GeneratorApplication.elm +455 -0
  63. package/src/Pages/Internal/Platform.elm +34 -27
  64. package/src/Pages/Manifest.elm +24 -0
  65. package/src/Pages/ProgramConfig.elm +6 -3
  66. package/src/Pages/Script.elm +100 -0
  67. package/src/PairingHeap.elm +137 -0
  68. package/src/Parser/Extra/String.elm +33 -0
  69. package/src/Parser/Extra.elm +69 -0
  70. package/src/ProgramTest/ComplexQuery.elm +360 -0
  71. package/src/ProgramTest/EffectSimulation.elm +122 -0
  72. package/src/ProgramTest/Failure.elm +367 -0
  73. package/src/ProgramTest/HtmlHighlighter.elm +116 -0
  74. package/src/ProgramTest/HtmlParserHacks.elm +58 -0
  75. package/src/ProgramTest/HtmlRenderer.elm +73 -0
  76. package/src/ProgramTest/Program.elm +30 -0
  77. package/src/ProgramTest/StringLines.elm +26 -0
  78. package/src/ProgramTest/TestHtmlHacks.elm +132 -0
  79. package/src/ProgramTest/TestHtmlParser.elm +201 -0
  80. package/src/ProgramTest.elm +2339 -0
  81. package/src/Query/Extra.elm +55 -0
  82. package/src/Result/Extra.elm +21 -0
  83. package/src/Server/Request.elm +2 -2
  84. package/src/Server/Session.elm +149 -83
  85. package/src/Server/SetCookie.elm +89 -31
  86. package/src/SimulatedEffect/Cmd.elm +69 -0
  87. package/src/SimulatedEffect/Http.elm +330 -0
  88. package/src/SimulatedEffect/Navigation.elm +69 -0
  89. package/src/SimulatedEffect/Ports.elm +62 -0
  90. package/src/SimulatedEffect/Process.elm +24 -0
  91. package/src/SimulatedEffect/Sub.elm +48 -0
  92. package/src/SimulatedEffect/Task.elm +252 -0
  93. package/src/SimulatedEffect/Time.elm +25 -0
  94. package/src/SimulatedEffect.elm +42 -0
  95. package/src/String/Extra.elm +6 -0
  96. package/src/Test/Http.elm +145 -0
  97. package/src/TestResult.elm +35 -0
  98. package/src/TestState.elm +305 -0
  99. package/src/Url/Extra.elm +100 -0
  100. package/src/Vendored/Diff.elm +321 -0
  101. package/src/Vendored/Failure.elm +217 -0
  102. package/src/Vendored/FormatMonochrome.elm +44 -0
  103. package/src/Vendored/Highlightable.elm +53 -0
@@ -0,0 +1,69 @@
1
+ module SimulatedEffect.Cmd exposing
2
+ ( none, batch
3
+ , map
4
+ )
5
+
6
+ {-| This module parallels [elm/core's `Platform.Cmd` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Platform-Cmd).
7
+
8
+ The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
9
+ to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
10
+
11
+ @docs none, batch
12
+
13
+ @docs map
14
+
15
+ -}
16
+
17
+ import ProgramTest exposing (SimulatedEffect)
18
+ import SimulatedEffect
19
+ import SimulatedEffect.Task as Task
20
+
21
+
22
+ {-| Tell the runtime that there are no commands.
23
+ -}
24
+ none : SimulatedEffect msg
25
+ none =
26
+ SimulatedEffect.None
27
+
28
+
29
+ {-| When you need the runtime system to perform a couple commands, you can batch them together.
30
+ -}
31
+ batch : List (SimulatedEffect msg) -> SimulatedEffect msg
32
+ batch =
33
+ SimulatedEffect.Batch
34
+
35
+
36
+ {-| Transform the messages produced by a command.
37
+ -}
38
+ map : (a -> msg) -> SimulatedEffect a -> SimulatedEffect msg
39
+ map f effect =
40
+ case effect of
41
+ SimulatedEffect.None ->
42
+ SimulatedEffect.None
43
+
44
+ SimulatedEffect.Batch effects ->
45
+ SimulatedEffect.Batch (List.map (map f) effects)
46
+
47
+ SimulatedEffect.Task t ->
48
+ t
49
+ |> Task.map f
50
+ |> Task.mapError f
51
+ |> SimulatedEffect.Task
52
+
53
+ SimulatedEffect.PortEffect portName value ->
54
+ SimulatedEffect.PortEffect portName value
55
+
56
+ SimulatedEffect.PushUrl url ->
57
+ SimulatedEffect.PushUrl url
58
+
59
+ SimulatedEffect.ReplaceUrl url ->
60
+ SimulatedEffect.ReplaceUrl url
61
+
62
+ SimulatedEffect.Back n ->
63
+ SimulatedEffect.Back n
64
+
65
+ SimulatedEffect.Load url ->
66
+ SimulatedEffect.Load url
67
+
68
+ SimulatedEffect.Reload skipCache ->
69
+ SimulatedEffect.Reload skipCache
@@ -0,0 +1,330 @@
1
+ module SimulatedEffect.Http exposing
2
+ ( get, post, request
3
+ , Header, header
4
+ , Body, emptyBody, stringBody, jsonBody
5
+ , Expect, expectString, expectJson, expectWhatever, Error
6
+ , expectStringResponse, Response
7
+ , task, Resolver, stringResolver
8
+ )
9
+
10
+ {-| This module parallels [elm/http's `Http` module](https://package.elm-lang.org/packages/elm/http/2.0.0/Http).
11
+ _Pull requests are welcome to add any functions that are missing._
12
+
13
+ The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
14
+ to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
15
+
16
+
17
+ # Requests
18
+
19
+ @docs get, post, request
20
+
21
+
22
+ # Header
23
+
24
+ @docs Header, header
25
+
26
+
27
+ # Body
28
+
29
+ @docs Body, emptyBody, stringBody, jsonBody
30
+
31
+
32
+ # Expect
33
+
34
+ @docs Expect, expectString, expectJson, expectWhatever, Error
35
+
36
+
37
+ # Elaborate Expectations
38
+
39
+ @docs expectStringResponse, Response
40
+
41
+
42
+ # Tasks
43
+
44
+ @docs task, Resolver, stringResolver
45
+
46
+ -}
47
+
48
+ import Http
49
+ import Json.Decode exposing (Decoder)
50
+ import Json.Encode
51
+ import ProgramTest exposing (SimulatedEffect, SimulatedTask)
52
+ import SimulatedEffect
53
+
54
+
55
+ {-| Create a `GET` request.
56
+ -}
57
+ get :
58
+ { url : String
59
+ , expect : Expect msg
60
+ }
61
+ -> SimulatedEffect msg
62
+ get r =
63
+ request
64
+ { method = "GET"
65
+ , headers = []
66
+ , url = r.url
67
+ , body = emptyBody
68
+ , expect = r.expect
69
+ , timeout = Nothing
70
+ , tracker = Nothing
71
+ }
72
+
73
+
74
+ {-| Create a `POST` request.
75
+ -}
76
+ post :
77
+ { url : String
78
+ , body : Body
79
+ , expect : Expect msg
80
+ }
81
+ -> SimulatedEffect msg
82
+ post r =
83
+ request
84
+ { method = "POST"
85
+ , headers = []
86
+ , url = r.url
87
+ , body = r.body
88
+ , expect = r.expect
89
+ , timeout = Nothing
90
+ , tracker = Nothing
91
+ }
92
+
93
+
94
+ {-| Create a custom request.
95
+ -}
96
+ request :
97
+ { method : String
98
+ , headers : List Header
99
+ , url : String
100
+ , body : Body
101
+ , expect : Expect msg
102
+ , timeout : Maybe Float
103
+ , tracker : Maybe String
104
+ }
105
+ -> SimulatedEffect msg
106
+ request r =
107
+ let
108
+ (Expect onResult) =
109
+ r.expect
110
+ in
111
+ SimulatedEffect.HttpTask
112
+ { method = r.method
113
+ , url = r.url
114
+ , headers =
115
+ case r.body of
116
+ EmptyBody ->
117
+ r.headers
118
+
119
+ StringBody body ->
120
+ header "Content-Type" body.contentType :: r.headers
121
+ , body =
122
+ case r.body of
123
+ EmptyBody ->
124
+ ""
125
+
126
+ StringBody body ->
127
+ body.content
128
+ , onRequestComplete = onResult >> SimulatedEffect.Succeed
129
+ }
130
+ |> SimulatedEffect.Task
131
+
132
+
133
+ {-| An HTTP header for configuring requests.
134
+ -}
135
+ type alias Header =
136
+ ( String, String )
137
+
138
+
139
+ {-| Create a `Header`.
140
+ -}
141
+ header : String -> String -> Header
142
+ header =
143
+ Tuple.pair
144
+
145
+
146
+ {-| Represents the body of a `Request`.
147
+ -}
148
+ type Body
149
+ = EmptyBody
150
+ | StringBody
151
+ { contentType : String
152
+ , content : String
153
+ }
154
+
155
+
156
+ {-| Create an empty body for your `Request`.
157
+ -}
158
+ emptyBody : Body
159
+ emptyBody =
160
+ EmptyBody
161
+
162
+
163
+ {-| Put some JSON value in the body of your `Request`. This will automatically
164
+ add the `Content-Type: application/json` header.
165
+ -}
166
+ jsonBody : Json.Encode.Value -> Body
167
+ jsonBody value =
168
+ StringBody
169
+ { contentType = "application/json"
170
+ , content = Json.Encode.encode 0 value
171
+ }
172
+
173
+
174
+ {-| Put some string in the body of your `Request`.
175
+ -}
176
+ stringBody : String -> String -> Body
177
+ stringBody contentType content =
178
+ StringBody
179
+ { contentType = contentType
180
+ , content = content
181
+ }
182
+
183
+
184
+ {-| Logic for interpreting a response body.
185
+ -}
186
+ type Expect msg
187
+ = Expect (Http.Response String -> msg)
188
+
189
+
190
+ {-| Expect the response body to be a `String`.
191
+ -}
192
+ expectString : (Result Http.Error String -> msg) -> Expect msg
193
+ expectString onResult =
194
+ Expect <|
195
+ \response ->
196
+ case response of
197
+ Http.BadUrl_ s ->
198
+ onResult (Err <| Http.BadUrl s)
199
+
200
+ Http.Timeout_ ->
201
+ onResult (Err Http.Timeout)
202
+
203
+ Http.NetworkError_ ->
204
+ onResult (Err Http.NetworkError)
205
+
206
+ Http.BadStatus_ metadata body ->
207
+ onResult (Err <| Http.BadStatus metadata.statusCode)
208
+
209
+ Http.GoodStatus_ _ body ->
210
+ onResult (Ok body)
211
+
212
+
213
+ {-| Expect a Response with a String body.
214
+ -}
215
+ expectStringResponse : (Result x a -> msg) -> (Response String -> Result x a) -> Expect msg
216
+ expectStringResponse toMsg onResponse =
217
+ Expect (onResponse >> toMsg)
218
+
219
+
220
+ {-| Expect the response body to be JSON.
221
+ -}
222
+ expectJson : (Result Http.Error a -> msg) -> Decoder a -> Expect msg
223
+ expectJson onResult decoder =
224
+ Expect <|
225
+ \response ->
226
+ case response of
227
+ Http.BadUrl_ s ->
228
+ onResult (Err <| Http.BadUrl s)
229
+
230
+ Http.Timeout_ ->
231
+ onResult (Err Http.Timeout)
232
+
233
+ Http.NetworkError_ ->
234
+ onResult (Err Http.NetworkError)
235
+
236
+ Http.BadStatus_ metadata _ ->
237
+ onResult (Err <| Http.BadStatus metadata.statusCode)
238
+
239
+ Http.GoodStatus_ _ body ->
240
+ case Json.Decode.decodeString decoder body of
241
+ Err jsonError ->
242
+ onResult (Err <| Http.BadBody <| Json.Decode.errorToString jsonError)
243
+
244
+ Ok value ->
245
+ onResult (Ok value)
246
+
247
+
248
+ {-| Expect the response body to be whatever.
249
+ -}
250
+ expectWhatever : (Result Error () -> msg) -> Expect msg
251
+ expectWhatever onResult =
252
+ Expect <|
253
+ \response ->
254
+ case response of
255
+ Http.BadUrl_ s ->
256
+ onResult (Err <| Http.BadUrl s)
257
+
258
+ Http.Timeout_ ->
259
+ onResult (Err Http.Timeout)
260
+
261
+ Http.NetworkError_ ->
262
+ onResult (Err Http.NetworkError)
263
+
264
+ Http.BadStatus_ metadata _ ->
265
+ onResult (Err <| Http.BadStatus metadata.statusCode)
266
+
267
+ Http.GoodStatus_ _ _ ->
268
+ onResult (Ok ())
269
+
270
+
271
+ {-| -}
272
+ type alias Error =
273
+ Http.Error
274
+
275
+
276
+ {-| -}
277
+ type alias Response body =
278
+ Http.Response body
279
+
280
+
281
+ {-| Just like [`request`](#request), but it creates a `Task`.
282
+ -}
283
+ task :
284
+ { method : String
285
+ , headers : List Header
286
+ , url : String
287
+ , body : Body
288
+ , resolver : Resolver x a
289
+ , timeout : Maybe Float
290
+ }
291
+ -> SimulatedTask x a
292
+ task r =
293
+ SimulatedEffect.HttpTask
294
+ { method = r.method
295
+ , url = r.url
296
+ , headers = r.headers
297
+ , body =
298
+ case r.body of
299
+ EmptyBody ->
300
+ ""
301
+
302
+ StringBody body ->
303
+ body.content
304
+ , onRequestComplete =
305
+ case r.resolver of
306
+ StringResolver f ->
307
+ f
308
+ }
309
+
310
+
311
+ {-| Describes how to resolve an HTTP task.
312
+ -}
313
+ type Resolver x a
314
+ = StringResolver (Response String -> SimulatedTask x a)
315
+
316
+
317
+ {-| Turn a response with a `String` body into a result.
318
+ -}
319
+ stringResolver : (Response String -> Result x a) -> Resolver x a
320
+ stringResolver f =
321
+ let
322
+ fromResult result =
323
+ case result of
324
+ Err x ->
325
+ SimulatedEffect.Fail x
326
+
327
+ Ok a ->
328
+ SimulatedEffect.Succeed a
329
+ in
330
+ StringResolver (f >> fromResult)
@@ -0,0 +1,69 @@
1
+ module SimulatedEffect.Navigation exposing
2
+ ( pushUrl, replaceUrl, back
3
+ , load, reload, reloadAndSkipCache
4
+ )
5
+
6
+ {-| This module parallels [elm/browsers's `Browser.Navigation` module](https://package.elm-lang.org/packages/elm/browser/1.0.1/Browser-Navigation).
7
+ _Pull requests are welcome to add any functions that are missing._
8
+
9
+ The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
10
+ to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
11
+
12
+
13
+ # Navigate within Page
14
+
15
+ @docs pushUrl, replaceUrl, back
16
+
17
+
18
+ # Navigate to other Pages
19
+
20
+ @docs load, reload, reloadAndSkipCache
21
+
22
+ -}
23
+
24
+ import ProgramTest exposing (SimulatedEffect)
25
+ import SimulatedEffect
26
+
27
+
28
+ {-| Change the URL, but do not trigger a page load.
29
+ This will add a new entry to the browser history.
30
+ -}
31
+ pushUrl : String -> SimulatedEffect msg
32
+ pushUrl =
33
+ SimulatedEffect.PushUrl
34
+
35
+
36
+ {-| Change the URL, but do not trigger a page load.
37
+ This _will not_ add a new entry to the browser history.
38
+ -}
39
+ replaceUrl : String -> SimulatedEffect msg
40
+ replaceUrl =
41
+ SimulatedEffect.ReplaceUrl
42
+
43
+
44
+ {-| Go back some number of pages.
45
+ -}
46
+ back : Int -> SimulatedEffect msg
47
+ back =
48
+ SimulatedEffect.Back
49
+
50
+
51
+ {-| Leave the current page and load the given URL.
52
+ -}
53
+ load : String -> SimulatedEffect msg
54
+ load =
55
+ SimulatedEffect.Load
56
+
57
+
58
+ {-| Reload the current page.
59
+ -}
60
+ reload : SimulatedEffect msg
61
+ reload =
62
+ SimulatedEffect.Reload False
63
+
64
+
65
+ {-| Reload the current page without using the browser cache.
66
+ -}
67
+ reloadAndSkipCache : SimulatedEffect msg
68
+ reloadAndSkipCache =
69
+ SimulatedEffect.Reload True
@@ -0,0 +1,62 @@
1
+ module SimulatedEffect.Ports exposing (send, subscribe)
2
+
3
+ {-| This module provides functions that allow you to create `SimulatedEffect`s
4
+ that parallel [Elm ports](https://guide.elm-lang.org/interop/ports.html) used in your real program.
5
+ This is meant to be used
6
+ to help you implement the function to provide when using
7
+ [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects)
8
+ and [`ProgramTest.withSimulatedSubscriptions`](ProgramTest#withSimulatedSubscriptions).
9
+
10
+ For a detailed example, see the [“Testing programs with ports” guidebook](https://elm-program-test.netlify.com/ports.html).
11
+
12
+ @docs send, subscribe
13
+
14
+ -}
15
+
16
+ import Json.Decode
17
+ import Json.Encode
18
+ import ProgramTest exposing (SimulatedEffect, SimulatedSub)
19
+ import SimulatedEffect
20
+
21
+
22
+ {-| Creates a `SimulatedEffect` that parallels using an outgoing Elm port.
23
+
24
+ For example, if your production code uses a port like this:
25
+
26
+ port logMessage : String -> Cmd msg
27
+
28
+ logMessage "hello"
29
+
30
+ Then the corresponding `SimulatedEffect` would be:
31
+
32
+ SimulatedEffect.Ports.send "logMessage" (Json.Encode.string "hello")
33
+
34
+ -}
35
+ send : String -> Json.Encode.Value -> SimulatedEffect msg
36
+ send =
37
+ SimulatedEffect.PortEffect
38
+
39
+
40
+ {-| Creates a `SimulatedSub` that parallels using an incoming Elm port.
41
+
42
+ For example, if your production code uses a port like this:
43
+
44
+ port activeUsers : (List String -> msg) -> Sub msg
45
+
46
+ subscriptions : Model -> Sub Msg
47
+ subscriptions model =
48
+ activeUsers OnActiveUsersLoaded
49
+
50
+ Then the corresponding `SimulatedSub` would be:
51
+
52
+ simulatedSubscriptions : Model -> SimulatedSub Msg
53
+ simulatedSubscriptions model =
54
+ SimulatedEffect.Ports.subscribe
55
+ "activeUsers"
56
+ (Json.Decode.list Json.Decode.string)
57
+ OnActiveUsersLoaded
58
+
59
+ -}
60
+ subscribe : String -> Json.Decode.Decoder a -> (a -> msg) -> SimulatedSub msg
61
+ subscribe portName decoder toMsg =
62
+ SimulatedEffect.PortSub portName (Json.Decode.map toMsg decoder)
@@ -0,0 +1,24 @@
1
+ module SimulatedEffect.Process exposing (sleep)
2
+
3
+ {-| This module parallels [elm/core's `Process` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Process).
4
+ _Pull requests are welcome to add any functions that are missing._
5
+
6
+ The functions here produce `SimulatedEffect`s instead of `Cmd`s, which are meant to be used
7
+ to help you implement the function to provide when using [`ProgramTest.withSimulatedEffects`](ProgramTest#withSimulatedEffects).
8
+
9
+
10
+ # Processes
11
+
12
+ @docs sleep
13
+
14
+ -}
15
+
16
+ import ProgramTest exposing (SimulatedTask)
17
+ import SimulatedEffect
18
+
19
+
20
+ {-| Block progress on the current process for the given number of milliseconds.
21
+ -}
22
+ sleep : Float -> SimulatedTask x ()
23
+ sleep delay =
24
+ SimulatedEffect.SleepTask delay SimulatedEffect.Succeed
@@ -0,0 +1,48 @@
1
+ module SimulatedEffect.Sub exposing
2
+ ( none, batch
3
+ , map
4
+ )
5
+
6
+ {-| This module parallels [elm/core's `Platform.Sub` module](https://package.elm-lang.org/packages/elm/core/1.0.2/Platform-Sub).
7
+
8
+ The functions here produce `SimulatedSub`s instead of `Sub`s, which are meant to be used
9
+ to help you implement the function to provide when using [`ProgramTest.withSimulatedSubscriptions`](ProgramTest#withSimulatedSubscriptions).
10
+
11
+ @docs none, batch
12
+
13
+ @docs map
14
+
15
+ -}
16
+
17
+ import Json.Decode
18
+ import ProgramTest exposing (SimulatedEffect, SimulatedSub)
19
+ import SimulatedEffect
20
+
21
+
22
+ {-| Tell the runtime that there are no subscriptions.
23
+ -}
24
+ none : SimulatedSub msg
25
+ none =
26
+ SimulatedEffect.NoneSub
27
+
28
+
29
+ {-| When you need to subscribe to multiple things, you can create a `batch` of subscriptions.
30
+ -}
31
+ batch : List (SimulatedSub msg) -> SimulatedSub msg
32
+ batch =
33
+ SimulatedEffect.BatchSub
34
+
35
+
36
+ {-| Transform the messages produced by a subscription.
37
+ -}
38
+ map : (a -> msg) -> SimulatedSub a -> SimulatedSub msg
39
+ map f effect =
40
+ case effect of
41
+ SimulatedEffect.NoneSub ->
42
+ SimulatedEffect.NoneSub
43
+
44
+ SimulatedEffect.BatchSub effects ->
45
+ SimulatedEffect.BatchSub (List.map (map f) effects)
46
+
47
+ SimulatedEffect.PortSub name decoder ->
48
+ SimulatedEffect.PortSub name (Json.Decode.map f decoder)