Browse Source

Merge branch 'master' into jk/windows-desktop

Jonathan Kelley 3 years ago
parent
commit
be2d6876ab

+ 7 - 7
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus"
-version = "0.1.4"
+version = "0.1.5"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"
@@ -11,13 +11,13 @@ documentation = "https://dioxuslabs.com"
 keywords = ["dom", "ui", "gui", "react", "wasm"]
 
 [dependencies]
-dioxus-core = { path = "./packages/core", version = "^0.1.4" }
-dioxus-html = { path = "./packages/html", version = "^0.1.1", optional = true }
-dioxus-core-macro = { path = "./packages/core-macro", version = "^0.1.3", optional = true }
-dioxus-hooks = { path = "./packages/hooks", version = "^0.1.4", optional = true }
+dioxus-core = { path = "./packages/core", version = "^0.1.6" }
+dioxus-html = { path = "./packages/html", version = "^0.1.3", optional = true }
+dioxus-core-macro = { path = "./packages/core-macro", version = "^0.1.5", optional = true }
+dioxus-hooks = { path = "./packages/hooks", version = "^0.1.5", optional = true }
 
-dioxus-web = { path = "./packages/web", version = "^0.0.2", optional = true }
-dioxus-desktop = { path = "./packages/desktop", version = "^0.1.1", optional = true }
+dioxus-web = { path = "./packages/web", version = "^0.0.3", optional = true }
+dioxus-desktop = { path = "./packages/desktop", version = "^0.1.3", optional = true }
 dioxus-ssr = { path = "./packages/ssr", version = "0.1.1", optional = true }
 
 # dioxus-router = { path = "./packages/router", optional = true }

+ 1 - 1
packages/core-macro/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-core-macro"
-version = "0.1.4"
+version = "0.1.5"
 authors = ["Jonathan Kelley"]
 edition = "2021"
 description = "Core macro for Dioxus Virtual DOM"

+ 3 - 3
packages/core-macro/src/rsx/element.rs

@@ -204,9 +204,9 @@ impl ToTokens for Element {
         tokens.append_all(quote! {
             __cx.element(
                 dioxus_elements::#name,
-                [ #(#listeners),* ],
-                [ #(#attr),* ],
-                [ #(#children),* ],
+                __cx.bump().alloc([ #(#listeners),* ]),
+                __cx.bump().alloc([ #(#attr),* ]),
+                __cx.bump().alloc([ #(#children),* ]),
                 #key,
             )
         });

+ 1 - 1
packages/core/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-core"
-version = "0.1.5"
+version = "0.1.6"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"

+ 23 - 45
packages/core/src/nodes.rs

@@ -75,7 +75,7 @@ pub enum VNode<'src> {
     ///     Example {}
     /// }
     /// ```
-    Fragment(VFragment<'src>),
+    Fragment(&'src VFragment<'src>),
 
     /// Component nodes represent a mounted component with props, children, and a key.
     ///
@@ -156,15 +156,12 @@ impl<'src> VNode<'src> {
 
     // Create an "owned" version of the vnode.
     pub fn decouple(&self) -> VNode<'src> {
-        match self {
-            VNode::Text(t) => VNode::Text(*t),
-            VNode::Element(e) => VNode::Element(*e),
-            VNode::Component(c) => VNode::Component(*c),
-            VNode::Placeholder(a) => VNode::Placeholder(*a),
-            VNode::Fragment(f) => VNode::Fragment(VFragment {
-                children: f.children,
-                key: f.key,
-            }),
+        match *self {
+            VNode::Text(t) => VNode::Text(t),
+            VNode::Element(e) => VNode::Element(e),
+            VNode::Component(c) => VNode::Component(c),
+            VNode::Placeholder(a) => VNode::Placeholder(a),
+            VNode::Fragment(f) => VNode::Fragment(f),
         }
     }
 }
@@ -447,19 +444,14 @@ impl<'a> NodeFactory<'a> {
         }))
     }
 
-    pub fn element<L, A, V>(
+    pub fn element(
         &self,
         el: impl DioxusElement,
-        listeners: L,
-        attributes: A,
-        children: V,
+        listeners: &'a [Listener<'a>],
+        attributes: &'a [Attribute<'a>],
+        children: &'a [VNode<'a>],
         key: Option<Arguments>,
-    ) -> VNode<'a>
-    where
-        L: 'a + AsRef<[Listener<'a>]>,
-        A: 'a + AsRef<[Attribute<'a>]>,
-        V: 'a + AsRef<[VNode<'a>]>,
-    {
+    ) -> VNode<'a> {
         self.raw_element(
             el.tag_name(),
             el.namespace(),
@@ -470,29 +462,15 @@ impl<'a> NodeFactory<'a> {
         )
     }
 
-    pub fn raw_element<L, A, V>(
+    pub fn raw_element(
         &self,
         tag_name: &'static str,
         namespace: Option<&'static str>,
-        listeners: L,
-        attributes: A,
-        children: V,
+        listeners: &'a [Listener<'a>],
+        attributes: &'a [Attribute<'a>],
+        children: &'a [VNode<'a>],
         key: Option<Arguments>,
-    ) -> VNode<'a>
-    where
-        L: 'a + AsRef<[Listener<'a>]>,
-        A: 'a + AsRef<[Attribute<'a>]>,
-        V: 'a + AsRef<[VNode<'a>]>,
-    {
-        let listeners: &'a L = self.bump.alloc(listeners);
-        let listeners = listeners.as_ref();
-
-        let attributes: &'a A = self.bump.alloc(attributes);
-        let attributes = attributes.as_ref();
-
-        let children: &'a V = self.bump.alloc(children);
-        let children = children.as_ref();
-
+    ) -> VNode<'a> {
         let key = key.map(|f| self.raw_text(f).0);
 
         VNode::Element(self.bump.alloc(VElement {
@@ -574,10 +552,10 @@ impl<'a> NodeFactory<'a> {
         if nodes.is_empty() {
             VNode::Placeholder(self.bump.alloc(VPlaceholder { id: empty_cell() }))
         } else {
-            VNode::Fragment(VFragment {
+            VNode::Fragment(self.bump.alloc(VFragment {
                 children: nodes.into_bump_slice(),
                 key: None,
-            })
+            }))
         }
     }
 
@@ -613,10 +591,10 @@ impl<'a> NodeFactory<'a> {
                 );
             }
 
-            VNode::Fragment(VFragment {
+            VNode::Fragment(self.bump.alloc(VFragment {
                 children,
                 key: None,
-            })
+            }))
         }
     }
 
