From f22ff8319078d283e675ff8dc735da5bf8efe0df Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Mon, 15 Feb 2021 14:14:28 -0500 Subject: [PATCH] Feat: WIP on deserialize --- README.md | 2 +- notes/ROADMAP.md | 70 +++++++++++++++++++++++++++++++ packages/cli/src/builder.rs | 15 ++++--- packages/cli/src/config.rs | 4 ++ packages/cli/src/logging.rs | 2 +- packages/core/Cargo.toml | 1 + packages/core/src/nodes.rs | 14 +++++-- packages/core/src/patch.rs | 1 + packages/web/Cargo.toml | 6 +++ packages/web/examples/basic.rs | 11 +++-- packages/web/src/lib.rs | 7 ++-- packages/webview/Cargo.toml | 3 ++ packages/webview/build.rs | 5 +++ packages/webview/examples/demo.js | 0 packages/webview/examples/demo.rs | 20 +++++++++ 15 files changed, 140 insertions(+), 21 deletions(-) create mode 100644 notes/ROADMAP.md create mode 100644 packages/webview/build.rs create mode 100644 packages/webview/examples/demo.js create mode 100644 packages/webview/examples/demo.rs diff --git a/README.md b/README.md index ed30a099f..67c6fa365 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ static Example: FC<()> = |ctx| {
-

"Hello, {val1}"

+

"Hello, {value}"

}) diff --git a/notes/ROADMAP.md b/notes/ROADMAP.md new file mode 100644 index 000000000..7e54d653d --- /dev/null +++ b/notes/ROADMAP.md @@ -0,0 +1,70 @@ +# Road map +This release map gives a sense of the release cadence and features per update going forward into the future. PRs are required to be squashed before merging. For each point release, we save a branch on master (0.1, 0.2, 0.3, master). Eventually, we'll remove these in favor of higher point releases when dioxus is stabilized. Any live PRs will be merged into the dev branch. + +Until 0.3, Dioxus will be in stealth mode. The goal is to launch with a bountiful feature set and a cohesive API before OSS tears it apart :). Once LiveView is ready, then Dioxus will launch completely with a beta service for LiveHost. + +## v0.1: Bare Necessities +> Enable ergonomic and performant webapps +--- +Dioxus Core +- Lifecycles for components +- Internal event system +- Diffing +- Patching + +Html macro +- special formatting +- closure handlers +- child handlers +- iterator handlers + +Dioxus web +- a + +Dioxus CLI +- Develop +- Bundle +- Test + +Server-side-rendering +- Write nodes to string +- Integration with tide, Actix, warp + +Dioxus WebView (desktop) +- One-file setup for desktop apps +- Integration with the web browser for rapid development + +## v0.2: Bread and butter +> Complex apps? CHECK +--- +State management +- Dioxus-Reducer as the blessed redux alternative + - Includes thunks and reducers (async dispatches) +- Dioxus-Dataflow as the blessed recoil alternative + - The hip, new approach for granular state + +Dioxus CLI +- Visual tool? +- Asset bundling service + +Dioxus DevTools integration with the web +- Basic support for pure liveview/webview + + +## v0.3: Superpowers +> Enable LiveView for fullstack development +--- +Dioxus LiveView + - Custom server built on Actix (or something fast) + - Ergonomic builders + - Concurrent system built into dioxus core + +Dioxus iOS + - Initial support via webview + - Look into native support based on how Flutter/SwiftUI works + +Dioxus Android + + +## v0.4: Community +> Foster the incoming community diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 27432d41c..0da93f5e8 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -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)?; diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs index 1a5d09b68..314fd57bc 100644 --- a/packages/cli/src/config.rs +++ b/packages/cli/src/config.rs @@ -14,6 +14,7 @@ pub struct Config { pub static_dir: PathBuf, pub manifest: cargo_toml::Manifest, 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, }) } diff --git a/packages/cli/src/logging.rs b/packages/cli/src/logging.rs index 4df6afa8d..2f6b5da5f 100644 --- a/packages/cli/src/logging.rs +++ b/packages/cli/src/logging.rs @@ -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()) diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 41574040a..55b45d412 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -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"] } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index 606a3f937..c721ff93a 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -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, } diff --git a/packages/core/src/patch.rs b/packages/core/src/patch.rs index 32ffdc005..e91e4435d 100644 --- a/packages/core/src/patch.rs +++ b/packages/core/src/patch.rs @@ -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>>), diff --git a/packages/web/Cargo.toml b/packages/web/Cargo.toml index aedf8c5f0..829874c17 100644 --- a/packages/web/Cargo.toml +++ b/packages/web/Cargo.toml @@ -37,3 +37,9 @@ features = [ "InputEvent", "DocumentType", ] + +[profile.release] +debug = true + +[lib] +crate-type = ["cdylib", "rlib"] diff --git a/packages/web/examples/basic.rs b/packages/web/examples/basic.rs index cf8b2dc48..7cb92c868 100644 --- a/packages/web/examples/basic.rs +++ b/packages/web/examples/basic.rs @@ -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
// {format!("Fibonacci Calculator: n = {}",n)} - "Fibonacci Calculator: n = {}" + "Jon's awesome site!!11"
// Subtext / description
// {format!("Calculated in {} nanoseconds",duration)} // {format!("Calculated in {} nanoseconds",duration)} - "Calculated in {} nanoseconds" + "He worked so hard on it :)"
// Main number
- // {format!("{}",fib_n)} + "1337"
// Try another diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index b7a559b2e..fcc0a6fda 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -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 { 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, dom: &VirtualDom) {} - // fn render_diffs() {} diff --git a/packages/webview/Cargo.toml b/packages/webview/Cargo.toml index 389221caf..738a812e0 100644 --- a/packages/webview/Cargo.toml +++ b/packages/webview/Cargo.toml @@ -9,3 +9,6 @@ edition = "2018" [dependencies] web-view = "0.7.2" dioxus-core = { path = "../core" } + + +[build-dependencies] diff --git a/packages/webview/build.rs b/packages/webview/build.rs new file mode 100644 index 000000000..ad97526af --- /dev/null +++ b/packages/webview/build.rs @@ -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() {} diff --git a/packages/webview/examples/demo.js b/packages/webview/examples/demo.js new file mode 100644 index 000000000..e69de29bb diff --git a/packages/webview/examples/demo.rs b/packages/webview/examples/demo.rs new file mode 100644 index 000000000..3838b32bb --- /dev/null +++ b/packages/webview/examples/demo.rs @@ -0,0 +1,20 @@ +//! An example where the dioxus vdom is running in a native thread, interacting with webview + +fn main() { + let html_content = "
Hello world!
"; + + 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(); +}