Neither of these lines are invoked when passing a value through a port. The first is called only when trying to parse a String
, like from the body of an HTTP response. There is also Json.Decode.decodeValue
which deals only with Value
s. The second line similarly is only invoked if you need to render a Value
to a String
by explicitly calling Json.Encode.encode
.
When the compiler generates code for ports it checks the type and sets up the appropriate converter from JS to Elm for that type. Lists and tuples, for example, get special treatment by getting converted to and from JS Arrays, but in the case of a Value
, the converter is identity
or Json.Decode.value
(the Decoder
analogue to identity
). No stringifying.
Generated port code for a Value
looks like this:
var $author$project$Module$portName = _Platform_outgoingPort('portName', $elm$core$Basics$identity);
var $author$project$Module$portName = _Platform_incomingPort('portName', $elm$json$Json$Decode$value);
Those generated arguments are used here https://github.com/elm/core/blob/master/src/Elm/Kernel/Platform.js#L363-L471
Flags are treated in the same manner as an incoming port.