spair
A framework for Single Page Application in Rust. Inspired by Simi, Mika and Yew, some parts of source are copied from them.
This project is in its early stage, breaking changes are expected.
Examples
See in /examples
Run examples
You need
- Rust with
wasm32-unknown-unknowntarget. cargo install wasm-packcargo install basic-http-serveror use your favorite file-server
In an example folder:
wasm-pack build --dev --target web
basic-http-server // or your favorite file-server
Open your browser and visit the correct url. By default, basic-http-server serves at http://localhost:4000.
How Spair works
Spair works similar to Simi. The big difference is that Simi needs procedural macros to implement the idea, but Spair does not need any macros. That said, a procedural macro/macros can help transform HTML-like code into Spair's Rust code. Such macros were not implemented yet.
The first render of a single page application need to render everything from an empty element. But on the second or subsequence renders, most (or all) of elements are already there. Why re-render, diffing and patching? Spair iterates through the existing elements and modifies them where changes are found.
When implementing spair::Component on your application's State, the spair::Component::render method receive a context which contains a comp: spair::Comp<C> and an element: spair::Element<C>.
comp is used to construct event handlers (for element events) or callbacks. element is the root element of your component, on which you can set static_attributes and/or attributes (in that order). And finally you can add static_nodes or nodes.
When Spair iterates through an element's child nodes if the expected element was not found, it will be created, and marked as JustCreated. Every static attributes and static nodes will only be executed on a JustCreated element. Every normal-mode attributes and normal-mode nodes will always be executed.
Notes
HTML's tags and attributes are implemented as methods in Spair. Names that are conflicted with Rust's keywords are implemented using raw identifers such as r#type, r#for...
What's done?
- Minimal features of the framework
- Basic support for routing
- All tag (?)
- Some attributes (enough for
examples/totomvc) - Keyed-list (behind
features=["keyed-list]) - Basic support for
fetch - Some common events on html elements
What's next?
(But don't expect soon)
[ ] Using Spair for some apps to stabilize API
[ ] Implement all attributes
[ ] Implement #[derive(spair::Routes)]
[ ] Add support for child components
[ ] Some benchmarks