@@ -639,10 +617,10 @@ impl<'a> NodeFactory<'a> {
         } else {
             let children = nodes.into_bump_slice();
 
-            Some(VNode::Fragment(VFragment {
+            Some(VNode::Fragment(self.bump.alloc(VFragment {
                 children,
                 key: None,
-            }))
+            })))
         }
     }
 }

+ 2 - 2
packages/desktop/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-desktop"
-version = "0.1.2"
+version = "0.1.3"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Dioxus VirtualDOM renderer for a remote webview instance"
@@ -12,7 +12,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.1.3", features = ["serialize"] }
+dioxus-core = { path = "../core", version = "^0.1.6", features = ["serialize"] }
 argh = "0.1.4"
 serde = "1.0.120"
 serde_json = "1.0.61"

+ 2 - 2
packages/hooks/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-hooks"
-version = "0.1.4"
+version = "0.1.5"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Dioxus VirtualDOM renderer for a remote webview instance"
@@ -12,4 +12,4 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-dioxus-core = { path = "../../packages/core", version = "0.1.5" }
+dioxus-core = { path = "../../packages/core", version = "^0.1.6" }

+ 2 - 2
packages/html/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-html"
-version = "0.1.2"
+version = "0.1.3"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "HTML Element pack for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences"
@@ -11,7 +11,7 @@ documentation = "https://docs.rs/dioxus"
 keywords = ["dom", "ui", "gui", "react", "wasm"]
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.1.4" }
+dioxus-core = { path = "../core", version = "^0.1.6" }
 serde = { version = "1", features = ["derive"], optional = true }
 serde_repr = { version = "0.1", optional = true }
 

+ 1 - 1
packages/router/Cargo.toml

@@ -11,7 +11,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.1.3", default-features = false }
+dioxus-core = { path = "../core", version = "^0.1.6", default-features = false }
 dioxus-html = { path = "../html", version = "^0.1.0", default-features = false }
 dioxus-core-macro = { path = "../core-macro", version = "^0.1.2" }
 

+ 2 - 2
packages/ssr/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-ssr"
-version = "0.1.1"
+version = "0.1.2"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Dioxus render-to-string"
@@ -13,7 +13,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.1.3", features = ["serialize"] }
+dioxus-core = { path = "../core", version = "^0.1.6", features = ["serialize"] }
 
 
 [dev-dependencies]

+ 2 - 2
packages/web/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "dioxus-web"
-version = "0.0.2"
+version = "0.0.3"
 authors = ["Jonathan Kelley"]
 edition = "2018"
 description = "Dioxus VirtualDOM renderer for the web browser using websys"
@@ -11,7 +11,7 @@ documentation = "https://dioxuslabs.com"
 keywords = ["dom", "ui", "gui", "react", "wasm"]
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.1.4" }
+dioxus-core = { path = "../core", version = "^0.1.6" }
 dioxus-html = { path = "../html", version = "^0.1.1" }
 js-sys = "0.3"
 wasm-bindgen = { version = "0.2.78", features = ["enable-interning"] }

+ 2 - 2
packages/web/src/dom.rs

@@ -13,7 +13,7 @@ use std::{any::Any, fmt::Debug, rc::Rc, sync::Arc};
 use wasm_bindgen::{closure::Closure, JsCast};
 use web_sys::{
     CssStyleDeclaration, Document, Element, Event, HtmlElement, HtmlInputElement,
-    HtmlOptionElement, HtmlTextAreaElement, Node, NodeList,
+    HtmlOptionElement, HtmlTextAreaElement, Node,
 };
 
 use crate::{nodeslab::NodeSlab, WebConfig};
@@ -49,7 +49,7 @@ impl WebsysDom {
     pub fn new(root: Element, cfg: WebConfig, sender_callback: Rc<dyn Fn(SchedulerMsg)>) -> Self {
         let document = load_document();
 
-        let mut nodes = NodeSlab::new(2000);
+        let nodes = NodeSlab::new(2000);
         let listeners = FxHashMap::default();
 
         // re-hydrate the page - only supports one virtualdom per page