Feat: WIP on deserialize

This commit is contained in:
Jonathan Kelley 2021-02-15 14:14:28 -05:00
parent 8439994859
commit f22ff83190
15 changed files with 140 additions and 21 deletions

View file

@ -18,7 +18,7 @@ static Example: FC<()> = |ctx| {
<button onclick={move |_| set_value("world!")}> "?" </button>
<button onclick={move |_| set_value("Dioxus 🎉")}> "?" </button>
<div>
<h1> "Hello, {val1}" </h1>
<h1> "Hello, {value}" </h1>
</div>
</div>
})

70
notes/ROADMAP.md Normal file
View file

@ -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

View file

@ -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)?;

View file

@ -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,
})
}

View file

@ -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())

View file

@ -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"] }

View file

@ -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,
}

View file

@ -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>>),

View file

@ -37,3 +37,9 @@ features = [
"InputEvent",
"DocumentType",
]
[profile.release]
debug = true
[lib]
crate-type = ["cdylib", "rlib"]

View file

@ -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>

View file

@ -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() {}

View file

@ -9,3 +9,6 @@ edition = "2018"
[dependencies]
web-view = "0.7.2"
dioxus-core = { path = "../core" }
[build-dependencies]

View file

@ -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() {}

View file

View file

@ -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();
}