Modular generated code for widgets

70 views
Skip to first unread message

Tim Stewart

unread,
Sep 2, 2015, 2:28:12 AM9/2/15
to Elm Discuss
I'm learning Elm (it's fascinating!) and I'd quite like to experiment with some Elm widgets inside a larger existing app. I'd be including different widgets on different pages. Is it possible to compile Elm widgets to separate files _without_ the full Elm runtime in each, and then include them separately after the Elm runtime and before the calls to Elm.embed? Something like:

<script src="Elm.js"></script>
<script src="MyGraphWidget.Elm.js"></script>
<script src="MyCarouselWidget.Elm.js></script>
<script>
  Elm.embed(Elm.MyGraphWidget, $("#graph-div")[0]);
  Elm.embed(Elm.MyCarouselWidget, $("#carousel-div")[0]);
</script>

I understand from here:


That it is possible to include them all in one file, I just haven't figured out whether they can be split up so each page only needs to load relevant code.

Thanks
Tim

Joey Eremondi

unread,
Sep 2, 2015, 2:31:49 AM9/2/15
to elm-d...@googlegroups.com
It's not currently a feature. However, if you take a look at the .elmo files in the elm-stuff/build-artifacts folder of your project, you'll see that it's just the generated JavaScript for a given module. You could probably piece these together to make a widget, and include the runtime once.

Be aware that this is probably not a very stable approach, since we're revising the object file format for 0.16.

--
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.

Sean Clark Hess

unread,
Sep 2, 2015, 10:36:01 AM9/2/15
to elm-d...@googlegroups.com
It sounds like lots of things are changing in 0.16. Do you have a rough idea of when that might ship? Weeks? Months?

Laszlo Pandy

unread,
Sep 2, 2015, 10:58:26 AM9/2/15
to elm-d...@googlegroups.com
Best guess: around 1 month. Don't hold me to it. Because there are a lot of changes it could be 2 months.

Corey Trampe

unread,
Sep 2, 2015, 11:24:22 AM9/2/15
to elm-d...@googlegroups.com

I've been tempted to ask the same. ("Are we there yet?!")

I predict an explosion of libraries when the official native story emerges. I'd wager there are a lot of us in kind of a holding pattern until then.

Many thanks to all the contributors for cooking up all this #awesomesauce.

Tim Stewart

unread,
Sep 2, 2015, 8:57:41 PM9/2/15
to Elm Discuss
Thanks for all the replies. When you say the object file format is changing for 0.16, is there any plan to also allow the generated JS files to be more modular? I.e. allow one Elm file and separate files for Elm.MyWidget?

I suggest looking at widgets like this is a good way to encourage adoption. It's quite hard for an Elm/FRP newbie to imagine biting off a whole complex SPA in a new paradigm, so widgets could be a good "gateway drug" :)
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@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+unsubscribe@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.
Reply all
Reply to author
Forward
0 new messages