3 ms·
So what ties together the model, update, and view? It looks to me like it is this Browser module, is that right? Not knowing Elm or Haskell syntax, I'm guessing
by Touche 8y ago
So what ties together the model, update, and view? It looks to me like it is this Browser module, is that right? Not knowing Elm or Haskell syntax, I'm guessing that Browser.sandbox is a function you call, passing in the model, update, and view functions.
Assuming that's all correct, how does Browser.sandbox, work exactly? In particular how does it know when to call Update?
At first glance it looks like it might massage the view and detect event listeners such as onClick in the button example, is that correct?
- hawkice 8y agoTurning Html Msg types into actual Dom nodes means hooking up the event handlers so that they call update with the Msg the event handler is given. Browser.sandbox is building the Dom nodes and has the update function.
- Touche 8y agoYeah, I got that far. How does it know what it should turn into an Update handler though?
- hawkice 8y agoYou pass it the update function, the one function handles all updates. Typically, you'll have a case statement in that function to dispatch it out to something more specific.
- neoberg 8y agoBrowser.sandbox, Browser.application etc. are your app's runtimes. (Or they are the doors to the runtime) Subscriptions or DOM elements can generate Msgs and every Msg causes an update cycle.
- rtfeldman 8y agoGreat question! You're correct, it's the Browser module. In Elm, the entire application state is a single immutable value, which Browser owns and only changes when it calls `update` and a new value gets returned. Browser calls `update` in response to these 3 situations: 1. An event handler from view (e.g. `onClick Foo` means Browser will call `update`, passing `Foo` as the message, whenever that element gets clicked) 2. A subscription fires (this is kinda like #1 except for global events instead of per-element handlers) 3. A command completes, and its resulting message needs to get sent to `update` Every interaction in Elm is modeled in terms of one of these!