miso

Native (mobile)

Static mounting

Because component constructors, event handlers and effects may need to be reconstructed on the other thread, native miso threads them across the boundary as static pointers rather than closures. This requires the StaticPointers language extension.

The root component is mounted with mountStatic_ wrapped in static:

{-# LANGUAGE StaticPointers #-}
module Main where

import Miso
import Miso.Native

main :: IO ()
main = native nativeEvents (static (mountStatic_ app))

Child components are embedded in a view the same way, with vcomp:

view _ _ _ = view_ [] [ vcomp () (static (mountStatic_ childComponent)) ]

VCompStatic

VCompStatic is the View constructor behind vcomp. Unlike VComp it carries a StaticPtr to its component constructor, giving the mount a stable, cross-thread-resolvable identity (a StaticKey) instead of relying on a manually-supplied Key. This is what lets the MTS independently reconstruct a mirror of a component mounted on the BTS, including ones mounted after the initial frame, and is also how actions dispatched from a main-thread handler get routed back to the correct component on the BTS.

The StaticKey itself serves as the mount's identity, so there is no need for (+>) or a manual key — use vcomp / vcomp_ together with mountStatic_ (or mountStaticWithProps / mountStaticUseContext) to build a VCompStatic.