mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-27 04:53:12 +00:00
508c560320
This change switches back to the original `ctx<props>` syntax for commponents. This lets lifetime elision to remove the need to match exactly which lifetime (props or ctx) gets carried to the output. As such, `Props` is currently required to be static. It *is* possible to loosen this restriction, and will be done in the future, though only through adding metadata about the props through the Props derive macro. Implementing the IS_STATIC trait is unsafe, so the derive macro will do it through some heuristics. For now, this unlocks sharing vnodes from parents to children, enabling pass-thru components, fragments, portals, etc.
50 lines
2 KiB
Rust
50 lines
2 KiB
Rust
//! Example: ECS Architecture for very list selectors
|
|
//! --------------------------------------------------
|
|
//! Sometimes, you need *peak* performance. Cloning and Rc might simply be too much overhead for your app.
|
|
//! If you're building CPU intense apps like graphics editors, simulations, or advanced visualizations,
|
|
//! slicing up your state beyond atoms might be desirable.
|
|
//!
|
|
//! Instead of storing groups of entities in a collection of structs, the ECS Architecture instead stores
|
|
//! an array for each field in of a struct. This tends to improve performance for batch operations on
|
|
//! individual fields at the cost of complexity. Fortunately, this ECS model is built right into Recoil,
|
|
//! making it easier than ever to enable sharded datastructures in your app.
|
|
//!
|
|
//! Instead of defining a struct for our primary datastructure, we'll instead use a type tuple, and then later
|
|
//! index that tuple to get the value we care about. Unfortunately, we lose name information wrt to each
|
|
//! type in the type tuple. This can be solved with an associated module, the derive EcsMacro, or just
|
|
//! by good documentation.
|
|
//!
|
|
//! This approach is best suited for applications where individual entries in families are very large
|
|
//! and updates to neighbors are costly in terms of Clone or field comparisons for memoization.
|
|
|
|
use dioxus::prelude::*;
|
|
use dioxus_core as dioxus;
|
|
use recoil::*;
|
|
|
|
type TodoModel = (
|
|
bool, // checked
|
|
String, // name
|
|
String, // contents
|
|
);
|
|
|
|
const TODOS: EcsModel<u32, TodoModel> = |builder| {};
|
|
// const SELECT_TITLE: SelectorBorrowed<u32, &str> = |s, k| TODOS.field(0).select(k);
|
|
// const SELECT_SUBTITLE: SelectorBorrowed<u32, &str> = |s, k| TODOS.field(1).select(k);
|
|
|
|
static App: FC<()> = |ctx| {
|
|
use_init_recoil_root(ctx, |_| {});
|
|
|
|
// let title = use_recoil_value(ctx, &C_SELECTOR);
|
|
|
|
let title = "";
|
|
rsx! { in ctx,
|
|
div {
|
|
"{title}"
|
|
// button { onclick: {next_light}, "Next light" }
|
|
}
|
|
}
|
|
};
|
|
|
|
fn main() {
|
|
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
|
}
|