Hello everybody.
I’m interested on learn more about Elm Runtime. How it works and how is implemented in Javascript with particular focus on the subscription system.
Any documentation page about it?
rupert
January 5, 2023, 9:22am
2
I have never seen any documentation about it. Whenever I have messed with the runtime, to understand it, debug something or experiment with a change, I just read the code. Most of the time the code is very well written and easy to follow.
Thank you @rupert , can you point me to the runtime source code on Github?
lydell
January 5, 2023, 11:09am
4
I find it very hard to follow many times
You’ll find the code in the various elm/*
packages. For example:
/*
import Basics exposing (never)
import Browser exposing (Internal, External)
import Browser.Dom as Dom exposing (NotFound)
import Elm.Kernel.Debug exposing (crash)
import Elm.Kernel.Debugger exposing (element, document)
import Elm.Kernel.Json exposing (runHelp)
import Elm.Kernel.List exposing (Nil)
import Elm.Kernel.Platform exposing (initialize)
import Elm.Kernel.Scheduler exposing (binding, fail, rawSpawn, succeed, spawn)
import Elm.Kernel.Utils exposing (Tuple0, Tuple2)
import Elm.Kernel.VirtualDom exposing (appendChild, applyPatches, diff, doc, node, passiveSupported, render, divertHrefToApp)
import Json.Decode as Json exposing (map)
import Maybe exposing (Just, Nothing)
import Result exposing (isOk)
import Task exposing (perform)
import Url exposing (fromString)
*/
This file has been truncated. show original
/*
import Basics exposing (identity)
import Elm.Kernel.Debug exposing (crash)
import Elm.Kernel.Json exposing (equality, runHelp, unwrap, wrap)
import Elm.Kernel.List exposing (Cons, Nil)
import Elm.Kernel.Utils exposing (Tuple2)
import Elm.Kernel.Platform exposing (export)
import Json.Decode as Json exposing (map, map2, succeed)
import Result exposing (isOk)
import VirtualDom exposing (toHandlerInt)
*/
// HELPERS
var _VirtualDom_divertHrefToApp;
This file has been truncated. show original
What I like to do, is opening some compiled Elm app JS in VSCode (or your editor/IDE of choice) and read through the code there. “Go to definition” and “parameter name inlay hints” help tremendously. At the same time, I keep the source code on GitHub open for cross reference, because sometimes things are called just a
or b
in the compiled code but maybe __callback
in the source code.
You might also be interested in this repo:
It’s an attempt at documenting some things about the runtime and experimenting with a different implementation.
3 Likes
I’ve written two blog posts that deal with are tangentially related to this subject.
What if Elm didn't ship with a VDOM library? No HTML or SVG? You might be tempted that it wouldn't be very useful, but we can implement it ourselves using pure elm and ports. Ports? You heard right,...
Deals mostly with how rendering/events work from a conceptual perspective.
Might be also interesting, but it’s more about higher level architectural patterns.
1 Like
Very interesting. Thank you.
jerith
January 14, 2023, 10:40pm
7
The underlying runtime system is based on effects managers. You can google for “elm effects managers” to find some discussion, including:
effect-managers.md
# The best guide on event managers in elm
Not because this guide is any good, but because it is the only one.
This is (to the best of my knowledge) correct as of version 19.0 of the elm compiler and version 1.0.2 of `elm/core`.
## Types of event managed things in elm
1. `Cmd`s
2. Port `Cmd`s (I believe these to be fundamentally different from normal `Cmd`s).
3. `Sub`s.
This file has been truncated. show original
6 Likes
system
Closed
January 24, 2023, 10:41pm
8
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.