I encountered this problem with the UI not updating (and the results of any 
user input, clicks, etc. queued but not handled) as well with the same 
"setTimeout" solution to get Elm to update the view and handle the events.

The requirement for the setTimeout is the same as for JavaScript:  As the 
process queue handling is a computation chain that is executed on a single 
thread, there are no breaks to handle UI updates (and input responses) and 
these updates are generally not performed until the whole chain of events 
is complete as to to a "Cmd.none".  By adding a "setTimeout", one breaks 
the chain so that UI can be handled.  There are actually some JS 
"setTimeout"'s automatically inserted into the process chain at intervals, 
but these are after a high number of process elements so won't make the UE 
response as immediate as one would like even if there is a lot of 
processing going on.  Thus, the need for this hack.

On Monday, 13 June 2016 15:27:43 UTC+7, Pietro Grandi wrote:
>
> Hi Tobias,
> I'm doing the same tutorial and trying to re-write it for the 0.17.
>
> I also stumbled across the timeout issue: basically without the timeout I 
> can't see any message I send to the port from javascript.
> Is there any clue about the reason why is it behaving this way?
>
> Since I'm making POCs to introduce ELM to our office it would be better to 
> be able to explaing why instead of just syncronize the rest of the app with 
> the elm part.
>
> Thanks!
>
> On Wednesday, May 11, 2016 at 11:23:06 AM UTC+2, Tobias Burger wrote:
>>
>> I think I've figured it out of how to get elm working with embed: 
>> https://github.com/toburger/elm-todomvc/tree/feature/elm17
>>
>>
>>    - You create your project like any other elm-lang/html project
>>    - You can create a dummy view or a view with some functionality
>>    *There is one advantage with creating a real view: you can test your 
>>    code with elm reactor and you don't have to compile your code every time 
>>    you make some changes.*
>>    - The ports story on the JS side hasn't changed, however you have to 
>>    invoke the elm code slightly different than before.
>>    However, to dispatch the messages I had to wrap then inside a 
>>    setTimeout function, don't know why...
>>    On the Elm code side I had to migrate from Signals to Sub, wasn't 
>>    that hard, BUT, and I think this is a bug: If you look at the signature 
>>    of dispatchDestroyCompleted, I had to use a "List Int" instead of a (), 
>>    because somehow it was transpiled as a Tuple and I got a runtime error 
>>    telling me, that it could not find Tuple0.
>>
>>
>> Am Mittwoch, 11. Mai 2016 10:30:30 UTC+2 schrieb John Orford:
>>>
>>> Yeh I checked just after I sent the email. Looks like that is the case...
>>>
>>> On Wed, 11 May 2016 at 10:28 Tobias Burger <stob...@gmail.com> wrote:
>>>
>>>> Yes, but it forces you to create a Html.App as far as I understand it.
>>>> Embed allowed you to have a "headless" elm application, where the logic 
>>>> was encapsulated in elm and the UI could be rendered by JavaScript (e.g. 
>>>> React).
>>>>
>>>>
>>>> Am Mittwoch, 11. Mai 2016 10:17:39 UTC+2 schrieb John Orford:
>>>>
>>>>> Have you tried looking at the guide?
>>>>>
>>>>> http://guide.elm-lang.org/interop/javascript.html
>>>>>
>>>>> It worked for updating my embedding code.
>>>>>
>>>>> On Wed, 11 May 2016 at 10:07 Tobias Burger <stob...@gmail.com> wrote:
>>>>>
>>>> I'm struggling on how to embed elm code as a worker in existing 
>>>>>> JavaScript code.
>>>>>> There exists this example for elm 0.16: 
>>>>>> http://tech.noredink.com/post/126978281075/walkthrough-introducing-elm-to-a-js-web-app
>>>>>> But I have problems in getting this code to work in elm 0.17.
>>>>>>
>>>>>> -- 
>>>>>> 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...@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...@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