Yay, deployed: https://github.com/cuducos/cunhajacaiu

It's a tiny project that I use to test my Elm skills and, surely, to learn
Elm.

Nothing very complex, Elm is updating the stopwatch, and loading the news —
loading both initial data from different JSON API (but once loaded, no
interaction is done but the “tick” from the stopwatch).

Except exercises and tutorials, this is my very first Elm project, so
probably there is a lot to improve (suggestions, comments, critiques, etc
are more than welcome).

The Elm modules are in cunhajacaiu/static/elm
<https://github.com/cuducos/cunhajacaiu/tree/master/cunhajacaiu/static/elm>

Many thanks for all the help, guys,


Eduardo Cuducos
http://cuducos.me/

On Tue, Jul 26, 2016 at 1:47 PM, Peter Damoc <pda...@gmail.com> wrote:

> To paraphrase Satchmo, "If lots more of us helped each other, we’d solve
> lots more problems. And then this world would be better."
> I'm glad I could help. ;)
>
>
> On Tue, Jul 26, 2016 at 2:27 PM, Eduardo Cuducos <cudu...@gmail.com>
> wrote:
>
>> Peter, thank you so much.
>>
>> You could be very mean due to my typo. Still you helped me a lot
>> combining Json.Decode.decodeString and Debug.log something I would take
>> ages to figure out.
>>
>> I could get it to work with local (sample) and real data now! I'll update
>> this topic once the code is up on GitHub ; )
>>
>> Thank you very much.
>>
>> On Tue, Jul 26, 2016 at 12:48 PM Peter Damoc <pda...@gmail.com> wrote:
>>
>>> OK,
>>>
>>> So, first, you had a typo in the decoder. it says "chidren" instead
>>> of "children"
>>>
>>> This is why it is better to first debug the decoder with fake but valid
>>> data and then move to retrieve the data from a live source.
>>>
>>> You do this by just prettifying the json and pasting it into a triple
>>> quote string value.
>>> And then you use Json.Decode.decodeString with this string value and
>>> inspect the result using Debug.log
>>>
>>> Here is how I modified your model to inspect:
>>>
>>>
>>> decodeJson =
>>>     let
>>>         data =
>>>             Debug.log "" (Json.decodeString decodeNews json_data)
>>>     in
>>>         Result.withDefault [] data
>>>
>>>
>>> model : Model
>>> model =
>>>     { news = decodeJson }
>>>
>>>
>>> I've used only the first two items from the json because it seams to
>>> trigger another error.
>>> I don't have time to investigate further but it seams that the Json
>>> library considers the JSON invalid and it looks like it's happening around
>>> stuff like this:
>>>
>>> "content":"&lt;iframe class="embedly-embed"
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Jul 26, 2016 at 12:33 PM, Eduardo Cuducos <cudu...@gmail.com>
>>> wrote:
>>>
>>>> Ow, sorry — thanks for letting me know, Peter.
>>>> Here are the correct links:
>>>>
>>>>    - Original JSON: https://www.reddit.com/search.json?q=subreddit:elm
>>>>    - My code so far:
>>>>    https://gist.github.com/cuducos/479ff955e3a8e18616f1905ae0a38774
>>>>
>>>> Peter, if I create a small JSON should I put it in a (local) HTTP or
>>>> Json.Decoder loads from the file system?
>>>>
>>>> Many thanks,
>>>>
>>>> On Tue, Jul 26, 2016 at 10:47 AM Peter Damoc <pda...@gmail.com> wrote:
>>>>
>>>>> The links you tried to post are broken.
>>>>>
>>>>> Have you tried creating a small sample JSON to test your decoders on?
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Jul 26, 2016 at 11:17 AM, Eduardo Cuducos <cudu...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I'm tryind to parse Reddit JSON
>>>>>> <#m_5531829199268513028_m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>>>>>  but I think I'm failing at the Json.Decoder— however I'm not sure
>>>>>> if that really is the problem, and I don't know what else to try.
>>>>>>
>>>>>> The (ugly) JSON has this format (not so ugly after cleaned up, BTW):
>>>>>>
>>>>>> {
>>>>>>   "data": {
>>>>>>     "children": [
>>>>>>       {
>>>>>>         "data": {
>>>>>>           "title": "Post title",
>>>>>>           "url": "http://po.st/url";,
>>>>>>           "domain": "po.st",
>>>>>>           …
>>>>>>         },
>>>>>>         …
>>>>>>       },
>>>>>>       …
>>>>>>     ],
>>>>>>     …
>>>>>>   }
>>>>>>   …}
>>>>>>
>>>>>> I want to parse the title, url and domain inside
>>>>>> data.children[i].data (where i stands for each element of the
>>>>>> list/array) in news list from my Elm model:
>>>>>>
>>>>>> type alias NewsItem =
>>>>>>     { title : String
>>>>>>     , url : String
>>>>>>     , domain : String
>>>>>>     }
>>>>>> type alias Model =
>>>>>>     { news : List NewsItem }
>>>>>>
>>>>>> I've tried this without success:
>>>>>>
>>>>>> decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
>>>>>>     Json.object3 NewsItem
>>>>>>         (Json.at ["data", "title"] Json.string)
>>>>>>         (Json.at ["data", "url"] Json.string)
>>>>>>         (Json.at ["data", "domain"] Json.string)
>>>>>> decodeNews : Json.Decoder (List NewsItem)decodeNews =
>>>>>>     Json.at ["data", "chidren"] (Json.list decodeNewsItem)
>>>>>>
>>>>>> The compiler throws no error at all, but once I open it (either with
>>>>>> elm-reactor or the HTML from elm-make) the screen is blank (no
>>>>>> errors, but no posts actually loaded from Reddit):
>>>>>>
>>>>>> What am I doing wrong? The full Elm script, with Task and init is
>>>>>> here
>>>>>> <#m_5531829199268513028_m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>>>>> .
>>>>>>
>>>>>> Many thanks,
>>>>>>
>>>>>> Eduardo Cuducos
>>>>>> http://cuducos.me
>>>>>> <#m_5531829199268513028_m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>>>>>
>>>>> --
>>>>>> 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 elm-discuss+unsubscr...@googlegroups.com.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> There is NO FATE, we are the creators.
>>>>> blog: http://damoc.ro/
>>>>>
>>>>> --
>>>>> 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 elm-discuss+unsubscr...@googlegroups.com.
>>>>> 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 elm-discuss+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> There is NO FATE, we are the creators.
>>> blog: http://damoc.ro/
>>>
>>> --
>>> 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 elm-discuss+unsubscr...@googlegroups.com.
>>> 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 elm-discuss+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>
> --
> 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 elm-discuss+unsubscr...@googlegroups.com.
> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to