Maybe programWithFlags is better but from what I can see it works only with Elm.Main.fullscreen syntax.So it can't be mounted to the specific part of the page. On the other side, Elm.Main.embed can be mounted to the DOM node, but it can't pass flags for programWithFlags. Is it possible to pass flags AND to mount Elm app to the given DOM node?
On Tuesday, June 7, 2016 at 2:40:20 AM UTC+1, Noah Gordon wrote: > > Take a look at `Html.App.programWithFlags`: > http://package.elm-lang.org/packages/elm-lang/html/1.0.0/Html-App#programWithFlags > > I'm pretty sure it was created with the 0.17 release specifically for this > purpose -- to import arbitrary data on initialization. Would probably be > cleaner than `setTimeout`! > > On Monday, June 6, 2016 at 9:09:43 PM UTC-4, Jaroslaw Zabiello wrote: >> >> It looks, like I can have 0 delay with setTimeout and it works. :) >> >> const app = Elm.Main.embed(document.querySelector('#app')\); >> setTimeout(function () { >> // Elm is ready to receive data >> app.ports.loadData.send(window.__DATA); >> }, 0); >> >> >> On Tuesday, June 7, 2016 at 1:57:00 AM UTC+1, Jaroslaw Zabiello wrote: >>> >>> I need to import some initial data from JS to Elm as fast as possible, >>> just after Elm app is embed to HTML page. The problem is I don't know how >>> much time I need for Elm to be ready for port communication from JS to Elm. >>> Definitely it can't be done just after mounting Elm to the page. >>> >>> The one solution would be delaying the transmission with SetTimeout like: >>> >>> >>> const elmDiv = document.querySelector('#app'); >>> const elmApp = Elm.Main.embed(elmDiv); >>> >>> setTimeout(function () { >>> elmApp.ports.loadData.send(window.__DATA); >>> }, 1000); >>> >>> >>> But I don't like to use arbitrary, artificial delay in the >>> communication. >>> >>> The another solution would be sending IsReady message from Elm to JS >>> first, subscribe to it, and from the subscription start sending data back >>> to Elm. >>> >>> elmApp.ports.isReady.subscribe(function() { >>> elmApp.ports.loadData.send(window.__DATA); >>> }); >>> >>> Is there any other way? A kind of callback to notify Elm is mounted and >>> ready for receiving data? >>> >>> Elm.Main.embed(elmDiv, function () { >>> // Elm is ready for receiving data from JS >>> this.port.loadData.send(myData); >>> }) >>> >>> -- 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.
