You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/components_guide_web/controllers/wasm_html/custom_elements.html.md
+12-2
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,11 @@ The element lets you use a WebAssembly instance that renders HTML. It loads your
10
10
- a `to_html()` function that returns the memory offset to your built HTML. This will be called on each render.
11
11
- an optional `free_all()` function that is called at the start of each render, used to free memory if you need.
12
12
13
-
If your rendered HTML includes a `<button>` with a `data-action` attribute, then a click listener will be added. The value of this attribute if set to the name of an exported function, will be called every time the button is clicked. The HTML will also be re-rendered for you.
13
+
Your WebAssembly instance can also hold internal state in its globals variables and in memory. This allows it to be stateful, rendering different HTML depending on the state.
14
14
15
-
For example a `<button data-action="increment">Increment counter</button>` will call the `increment()` function you export, plus call your `to_html()` function, allowing you to re-render say a counter from `<output>1</output>` to `<output>2</output>`. Note: you must render the button each time: this allow you to change which buttons are available depending on your internal state.
15
+
If your rendered HTML includes a `<button>` with a `data-action` attribute, then a click listener will be added. The value of this attribute if set to the name of an exported function, will be called every time the button is clicked. The HTML will also be re-rendered for you by calling `to_html()` again.
16
+
17
+
For example a `<button data-action="increment">Increment counter</button>` will call the `increment()` function you export, plus call your `to_html()` function, allowing you to re-render say a counter from `<output>1</output>` to `<output>2</output>`. Note: you must render your buttons every time: this allow you to change which buttons are available depending on your internal state.
16
18
17
19
### Usage
18
20
@@ -66,9 +68,13 @@ async function initWasmHTML(el, wasmModulePromise) {
These are some starter event listeners. Any DOM event is possible, it‘s up to you to decide which properties from the event you want and the convention for passing their data to your WebAssembly instance. Usually a specially named exported function makes sense.
0 commit comments