Development
Run and verify it in the browser
None of the code in model.rs, interface.rs, or motion.rs needs to change for the browser—only the host entry point swaps SdlSurface for WebCanvasSurface.
Compare the Web and desktop entry points
Click the desktop.rs tab in the top bar to compare web.rs and desktop.rs: both prepare their surface and storage backend, then call the same install(&mut app, chapter, reduced, storage):
⋯web.rs:54
+54 let surface = WebCanvasSurface::new(canvas);
+55 let mut app = App::with_factory(surface, WebCanvasRendererFactory::new());
+56 app.set_theme(if dark { "dark" } else { "light" })
+57 .map_err(|error| JsError::new(&format!("{error:?}")))?;
+58 let storage = if persist && chapter.has_storage() {
+59 LocalStorageStorage::with_prefix(concat!("mirui-first-app-", env!("CARGO_PKG_VERSION")))
+60 .ok()
+61 .map(Storage::into_handle)
+62 } else {
+63 None
+64 };
+65 install(&mut app, chapter, reduced, storage);
+66 app.prepare_text_layout()
+67 .map_err(|error| JsError::new(&format!("{error:?}")))?;
+68 Ok(Self { app })
⋯desktop.rs:6
6fn main() {
7 let chapter = std::env::args()
8 .nth(1)
9 .and_then(|arg| arg.parse().ok())
10 .and_then(Chapter::new)
11 .unwrap_or(Chapter::FINAL);
12 let storage = if chapter.has_storage() {
13 Some(
14 FileStorage::open("task-list.mirui")
15 .expect("open task storage")
16 .into_handle(),
17 )
18 } else {
19 None
20 };
21 let mut app = App::new(SdlSurface::new("Task list", 420, 440));
22 install(&mut app, chapter, false, storage);
23 app.run();
24}
Loading preview…
What changed in this step
- One
install, multiple surfaces: Models, stylesheets, layout, and animations live ininstall. The Web host binds a<canvas>withWebCanvasSurfaceand drivesapp.tick()fromrequestAnimationFrame. - Headless integration tests & Wasm bundle: Run the two commands below.
cargo testmounts all seven chapters and every concept demo onApp::headless, exercising taps and persistence round-trips;playgroundbuilds the WebAssembly bundle running on this page.
Run on your machine
sh
cargo test -p mirui-first-app
bun run --cwd docs playground