I wonder if the `json-to-elm` project includes what you're looking for.  I
see a Types.elm file that includes a toValue function:

toValue : String -> Json.Value
> toValue =
>     Native.Types.toValue
>

And in the Native.Types module, a definition of toValue that uses native
javascript:

    var toValue = function(text){
>         try {
>             return JSON.parse(text);
>         } catch (e) {
>             return {};
>         }
>     };
>




On Fri, Jul 29, 2016 at 2:33 PM, Paul Blair <[email protected]> wrote:

> Duane, the dictionary has string keys; its values are just values of a
> union type--they are not modules in themselves, but just tags that the case
> statement can key on in order to decide on which module to send the message
> to.
>
> On the second point, the top-level component knows enough about the
> incoming message to get the value from the message_type key. The type of
> the data field is opaque to the top-level; the top-level just sees it as
> Json.Value. This does in fact work; it's just hard to test.
>
>
> On Fri, Jul 29, 2016 at 3:47 PM, Duane Johnson <[email protected]>
> wrote:
>
>>
>> On Fri, Jul 29, 2016 at 12:52 PM, Paul Blair <[email protected]> wrote:
>>
>>> toMessage : FromServer -> Message
>>> toMessage incoming =
>>>   case Dict.get incoming.message_type componentDictionary of
>>>     Just MyInnerComponent ->
>>>       InnerComponentModule.toMessage incoming |>
>>> MyInnerComponentMessageWrapper
>>>     Nothing ->
>>>       ...
>>>
>>
>>
>> I'm still learning Elm, so forgive that this is not necessarily going to
>> be expert advice :)
>>
>> My first question is, what is the type of `componentDictionary`? It looks
>> to me like it has `String` type keys, but then I don't understand what the
>> type signature of the value is. `Maybe type`? How can you match on `Just
>> MyInnerComponent`?
>>
>> Second question: it seems like the top-level component *must* know
>> something about the messages in order to route to subcomponents. Can you
>> include a list of json keys in that routing information, so that you can
>> pass a narrower scope of data into each subcomponent? It seems like if you
>> can, that would make your testing story a lot easier.
>>
>> Duane
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Elm Discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/elm-discuss/fwDl6deEC1Q/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to