miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Reload

Contents

Description

Support for live reloading of miso applications.

Live Reload

This module exposes two functions meant to be used during interactive development with GHC WASM browser mode, live and reload.

Reload

Use reload if you'd like to redraw the page on each file change, resetting the working application state.

main :: IO ()
main = reload defaultEvents app

Live

Use live if you'd like to persist the working application state (all Component model) between GHCi reloads. This only works if you do not alter the model schema (e.g. add, remove, change a field's type).

main :: IO ()
main = live defaultEvents app

See the miso-sampler for example usage.

Synopsis

Functions

reload :: Eq model => Events -> App model action -> IO () Source #

Clears the <body> and <head> on each reload.

Meant to be used with WASM browser mode.

main :: IO ()
main = reload defaultEvents app

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

live :: Eq model => Events -> App model action -> IO () Source #

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 = live defaultEvents app

Since: 1.9.0.0