Feat: remove old macro
This commit is contained in:
1 parent
e66827ec92
commit
9d0727edab
43 files changed
+208
-2306
No files matched your search
@@ -14,7 +14,7 @@ wasm-bindgen = "0.2.71"
|
||||
# wasm-bindgen = "0.2.70"
|
||||
lazy_static = "1.4.0"
|
||||
wasm-bindgen-futures = "0.4.20"
|
||||
futures = "0.3.12"
|
||||
# futures = "0.3.12"
|
||||
wasm-logger = "0.2.0"
|
||||
log = "0.4.14"
|
||||
fxhash = "0.2.1"
|
||||
@@ -25,6 +25,9 @@ wasm-bindgen-test = "0.3.21"
|
||||
once_cell = "1.7.2"
|
||||
# html-validation = { path = "../html-validation", version = "0.1.1" }
|
||||
|
||||
async-channel = "1.6.1"
|
||||
# futures-lite = "1.11.3"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
features = [
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
use dioxus_web::{WebsysRenderer, dioxus::prelude::*};
|
||||
use dioxus_web::{dioxus::prelude::*, WebsysRenderer};
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(CustomA))
|
||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(CustomA))
|
||||
}
|
||||
|
||||
use components::CustomB;
|
||||
|
||||
fn CustomA<'a>(ctx: Context<'a>, props: &'a ()) -> DomTree {
|
||||
let (val, set_val) = use_state(&ctx, || "abcdef".to_string());
|
||||
ctx.render(rsx!{
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
class: "m-8"
|
||||
"CustomA {val}"
|
||||
button {
|
||||
"Upper"
|
||||
@@ -29,35 +31,41 @@ fn CustomA<'a>(ctx: Context<'a>, props: &'a ()) -> DomTree {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Props, PartialEq)]
|
||||
struct PropsB<'src> {
|
||||
val: &'src str
|
||||
}
|
||||
mod components {
|
||||
use super::*;
|
||||
|
||||
fn CustomB<'a>(ctx: Context<'a>, props: &'a PropsB<'a>) -> DomTree {
|
||||
let (first, last) = props.val.split_at(3);
|
||||
ctx.render(rsx!{
|
||||
div {
|
||||
"CustomB {props.val}"
|
||||
CustomC {
|
||||
val: first
|
||||
#[derive(Debug, Props, PartialEq)]
|
||||
pub struct PropsB<'src> {
|
||||
val: &'src str,
|
||||
}
|
||||
|
||||
pub fn CustomB<'a>(ctx: Context<'a>, props: &'a PropsB<'a>) -> DomTree {
|
||||
let (first, last) = props.val.split_at(3);
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
class: "m-8"
|
||||
"CustomB {props.val}"
|
||||
CustomC {
|
||||
val: first
|
||||
}
|
||||
CustomC {
|
||||
val: last
|
||||
}
|
||||
}
|
||||
CustomC {
|
||||
val: last
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Props, PartialEq)]
|
||||
struct PropsC<'src> {
|
||||
val: &'src str,
|
||||
}
|
||||
|
||||
fn CustomC<'a>(ctx: Context<'a>, props: &'a PropsC<'a>) -> DomTree {
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
class: "m-8"
|
||||
"CustomC {props.val}"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Props, PartialEq)]
|
||||
struct PropsC<'src> {
|
||||
val: &'src str
|
||||
}
|
||||
|
||||
fn CustomC<'a>(ctx: Context<'a>, props: &'a PropsC<'a>) -> DomTree {
|
||||
ctx.render(rsx!{
|
||||
div {
|
||||
"CustomC {props.val}"
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ fn main() {
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async {
|
||||
WebsysRenderer::new_with_props(Example, ExampleProps { initial_name: "..?", blarg: Vec::new()})
|
||||
let props = ExampleProps { initial_name: "..?", blarg: vec!["abc".to_string(), "abc".to_string()]};
|
||||
WebsysRenderer::new_with_props(Example, props)
|
||||
.run()
|
||||
.await
|
||||
.unwrap()
|
||||
@@ -38,17 +39,19 @@ static Example: FC<ExampleProps> = |ctx, props| {
|
||||
"Hello, {name}"
|
||||
}
|
||||
|
||||
CustomButton { name: sub, set_name: Box::new(move || set_name("jack")) }
|
||||
// CustomButton { name: "Jack!", set_name: Box::new(move || set_name("jack")) }
|
||||
// CustomButton { name: "Jill!", set_name: Box::new(move || set_name("jill")) }
|
||||
// CustomButton { name: "Reset!", set_name: Box::new(move || set_name(props.initial_name)) }
|
||||
// CustomButton { name: sub, set_name: Box::new(move || set_name("jack")) }
|
||||
CustomButton { name: "Jack!", set_name: Box::new(move || set_name("jack")) }
|
||||
CustomButton { name: "Jill!", set_name: Box::new(move || set_name("jill")) }
|
||||
CustomButton { name: "Bill!", set_name: Box::new(move || set_name("Bill")) }
|
||||
CustomButton { name: "Reset!", set_name: Box::new(move || set_name(props.initial_name)) }
|
||||
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
#[derive(Props)]
|
||||
struct ButtonProps<'src> {
|
||||
name: &'src String,
|
||||
name: &'src str,
|
||||
// name: &'src str,
|
||||
set_name: Box< dyn Fn() + 'src>
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Borrow, convert::TryInto, fmt::Debug, sync::Arc};
|
||||
use std::{borrow::Borrow, convert::TryInto, default, fmt::Debug, sync::Arc};
|
||||
|
||||
use dioxus_core::{
|
||||
events::{EventTrigger, VirtualEvent},
|
||||
@@ -27,6 +27,8 @@ impl std::fmt::Debug for RootCallback {
|
||||
pub(crate) struct PatchMachine {
|
||||
pub(crate) stack: Stack,
|
||||
|
||||
pub(crate) known_roots: FxHashMap<u32, Node>,
|
||||
|
||||
pub(crate) root: Element,
|
||||
|
||||
pub(crate) temporaries: FxHashMap<u32, Node>,
|
||||
@@ -165,6 +167,7 @@ impl PatchMachine {
|
||||
let events = EventDelegater::new(root.clone(), event_callback);
|
||||
|
||||
Self {
|
||||
known_roots: Default::default(),
|
||||
root,
|
||||
events,
|
||||
stack: Stack::with_capacity(20),
|
||||
@@ -476,8 +479,15 @@ impl PatchMachine {
|
||||
el.set_class_name(class_name);
|
||||
}
|
||||
}
|
||||
Edit::TraverseToKnown { node } => {}
|
||||
Edit::MakeKnown { node } => {}
|
||||
Edit::MakeKnown { node } => {
|
||||
let domnode = self.stack.top();
|
||||
self.known_roots.insert(node, domnode.clone());
|
||||
}
|
||||
Edit::TraverseToKnown { node } => {
|
||||
let domnode = self.known_roots.get(&node).expect("Failed to pop know root");
|
||||
self.stack.push(domnode.clone());
|
||||
|
||||
}
|
||||
Edit::RemoveKnown => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use web_sys::{window, Document, Element, Event, Node};
|
||||
use dioxus::virtual_dom::VirtualDom;
|
||||
pub use dioxus_core as dioxus;
|
||||
use dioxus_core::{events::EventTrigger, prelude::FC};
|
||||
use futures::{channel::mpsc, SinkExt, StreamExt};
|
||||
// use futures::{channel::mpsc, SinkExt, StreamExt};
|
||||
|
||||
pub mod interpreter;
|
||||
|
||||
@@ -58,7 +58,7 @@ impl WebsysRenderer {
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> dioxus_core::error::Result<()> {
|
||||
let (sender, mut receiver) = mpsc::unbounded::<EventTrigger>();
|
||||
let (sender, mut receiver) = async_channel::unbounded::<EventTrigger>();
|
||||
|
||||
let body_element = prepare_websys_dom();
|
||||
|
||||
@@ -85,7 +85,7 @@ impl WebsysRenderer {
|
||||
// Event loop waits for the receiver to finish up
|
||||
// TODO! Connect the sender to the virtual dom's suspense system
|
||||
// Suspense is basically an external event that can force renders to specific nodes
|
||||
while let Some(event) = receiver.next().await {
|
||||
while let Ok(event) = receiver.recv().await {
|
||||
// log::debug!("patch stack size before {:#?}", patch_machine.stack);
|
||||
// patch_machine.reset();
|
||||
// patch_machine.stack.push(root_node.clone());
|
||||
|
||||
Reference in new issue
Block a user