Elmish.HotReload.Bolero is a package that enables (experimental) stateful hot-reloading of the Elmish pipeline for Bolero. The "stateful" part of the reloading means that your model is preserved between reloads and the screen is automatically refreshed.
This library is brand new, please open issues for any problems you encounter or suggestions you may have.
Enabling Bolero Reload comes in 2 parts. Elmish.HotReload relies on the Elmish model and message types to be obj in
order to hot-swap them individually at runtime.
- Use a compiler directive to indicate a
ProgramComponent<obj, obj>()will be used during debug, but a properly typedProgramComponentwill be used in Release. - Use
Program.withHotReloadto erase theProgramcomponent and indicate where yourviewandupdatefunctions live.
type MyApp () =
#if !DEBUG
inherit ProgramComponent<Model, Message> ()
#else
inherit ProgramComponent<obj, obj>()
#endif
override this.Program =
Program.mkProgram (fun _ -> initModel, Cmd.none) update view
|> Program.withErrorHandler (fun (msg, exn) -> printfn "Error: %s\n\n%A" msg exn)
#if DEBUG
|> Program.withHotReload (None) <@ view @> <@ update @>
#endif
- Install the
bolero-livetool with the following commanddotnet install -g bolero-live - Run
bolero-livefrom your Bolero project directory.
FCSWatch takes care of watching your project and compiling it when updates occur. FCS watch also exposes a WebHook to indicate when an update has occured. This webhook is received by the Bolero CLI tool which then reads the updated assemblies and updates the Bolero Web Server as well as all running clients.
The Bolero CLI Tool exposes a small webserver (to listen for the FCSWatch hook) and a SignalR Hub. The SignalR Hub is
used for client communication. When your Bolero app starts up, Elmish.HotReload.Bolero registers the client with the
SignalR Hub. After the CLI tool receives an update from FCSWatch the assemblies are streamed down to the client and
the pipeline is reloaded.
Elmish.HotReload also contains some logic for magically mapping from a previous type of model, to a newly updated
model. Currently the support is mainly aimed at models with the same shape can be mapped to themselves (an unfortunate
artifact of reloading requires this). Some other model changes are supported, with deeper, more robust support to follow.
-
Refreshing the page will only yield the latest updates if running in Debug mode.
This is because
FCSWatchdoes not currently update the distribution dll locations for Blazor and the bolero hotreload cli tool takes care of updated the default directory only. -
Some model and message type changes fail at runtime.
In order to do stateful hot-reloading,
Elmish.HotReloadmust infer how to fill in a new model shape from the old model shape, effort on this will continue, however not all use-cases may be captured at this time. To work around this issue, simple refresh your browser window.