wip: staticify?
This commit is contained in:
1 parent
78d093a945
commit
5ad81885e4
21 files changed
+433
-346
No files matched your search
@@ -13,26 +13,27 @@ fn main() {
|
||||
}
|
||||
|
||||
static App: FC<()> = |ctx, _| {
|
||||
log::info!("Ran component");
|
||||
use dioxus::builder::*;
|
||||
todo!()
|
||||
// ctx.render(|b| {
|
||||
// div(b)
|
||||
// .child(text("hello"))
|
||||
// .listeners([on(b, "click", |_| {
|
||||
// //
|
||||
// log::info!("button1 clicked!");
|
||||
// })])
|
||||
// .finish()
|
||||
// })
|
||||
// ctx.render(html! {
|
||||
// <div onclick={move |_| log::info!("button1 clicked!")}>
|
||||
// "Hello"
|
||||
// // <div class="flex items-center justify-center flex-col">
|
||||
// // <div class="font-bold text-xl"> "Count is ..." </div>
|
||||
// // <button onclick={move |_| log::info!("button1 clicked!")}> "increment" </button>
|
||||
// // <button onclick={move |_| log::info!("button2 clicked!")}> "decrement" </button>
|
||||
// // </div>
|
||||
// </div>
|
||||
// })
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
h1 {"hello"}
|
||||
C1 {}
|
||||
C2 {}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
static C1: FC<()> = |ctx, props| {
|
||||
ctx.render(rsx! {
|
||||
button {
|
||||
"numba 1"
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
static C2: FC<()> = |ctx, props| {
|
||||
ctx.render(rsx! {
|
||||
button {
|
||||
"numba 2"
|
||||
}
|
||||
})
|
||||
};
|
||||
@@ -6,6 +6,7 @@ fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
log::info!("hello world");
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example));
|
||||
}
|
||||
|
||||
@@ -18,6 +19,8 @@ static Example: FC<()> = |ctx, _props| {
|
||||
set_event(Some(evt));
|
||||
};
|
||||
|
||||
log::info!("hello world");
|
||||
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -35,21 +38,35 @@ static Example: FC<()> = |ctx, _props| {
|
||||
id: "json"
|
||||
"{event}"
|
||||
}
|
||||
Example2 { name: "{event}" }
|
||||
// Example2 { name: "{event}".to_string() }
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
struct Props {
|
||||
#[derive(Debug, PartialEq, Props)]
|
||||
struct ExampleProps {
|
||||
name: String
|
||||
}
|
||||
|
||||
static Example2: FC<Props> = |ctx, props| {
|
||||
static Example2: FC<ExampleProps> = |ctx, props| {
|
||||
ctx.render(rsx!{
|
||||
div {
|
||||
h1 {"hello {props.name}"}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
impl Properties for ExampleProps {
|
||||
type Builder = ExamplePropsBuilder<((),)>;
|
||||
type StaticOutput = ExampleProps;
|
||||
fn builder() -> Self::Builder {
|
||||
ExampleProps::builder()
|
||||
}
|
||||
|
||||
|
||||
unsafe fn into_static(self) -> Self::StaticOutput {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
use bumpalo::Bump;
|
||||
use dioxus::{events::EventTrigger, prelude::*};
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_web::WebsysRenderer;
|
||||
|
||||
// creates a proxy address that gets transpiled at compile time
|
||||
// all asset ids are shuttled through the renderer
|
||||
// static IMG: ImgAsset = dioxus_asset!("");
|
||||
|
||||
fn main() {
|
||||
// wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
// console_error_panic_hook::set_once();
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
|
||||
console_error_panic_hook::set_once();
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example))
|
||||
}
|
||||
|
||||
static Example: FC<()> = |ctx, props| {
|
||||
static Example: FC<()> = |ctx, _props| {
|
||||
let (name, set_name) = use_state(&ctx, || "...?");
|
||||
|
||||
|
||||
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
class: "py-12 px-4 text-center w-full max-w-2xl mx-auto"
|
||||
@@ -47,9 +41,3 @@ static Example: FC<()> = |ctx, props| {
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// onclick: {move |_| set_name("jill")}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! --------------
|
||||
//! This crate implements a renderer of the Dioxus Virtual DOM for the web browser using Websys.
|
||||
|
||||
use dioxus::prelude::Properties;
|
||||
use fxhash::FxHashMap;
|
||||
use web_sys::{window, Document, Element, Event, Node};
|
||||
|
||||
@@ -48,7 +49,7 @@ impl WebsysRenderer {
|
||||
/// Automatically progresses the creation of the VNode tree to completion.
|
||||
///
|
||||
/// A VDom is automatically created. If you want more granular control of the VDom, use `from_vdom`
|
||||
pub fn new_with_props<T: 'static>(root: FC<T>, root_props: T) -> Self {
|
||||
pub fn new_with_props<T: Properties + 'static>(root: FC<T>, root_props: T) -> Self {
|
||||
Self::from_vdom(VirtualDom::new_with_props(root, root_props))
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ impl WebsysRenderer {
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> dioxus_core::error::Result<()> {
|
||||
let (mut sender, mut receiver) = mpsc::unbounded::<EventTrigger>();
|
||||
let (sender, mut receiver) = mpsc::unbounded::<EventTrigger>();
|
||||
|
||||
let body_element = prepare_websys_dom();
|
||||
|
||||
@@ -75,8 +76,10 @@ impl WebsysRenderer {
|
||||
|
||||
// todo: initialize the event registry properly on the root
|
||||
|
||||
self.internal_dom.rebuild()?.iter().for_each(|edit| {
|
||||
// log::debug!("patching with {:?}", edit);
|
||||
let edits = self.internal_dom.rebuild()?;
|
||||
log::debug!("Received edits: {:#?}", edits);
|
||||
edits.iter().for_each(|edit| {
|
||||
log::debug!("patching with {:?}", edit);
|
||||
patch_machine.handle_edit(edit);
|
||||
});
|
||||
// log::debug!("patch stack size {:?}", patch_machine.stack);
|
||||
@@ -92,7 +95,7 @@ impl WebsysRenderer {
|
||||
.progress_with_event(event)?
|
||||
.iter()
|
||||
.for_each(|edit| {
|
||||
// log::debug!("edit stream {:?}", edit);
|
||||
log::debug!("edit stream {:?}", edit);
|
||||
patch_machine.handle_edit(edit);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user