A toolkit for building fast, reliable Web applications and libraries with Rust and Wasm.
Gloo is a collection of libraries, and those libraries provide ergonomic Rust
wrappers for browser APIs.
js-sys are very difficult/inconvenient
to use directly so provides wrappers around the raw bindngs which makes it easier
to consume those APIs. This is why it is called a "toolkit", instead of "library"
In the Rust and WebAssembly working group's 2019 roadmap, we chose to deliberately cultivate our library ecosystem by building a modular toolkit:
Collaborating on a Modular Toolkit
The idea of building [high-level libraries] in a modular way that will allow others in the community to put the components together in a different way is very exciting to me. This hopefully will make the ecosystem as a whole much stronger.
In particular I’d love to see a modular effort towards implementing a virtual DOM library with JSX like syntax. There have been several efforts on this front but all have seemed relatively monolithic and “batteries included”. I hope this will change in 2019.
— Ryan Levick in Rust WebAssembly 2019
Don't create branded silos. Branding might perhaps be useful to achieve fame. But if we truly want Rust's Wasm story to succeed we should think of ways to collaborate instead of carving out territory.
— Yoshua Wuyts in Wasm 2019
In 2018, we created foundational libraries like
web-sys. In 2019, we should build modular, high-level libraries on top of them, and collect the libraries under an umbrella toolkit crate for a holistic experience. This toolkit and its libraries will make available all the batteries you want when targeting Wasm.
Gloo is this modular toolkit.
Cultivate the Rust and Wasm library ecosystem: We want to use Gloo as a forcing function for creating and sharing the building blocks of Web development. The kinds of libraries that any framework or high-level library would need to build. We want to explicitly disentangle these libraries and make them available for sharing across the whole ecosystem.
Modular Toolkit, not Framework: Gloo should be a loose collection of utility crates that can be used individually, or all together. Gloo doesn't assume that it "owns" the whole Webpage, that it controls the Wasm
startfunction, etc. This lack of assumptions enables reaching more use cases (such as surgically replacing a hot code path from JS) than monolithic frameworks can. Wherever possible, Gloo should prefer interfaces over implementations, so that different implementations with different approaches are swap-able.
Fast: Let's leverage Rust's zero-cost abstractions, and design with performance in mind, to show everyone how fast the Web can be ;)
Reliable: Every crate should be thoroughly tested. Headless browser tests. Quickcheck tests. Using the type system to make whole classes of bugs impossible.
Small: Small code size for faster page loads. No accidentally pulling in all of the panicking and formatting infrastructure. Users shouldn't have to make a trade off between using Gloo libraries and having small Wasm binaries.
Idiomatic: We want to build Rust-y APIs, that feel natural to use. The Web's APIs were not designed for the Rust language, and you can feel the impedance mismatch every now and then. Let's correct that, bridge the gap, and make libraries that are a joy to use.
This example uses
gloo::events for adding event listeners and
for creating timeouts. It creates a
<button> element and adds a "click" event
listener to it. Whenever the button is clicked, it starts a one second timeout,
which sets the button's text content to "Hello from one second ago!".
use ; use *;
Want to help us build Gloo? Check out