concept Elm Runtime in category elm

appears as: Elm Runtime, The Elm Runtime, Elm Runtime
Elm in Action

This is an excerpt from Manning's book Elm in Action.

Figure 2.6. The Elm Runtime uses The Elm Architecture to manage data flow.

Next, we’ll render a thumbnail for each photo in our list. At the top level of a typical Elm application is a single view function, which accepts our current model as an argument and then returns some Html. The Elm Runtime takes the Html returned by this view function and alters the page’s actual DOM to match it.

We’ve never needed the return value of Elm.PhotoGroove.init() before, but now we do. This object, typically named app, lets us subscribe to data that Elm sends to JavaScript via ports like setFilters. When the Elm Runtime executes the Cmd returned by setFilters, the callback function we’ve passed to app.ports.setFilters.subscribe will run. The options argument it accepts is the Filter-Options record Elm sent over, but converted from an Elm record to a JavaScript object.

One reason the Elm Runtime has good performance is that it skips unnecessary renders. See, browsers repaint the DOM as pixels on users’ screens only every so often. If the Elm Runtime changes part of the DOM, and then changes it again before the next repaint, the first change will have been wasted time; only the second change will be painted for users to see.