AtlatestRepositorysigil-web-client
sigil-web-client / treeREADME.md
1
# sigil-web-client3
Client-side WASM UI framework for [Sigil](https://codeberg.org/sigil/sigil). A react-like rendering layer for browser applications compiled to WebAssembly: it renders Sigil SXML into the browser DOM and keeps application code independent of the underlying WASM DOM bridge.5
`(sigil web client)` is the browser-side counterpart to the server-side [sigil-web](https://codeberg.org/sigil/sigil-web) framework. The two are orthogonal: this library imports only `sigil-wasm-dom` and shares no code with the server-side modules.7
## Usage9
```scheme10
(import (sigil web client))12
;; Look up a DOM root by selector13
(define root (web-client-root "#app"))15
;; Mount a view: SXML, or a nullary procedure returning SXML16
(web-client-mount root (lambda () `(div "Hello, world!")))18
;; Update the mounted view in place19
(web-client-update root (lambda () `(div "Updated!")))21
;; Clear a root22
(web-client-clear root)23
```25
### Memoized subtrees27
Use `web-client-memo` when a rendered subtree is immutable for a known28
revision:30
```scheme31
(web-client-memo32
turn-id turn-revision33
(lambda ()34
`(section ,@(render-completed-turn turn))))35
```37
When a later `web-client-update` produces the same key and revision,38
reconciliation retains that element's complete DOM subtree without evaluating39
the producer or walking its attributes and descendants. A changed revision40
evaluates the producer and resumes normal reconciliation. The key and revision41
are renderer metadata and are not written to the DOM.43
Memoized content must be immutable for the lifetime of its revision, including44
event handlers and attributes on the boundary element. Use this for stable,45
expensive regions while leaving actively changing siblings unmemoized.47
### Exports49
- `web-client-root` — look up a DOM root node by selector50
- `web-client-root?` — validate a root node handle51
- `web-client-render` — render a view (an SXML value, or a nullary procedure returning one)52
- `web-client-mount` — mount a view into a root53
- `web-client-update` — update a mounted view in place; returns `#f` without54
mutating when retained children no longer match the DOM (call55
`web-client-clear` to recover from out-of-band changes)56
- `web-client-clear` — clear a root57
- `web-client-reset!` — reset retained client state59
## Building61
This is a browser/WASM library. Build it into a web application with the `web` config:63
```sh64
sigil deps install65
sigil build --config web66
```68
## License70
BSD-3-Clause