Expand description
§Xilem Web
This is a prototype implementation of the Xilem architecture (through Xilem Core) using DOM elements as Xilem elements (unfortunately the two concepts have the same name).
§Quickstart
The easiest way to start, is to use Trunk within some of the examples (see the web_examples/
directory).
Run trunk serve
, then navigate the browser to the link provided (usually http://localhost:8080).
§Example
A minimal example to run an application with xilem_web:
use xilem_web::{
document_body,
elements::html::{button, div, p},
interfaces::{Element as _, HtmlDivElement},
App,
};
fn app_logic(clicks: &mut u32) -> impl HtmlDivElement<u32> + use<> {
div((
button(format!("clicked {clicks} times")).on_click(|clicks: &mut u32, _event| *clicks += 1),
(*clicks >= 5).then_some(p("Huzzah, clicked at least 5 times")),
))
}
pub fn main() {
let clicks = 0;
App::new(document_body(), clicks, app_logic).run();
}
§Minimum supported Rust Version (MSRV)
This version of Xilem Web has been verified to compile with Rust 1.86 and later.
Future versions of Xilem Web might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
Click here if compiling fails.
As time has passed, some of Xilem Web’s dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don’t want to upgrade your Rust toolchain, then you could downgrade the dependency.
# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1
§Community
Discussion of Xilem Web development happens in the Linebender Zulip, specifically the #xilem channel. All public content can be read without logging in.
Contributions are welcome by pull request. The Rust code of conduct applies.
§License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
Re-exports§
pub use xilem_core as core;
Modules§
- concurrent
- Async views, allowing concurrent operations, like fetching data from a server
- diff
- Basic utility functions for diffing when rebuilding the views with
View::rebuild
- elements
- Basic builder functions to create DOM elements, such as
html::div
- events
- interfaces
- Opinionated extension traits roughly resembling their equivalently named DOM interfaces.
- modifiers
- This module contains DOM element modifiers, e.g. to add attributes/classes/styles.
- props
- This module contains the state (called props in this crate) of the virtual DOM.
- svg
- Contains opinionated views such as
kurbo
shapes which can be used in an svg context
Macros§
- overwrite_
bool_ modifier - A macro to create a boolean overwrite modifier.
- overwrite_
bool_ modifier_ view - A macro to create a boolean overwrite modifier view for a modifier that’s in the parent module with the same name.
Structs§
- After
Build - Invokes the
callback
after the innerelement
DomView
was created. Seeafter_build
for more details. - After
Rebuild - Invokes the
callback
after the innerelement
DomView<State>
Seeafter_rebuild
for more details. - App
- The type responsible for running your app.
- Before
Teardown - Invokes the
callback
before the innerelement
DomView
(and its underlying DOM node) is destroyed. Seebefore_teardown
for more details. - Message
Thunk - A thunk to send messages to the views, it’s being used for example in event callbacks
- Pod
- A container, which holds the actual DOM node, and associated props, such as attributes or classes.
- PodFlags
- General flags describing the current state of the element (in hydration, was created, needs update (in general for optimization))
- PodMut
- The mutable representation of
Pod
. - Pointer
- A view that allows stateful handling of
PointerEvent
s withPointerMsg
- Pointer
Details - Details of a pointer event.
- Templated
- This view creates an internally cached deep-clone of the underlying DOM node. When the inner view is created again, this will be done more efficiently.
- ViewCtx
- The
View
Context
which is used for allDomView
s
Enums§
- Attribute
Value - Representation of an attribute value.
- Pointer
Msg - A message representing a pointer event.
Constants§
Traits§
- Action
- Implement this trait for types you want to use as actions.
- AnyNode
- A trait used for type erasure of
DomNode
s It is e.g. used inAnyPod
- DomFragment
- An ordered sequence of views, or sometimes also called fragment, it’s used for
0..N
DomView
s. SeeViewSequence
for more technical details. - DomNode
- A trait to represent DOM nodes, which can optionally have associated
props
that are applied while building/rebuilding the views - DomView
- The central
View
derived trait to represent DOM nodes inxilem_web
, it’s the base for allView
s inxilem_web
- From
With Context - Into
Attribute Value - Types implementing this trait can be used as value in e.g.
Element::attr
- Message
- Types which can be contained in a
DynMessage
. - Optional
Action - Trait that allows callbacks to be polymorphic on return type
(
Action
,Option<Action>
or()
). An implementation detail.
Functions§
- after_
build - Invokes the
callback
after the innerelement
DomView
was created. The callback has a reference to the raw DOM node as its only parameter. - after_
rebuild - Invokes the
callback
after the innerelement
DomView<State>
was rebuild, which usually happens after anything has changed in theState
. - before_
teardown - Invokes the
callback
before the innerelement
DomView
(and its underlying DOM node) is destroyed. - document
- Helper to get the HTML document
- document_
body - Helper to get the HTML document body element
- get_
element_ by_ id - Helper to get a DOM element by id
- input_
event_ target_ value - Helper to get the value from an HTML input element from a given event.
- templated
- This view creates an internally cached deep-clone of the underlying DOM node.
Type Aliases§
- AnyDom
View - A view which can have any
DomView
type, seeAnyView
for more details. - AnyPod
- Type-erased
Pod
, it’s used for example as intermediate representation for children of a DOM node - DynMessage
- A dynamically typed message for the
View
trait.