Not because this guide is any good, but because it is the only one.
This is (to the best of my knowledge) correct as of version 19.0 of the elm compiler and version 1.0.2 of elm/core
.
Cmd
s- Port
Cmd
s (I believe these to be fundamentally different from normalCmd
s). Sub
s.Tasks
s (although maybe these are just a precursor to normalCmd
s).
An event manager is a collection of specially named elm functions (helped by some special syntax) contained within an event manager elm module.
These functions have access to some state which they can modify (via a pure update function).
An effect manager elm module starts with effect module ModuleName where { command = MyCmd, subscription = MySub } exposing (..)
if the module does not contain any function that create Cmd
s then the command = MyCmd,
is ommitted (likewise for the , subscription = MySub
part).
- A
Cmd
event manager is a javascript object.init
,onEffects
,onSelfMsg
andcmdMap
are elm functions defined in the effect manager elm module.
{
__init: init,
__onEffects: onEffects,
__onSelfMsg: onSelfMsg,
__cmdMap: cmdMap,
__subMap: undefined
};
- A port
Cmd
event manager (created by the elm compiler for everyport x : SomeType -> Cmd never
) is different from a normalCmd
event manager.
{
__cmdMap: _Platform_outgoingPortMap,
__converter: converter,
__portSetup: _Platform_setupOutgoingPort
}
See the definition of _Platform_outgoingPortMap
and _Platform_setupOutgoingPort
.
converter
is an elm function with type annotation: converter: SomeType -> Json.Encode.Value
.
3. A Sub
event manager is very similar to a Cmd
event manager.
init
, onEffects
, onSelfMsg
and subMap
are elm functions defined in the effect manager elm module.
{
__init: init,
__onEffects: onEffects,
__onSelfMsg: onSelfMsg,
__cmdMap: 0,
__subMap: subMap
};
I believe the __cmdMap
is set to 0
rather than undefined
to save bits.
-
Using an effect manager for debouncing. This is written for elm 18 but nothing has changed (I believe). http://simonh1000.github.io/2017/05/effect-managers/
-
A (non
elm/*
) example of an effect manager. Probably elm 18. https://gist.github.com/maxhoffmann/117e0d31e7976a40477738975f4903d3 -
This one is not that informative. https://newfivefour.com/elm-lang-effects-managers-basics.html
-
Don't write effect managers. https://discourse.elm-lang.org/t/please-help-how-to-start-writing-an-effect-manager-module/1405