Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:elm-programming [2020/07/05 06:42] alfred [Succeed] |
wiki2:elm-programming [2021/05/02 10:06] (actual) |
||
|---|---|---|---|
| Línea 64: | Línea 64: | ||
| in | in | ||
| ( model, cmd ) | ( model, cmd ) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ==== Trigger after one calling ==== | ||
| + | |||
| + | You can do something like this for sending message ''UpdateTotals'' with value 100: | ||
| + | <code> | ||
| + | GetAccount result -> case result of | ||
| + | Ok account -> ({model | account = account }, Task.succeed (UpdateTotals 100.0) |> Task.perform identity) | ||
| + | Err err -> log (toString err) (model, Cmd.none) | ||
| + | </code> | ||
| + | |||
| + | Or just define: | ||
| + | <code> | ||
| + | send : msg -> Cmd msg | ||
| + | send msg = Task.succeed msg |> Task.perform identity | ||
| </code> | </code> | ||
| Línea 135: | Línea 151: | ||
| ==== Flags. Js values on app initialization ==== | ==== Flags. Js values on app initialization ==== | ||
| - | Flags are a way to pass values into Elm on initialization. | + | Flags are a way to pass values into Elm on initialization. The idea is that you use the type of those values that are passed to your script for produce the first model status. |
| + | |||
| + | So an initial function like this: | ||
| + | <code> | ||
| + | init : () -> (Model, Cmd Msg) | ||
| + | init _ = | ||
| + | ( initialModel, Http.get{ url = "/api/bookmarks", expect = Http.expectJson BookmarksReceived resultsDecoder} ) | ||
| + | </code> | ||
| + | |||
| + | With Flags will be similar to this: | ||
| + | <code> | ||
| + | init : FlagsType -> (Model, Cmd Msg) | ||
| + | </code> | ||
| In JS we can create the application with the chosen flags: | In JS we can create the application with the chosen flags: | ||
| Línea 427: | Línea 455: | ||
| ==== Create a program without a view ==== | ==== Create a program without a view ==== | ||
| Use ''Platform.worker''. Documentation [[https://package.elm-lang.org/packages/elm/core/1.0.5/Platform#worker|here]]. | Use ''Platform.worker''. Documentation [[https://package.elm-lang.org/packages/elm/core/1.0.5/Platform#worker|here]]. | ||
| - | ===== Gotchas ===== | ||
| - | Every function that accepts two arguments can be converted in one that accepts one argument: | ||
| - | <code> | ||
| - | > String.repeat | ||
| - | <function> : Int -> String -> String | ||
| - | |||
| - | > String.repeat 4 | ||
| - | <function> : String -> String | ||
| - | </code> | ||