avh4 / avh4/elm-program-test

How about on examples use List Effects instend of Effect

Open
#74 1 comment 0 reactions 0 assignees View on GitHub
discussion
Dominant language
Elm
Stars
95
Forks
28
PR merge metrics
No merged PRs in 30d

Description

I had a problem to convert my code to use List Effect.
I followed the documentations and there just use Effect.

I written an apliccation and just on last time I must use two Cmds on the init function.
@avh4 Do you have better way to do this?

```elm
effectBatch : List Effect -> List (Cmd Msg)
effectBatch list =
List.map perform list
```

```elm

main : Program Encode.Value Model Msg
main =
Browser.element
{ view = view
, init = \flags -> init flags |> Tuple.mapSecond effectBatch |> Tuple.mapSecond Cmd.batch
, update =
\msg model ->
update msg model
|> Tuple.mapSecond effectBatch
|> Tuple.mapSecond Cmd.batch
, subscriptions = always Sub.none
}
```

```Elm
update : Msg -> Model -> ( Model, List Effect )
update msg model =
Tuple.mapSecond List.singleton <|
case msg of
```

```ELM
simulateEffectsTest : List Main.Effect -> PT.SimulatedEffect Main.Msg
simulateEffectsTest listOfEffect =
List.map simulateEffects listOfEffect
|> SimulatedEffect.Cmd.batch
```
```elm
start : Encode.Value -> PT.ProgramTest Main.Model Main.Msg (List Main.Effect)
start value =
PT.createElement
{ init = Main.init
, update = Main.update
, view = Main.view
}
|> PT.withSimulatedEffects simulateEffectsTest
|> PT.start value
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.