| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Reload
Contents
Description
Overview
Miso.Reload supports hot-reloading of miso applications during
interactive development with GHC WASM browser mode (ghciwatch +
WASM GHCi). It provides two entry points that replace startApp in
your main:
reload- clears
<head>and<body>— full reset on every:r; model is lost live- clears
<body>only — model state survives:r
reload
Clears both <head> and <body>, kills any running scheduler thread,
and re-mounts the component from scratch. All application state is lost.
Use this when you are actively changing the model type.
main :: IO () main =reloaddefaultEventsapp
live
Clears only <body>, then re-mounts the component using the __old
model__ value recovered from the previous GHCi session via a C-heap
stable pointer. <head> injections (stylesheets, scripts) from the
previous session are preserved.
main :: IO () main =livedefaultEventsapp
Warning: live is unsafe if you change the model type between
reloads (adding, removing, or changing a field's type). Such a change
will produce a segfault because the old in-memory model is coerced
directly into the new type. Use reload whenever you alter the model
schema.
See also
- miso-sampler — reference project demonstrating
live - Miso.Runtime —
initComponentand component lifecycle - Miso.Event.Types —
defaultEventsused as first argument
Functions
Arguments
| :: Eq model | |
| => Events | Event delegation map (typically |
| -> App model action | Top-level application component to (re-)mount |
| -> IO () |
Clears the <body> and <head> on each reload.
Meant to be used with WASM browser mode.
main :: IO () main =reloaddefaultEventsapp
N.B. This also resets the internal component state. This means all currently
mounted components become unmounted and ComponentId are reset to their
original form factory.
If you'd like to preserve application state between calls to GHCi `:r`, see live.
Since: 1.9.0.0
Arguments
| :: Eq model | |
| => Events | Event delegation map (typically |
| -> App model action | Top-level application component to (re-)mount with preserved model state |
| -> IO () |
Live reloading. Persists all Component model between successive GHCi reloads.
This means application state should persist between GHCi reloads
Schema changes to model are currently unsupported. If you're
changing fields in model (adding, removing, changing a field's type), this
will more than likely segfault. If you change the view or update functions
it will be fine.
Use reload if you're changing the model frequently and live
if you're adjusting the view / update function logic.
main :: IO () main =livedefaultEventsapp
Since: 1.9.0.0