Feat: WIP on deserialize
This commit is contained in:
1 parent
8439994859
commit
f22ff83190
15 files changed
+140
-21
No files matched your search
@@ -44,12 +44,15 @@ pub fn build(config: &Config, _build_config: &BuildConfig) -> Result<()> {
|
||||
let mut cmd = Command::new("cargo");
|
||||
cmd.current_dir(&crate_dir)
|
||||
.arg("build")
|
||||
.arg("--release")
|
||||
.arg("--target")
|
||||
.arg("wasm32-unknown-unknown")
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped());
|
||||
|
||||
if config.release {
|
||||
cmd.arg("--release");
|
||||
}
|
||||
|
||||
match executable {
|
||||
ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
||||
ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
||||
@@ -67,11 +70,13 @@ pub fn build(config: &Config, _build_config: &BuildConfig) -> Result<()> {
|
||||
|
||||
let input_path = match executable {
|
||||
ExecutableType::Binary(name) | ExecutableType::Lib(name) => target_dir
|
||||
.join("wasm32-unknown-unknown/release")
|
||||
// .join("wasm32-unknown-unknown/release")
|
||||
.join("wasm32-unknown-unknown/debug")
|
||||
.join(format!("{}.wasm", name)),
|
||||
|
||||
ExecutableType::Example(name) => target_dir
|
||||
.join("wasm32-unknown-unknown/release/examples")
|
||||
// .join("wasm32-unknown-unknown/release/examples")
|
||||
.join("wasm32-unknown-unknown/debug/examples")
|
||||
.join(format!("{}.wasm", name)),
|
||||
};
|
||||
|
||||
@@ -81,8 +86,8 @@ pub fn build(config: &Config, _build_config: &BuildConfig) -> Result<()> {
|
||||
.debug(true)
|
||||
.demangle(true)
|
||||
.keep_debug(true)
|
||||
.remove_name_section(true)
|
||||
.remove_producers_section(true)
|
||||
.remove_name_section(false)
|
||||
.remove_producers_section(false)
|
||||
.out_name("module")
|
||||
.generate(&bindgen_outdir)?;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Config {
|
||||
pub static_dir: PathBuf,
|
||||
pub manifest: cargo_toml::Manifest<cargo_toml::Value>,
|
||||
pub executable: ExecutableType,
|
||||
pub release: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -50,6 +51,8 @@ impl Config {
|
||||
.expect("No lib found from cargo metadata");
|
||||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
let release = false;
|
||||
|
||||
Ok(Self {
|
||||
out_dir,
|
||||
crate_dir,
|
||||
@@ -58,6 +61,7 @@ impl Config {
|
||||
static_dir,
|
||||
manifest,
|
||||
executable,
|
||||
release,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ pub fn set_up_logging() {
|
||||
// field which defaults to the module path but can be overwritten with the `target`
|
||||
// parameter:
|
||||
// `info!(target="special_target", "This log message is about special_target");`
|
||||
.level_for("dioxus-cli", log::LevelFilter::Info)
|
||||
.level_for("dioxus", log::LevelFilter::Info)
|
||||
// .level_for("pretty_colored", log::LevelFilter::Trace)
|
||||
// output to stdout
|
||||
.chain(std::io::stdout())
|
||||
|
||||
@@ -31,4 +31,5 @@ id-arena = "2.2.1"
|
||||
thiserror = "1.0.23"
|
||||
fxhash = "0.2.1"
|
||||
longest-increasing-subsequence = "0.1.0"
|
||||
serde = "1.0.123"
|
||||
# hashbrown = { version = "0.9.1", features = ["bumpalo"] }
|
||||
@@ -141,7 +141,7 @@ mod velement {
|
||||
|
||||
/// An attribute on a DOM node, such as `id="my-thing"` or
|
||||
/// `href="https://example.com"`.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Attribute<'a> {
|
||||
pub name: &'static str,
|
||||
pub value: &'a str,
|
||||
@@ -177,7 +177,13 @@ mod velement {
|
||||
pub struct Listener<'bump> {
|
||||
/// The type of event to listen for.
|
||||
pub(crate) event: &'static str,
|
||||
/// The callback to invoke when the event happens.
|
||||
|
||||
// ref to the real listener
|
||||
// pub(crate) id: u32,
|
||||
|
||||
// pub(crate) _i: &'bump str,
|
||||
// #[serde(skip_serializing, skip_deserializing, default="")]
|
||||
// /// The callback to invoke when the event happens.
|
||||
pub(crate) callback: &'bump (dyn Fn(())),
|
||||
}
|
||||
|
||||
@@ -186,7 +192,7 @@ mod velement {
|
||||
/// Keys must be unique among siblings.
|
||||
///
|
||||
/// If any sibling is keyed, then they all must be keyed.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NodeKey(pub(crate) u32);
|
||||
|
||||
impl Default for NodeKey {
|
||||
@@ -225,7 +231,7 @@ mod velement {
|
||||
}
|
||||
|
||||
mod vtext {
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct VText<'bump> {
|
||||
pub text: &'bump str,
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ use crate::innerlude::{VNode, VText};
|
||||
///
|
||||
/// The patching process is tested in a real browser in crates/virtual-dom-rs/tests/diff_patch.rs
|
||||
|
||||
// #[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub enum Patch<'a> {
|
||||
/// Append a vector of child nodes to a parent node id.
|
||||
AppendChildren(NodeIdx, Vec<&'a VNode<'a>>),
|
||||
|
||||
@@ -37,3 +37,9 @@ features = [
|
||||
"InputEvent",
|
||||
"DocumentType",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
@@ -8,7 +8,7 @@ use dioxus_web::*;
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||
log::debug!("Hello world, from the app");
|
||||
// log::debug!("Hello world, from the app");
|
||||
WebsysRenderer::simple_render(html! {
|
||||
|
||||
// Body
|
||||
@@ -18,28 +18,27 @@ fn main() {
|
||||
// Title
|
||||
<div class="font-bold text-xl">
|
||||
// {format!("Fibonacci Calculator: n = {}",n)}
|
||||
"Fibonacci Calculator: n = {}"
|
||||
"Jon's awesome site!!11"
|
||||
</div>
|
||||
|
||||
// Subtext / description
|
||||
<div class="text-sm text-gray-500">
|
||||
// {format!("Calculated in {} nanoseconds",duration)}
|
||||
// {format!("Calculated in {} nanoseconds",duration)}
|
||||
"Calculated in {} nanoseconds"
|
||||
"He worked so hard on it :)"
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row items-center justify-center mt-6">
|
||||
// Main number
|
||||
<div class="font-medium text-6xl">
|
||||
// {format!("{}",fib_n)}
|
||||
"1337"
|
||||
</div>
|
||||
</div>
|
||||
|
||||
// Try another
|
||||
<div class="flex flex-row justify-between mt-6">
|
||||
// <a href=format!("http://localhost:8080/fib/{}", other_fib_to_try) class="underline">
|
||||
"Click to try another number"
|
||||
// {"Click to try another number"}
|
||||
"Legit made my own React"
|
||||
// </a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -115,14 +115,14 @@ impl WebsysRenderer {
|
||||
let mut machine = DiffMachine::new();
|
||||
|
||||
let patches = machine.diff(&old, &new);
|
||||
log::info!("There are {:?} patches", patches.len());
|
||||
// log::info!("There are {:?} patches", patches.len());
|
||||
|
||||
let root2 = root_node.clone();
|
||||
patch(root_node, &patches).expect("Failed to simple render");
|
||||
let document = web_sys::window().unwrap().document().unwrap();
|
||||
|
||||
document.body().unwrap().append_child(&root2);
|
||||
log::info!("Succesfully patched the dom");
|
||||
// log::info!("Succesfully patched the dom");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ pub fn create_element_node(node: &dioxus_core::nodes::VElement) -> CreatedNode<E
|
||||
let mut previous_node_was_text = false;
|
||||
|
||||
node.children.iter().for_each(|child| {
|
||||
log::info!("Patching child");
|
||||
// log::info!("Patching child");
|
||||
match child {
|
||||
VNode::Text(text_node) => {
|
||||
let current_node = element.as_ref() as &web_sys::Node;
|
||||
@@ -534,5 +534,4 @@ pub fn create_text_node(node: &VText) -> Text {
|
||||
// /// For any listeners in the tree, attach the sender closure.
|
||||
// /// When a event is triggered, we convert it into the synthetic event type and dump it back in the Virtual Dom's queu
|
||||
// fn attach_listeners(sender: &UnboundedSender<EventTrigger>, dom: &VirtualDom) {}
|
||||
|
||||
// fn render_diffs() {}
|
||||
@@ -9,3 +9,6 @@ edition = "2018"
|
||||
[dependencies]
|
||||
web-view = "0.7.2"
|
||||
dioxus-core = { path = "../core" }
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
@@ -0,0 +1,5 @@
|
||||
// todo
|
||||
// build the .wasm bundle directly from this build script
|
||||
// the bundle should never change (and not be linked to user code)]
|
||||
|
||||
fn main() {}
|
||||
Whitespace-only changes.
@@ -0,0 +1,20 @@
|
||||
//! An example where the dioxus vdom is running in a native thread, interacting with webview
|
||||
|
||||
fn main() {
|
||||
let html_content = "<div>Hello world!</div>";
|
||||
|
||||
web_view::builder()
|
||||
.title("My Project")
|
||||
.content(web_view::Content::Html(html_content))
|
||||
.size(320, 480)
|
||||
.resizable(true)
|
||||
.debug(true)
|
||||
.user_data(())
|
||||
.invoke_handler(|view, arg| {
|
||||
//
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user