$ show ranile/gloo
Gloo is a modular Rust toolkit for WebAssembly that provides idiomatic, ergonomic wrappers around browser APIs. Instead of using raw `web-sys` or `js-sys` bindings, Gloo offers a collection of reusable crates covering timers, events, file I/O, storage, dialogs, console logging, networking (HTTP, WebSocket, EventSource), history management, rendering, and web workers. The architecture is a multi-crate workspace with an umbrella crate (`gloo`) that re-exports all sub-crates, allowing users to depend on the whole toolkit or individual crates. Key entry points are the public APIs of each crate, e.g., `EventListener`, `Timeout`, `Request`, `Blob`, `WorkerBridge`. Primary data flows are callbacks or futures/streams from JavaScript to Rust, with serialization handled by serde and postcard for workers. External dependencies include `wasm-bindgen`, `web-sys`, `js-sys`, `serde`, `futures`, and others. This is not a data research repository; it is a library/framework for building WebAssembly applications.
The LLM identified 3 files worth highlighting for reuse:
Provides an `EventListener` type that wraps `web_sys::EventTarget::add_event_listener` in an RAII fashion. It handles the lifecycle of closures (including `Closure::wrap`/`forget`), supports capture/bubble phases, passive listeners, and one-shot listeners via `FnOnce`. The implementation carefully manages unwind safety across wasm `catch_unwind` boundaries. This component is self-contained, reusable in any WASM project that needs DOM event listening, and demonstrates safe, idiomatic Rust patterns for bridging JavaScript callbacks.
Implements `Timeout` and `Interval` types with a `forget` pattern to manage `setTimeout`/`setInterval` handles. The drop implementation clears the timer, preventing callback leaks. It uses raw `wasm_bindgen` externs to avoid depending on `web_sys::Window` (works in workers), and handles the `FnOnce` vs `FnMut` distinction correctly. The `Cancel` method returns the closure, allowing reuse. This is a clean, minimal, reusable component for scheduling tasks in WASM.
Defines `JsValueSerdeExt`, an extension trait on `JsValue` for converting between Rust `serde`-serializable types and JavaScript values using `serde_json` and `js_sys::JSON`. It provides `from_serde` and `into_serde` methods. The trait is sealed to prevent external implementation, ensuring invariants. This component is a small, focused utility widely applicable in any WASM project needing serde-based serialization, and it cleanly lifts serde out of `wasm-bindgen` core.