Realm.js you will see a function
shutdown(), here is why we bother with this shutdown routine: our elm app controls the document body, and we can simply start the next app when we are switching (we used to do this, but we found some issues).
Problem is the event handlers of the app that we are trying to unload/shutdown. Elm does not have .destroy() corresponding to .init(), to cleanly remove all the
click etc event handlers we have attached to our old app’s view. Similarly the subscriptions, can still keep on firing after the app is unloaded, leading to bugs and confusion.
The way it works is, Realm.App wraps the client application, and Realm.App receives the shutdown message we send:
When Realm.App gets this message, it stops calling client application’s view, instead it returns an empty view with a DOM element with unique ID (
appShutdownEmptyElement). When Elm’s virtual DOM library comes across this empty DOM, it deletes all the DOM, by cleanly removing all event handlers.
Further Realm.App does not call
subscriptions, so Elm removes subscription related event handlers too.
rustfmtFor Some Section