A Lamdera package. It is not on package.elm-lang.org: the Lamdera compiler provides it, from static.lamdera.com, so lamdera install works and elm install does not.
Note: Elm has managed effects, meaning that things like HTTP requests or writing to disk are all treated as data in Elm. When this data is given to the Elm runtime system, it can do some “query optimization” before actually performing the effect. Perhaps unexpectedly, this managed effects idea is the heart of why Elm is so nice for testing, reuse, reproducibility, etc.
Elm has two kinds of managed effects: commands and subscriptions.
Tell the runtime that there are no commands.
When you need the runtime system to perform a couple commands, you can batch them together. Each is handed to the runtime at the same time, and since each can perform arbitrary operations in the world, there are no ordering guarantees about the results.
Note: Cmd.none and Cmd.batch [ Cmd.none, Cmd.none ] and Cmd.batch []
all do the same thing.
This function sends data to JS land. Below is an example of how to use it.
import Command
import Json.Encode
port copyToClipboardPort : Cmd Json.Encode.Value -> msg
copyToClipboard value =
Command.sendToJs "copyToClipboardPort" copyToClipboardPort valueCommands and Subscriptions with this type variable indicate that they can only be used on the frontend.
import Command exposing (Command, FrontendOnly)
import Effect.File.Select
download : Command FrontendOnly toMsg msg
download =
Effect.File.Select "/my-file.txt"Commands and Subscriptions with this type variable indicate that they can only be used on the backend.
import Command exposing (BackendOnly, Command)
import Effect.Lamdera exposing (ClientId)
sendData : ClientId -> Command BackendOnly toMsg msg
sendData clientId =
Effect.Lamdera.sendToFrontend clientId dataEscape hatch for Cmd msg values.
No tests can be applied to this value, it will be completely ignored by program-test.
You should not be using this function except temporarily in a progressive implementation of program-test.
A command is a way of telling Elm, “Hey, I want you to do this thing!” So if you want to send an HTTP request, you would need to command Elm to do it. Or if you wanted to ask for geolocation, you would need to command Elm to go get it.
Every
Cmdspecifies (1) which effects you need access to and (2) the type of messages that will come back into your application.Note: Do not worry if this seems confusing at first! As with every Elm user ever, commands will make more sense as you work through the Elm Architecture Tutorial and see how they fit into a real application!