When a HTTP request is made to load this page, we dynamically compile the WebAssembly for the above widget on-the-fly.
At WebAssembly compile-time (but Elixir runtime) we:
- Load CSV of USA States using
Req
from https://raw.githubusercontent.com/jasonong/List-of-US-States/master/states.csv - Parse CSV using
NimbleCSV
. - Initialize each state name in WebAssembly memory.
At WebAssembly runtime we:
- Loop over each state name.
- Render HTML using
SilverOrb.StringBuilder
, with a list item for each state name.
At HTTP response time we:
- Render initial HTML using
GoldenOrb.html
Phoenix Component that:- Instantiates
WebAssembly
instance on server. - Calls exported
text_html
on the WebAssembly instance, and read HTML from its memory. - Renders HTML as child.
- Instantiates
In the browser we:
- Download
.wasm
from server. - Instantiate
WebAssembly
instance in browser. - Call exported
text_html
on the WebAssembly instance, and read HTML from its memory. - Use morphdom (the same library LiveView uses) to efficiently update the DOM.
- Listen to DOM events using event delegation, calling matching function export on the WebAssembly instance.
- For each event received, repeat steps 3–5. Tada, we have an interactive widget!