WIP implement hot reloading context for html

This commit is contained in:
= committed 2022-12-12 21:46:49 -06:00
1 parent c961bf0779
commit 6d2e510200
3 files changed
+146 -14

No files matched your search

+1
View File
@@ -12,6 +12,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
[dependencies] [dependencies]
dioxus-core = { path = "../core", version = "^0.2.1" } dioxus-core = { path = "../core", version = "^0.2.1" }
dioxus-rsx = { path = "../rsx" }
serde = { version = "1", features = ["derive"], optional = true } serde = { version = "1", features = ["derive"], optional = true }
serde_repr = { version = "0.1", optional = true } serde_repr = { version = "0.1", optional = true }
wasm-bindgen = { version = "0.2.79", optional = true } wasm-bindgen = { version = "0.2.79", optional = true }
+143 -13
View File
@@ -1,6 +1,6 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
use crate::{GlobalAttributes, SvgAttributes}; use crate::{GlobalAttributes, SvgAttributes};
use dioxus_rsx::HotReloadingContext;
pub type AttributeDiscription = (&'static str, Option<&'static str>, bool); pub type AttributeDiscription = (&'static str, Option<&'static str>, bool);
@@ -41,6 +41,29 @@ macro_rules! impl_attribute {
}; };
} }
macro_rules! impl_attribute_match {
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (DEFAULT),
) => {
stringify!($fil) => Some((stringify!($fil), None))
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident ($name:literal),
) => {
stringify!($fil) => Some(($name, None))
};
(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident (in $ns:ident),
) => {
stringify!($fil) => Some((stringify!(fil), Some(stringify!(ns))))
};
}
macro_rules! impl_element { macro_rules! impl_element {
( (
$(#[$attr:meta])* $(#[$attr:meta])*
@@ -55,7 +78,6 @@ macro_rules! impl_element {
$(#[$attr])* $(#[$attr])*
pub struct $name; pub struct $name;
impl $name { impl $name {
pub const TAG_NAME: &'static str = stringify!($name); pub const TAG_NAME: &'static str = stringify!($name);
pub const NAME_SPACE: Option<&'static str> = None; pub const NAME_SPACE: Option<&'static str> = None;
@@ -100,6 +122,78 @@ macro_rules! impl_element {
} }
} }
macro_rules! impl_element_match {
(
$(#[$attr:meta])*
$name:ident None {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if element == stringify!($name) {
return Some((stringify!($name), None));
}
};
(
$(#[$attr:meta])*
$name:ident $namespace:ident {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
if element == stringify!($name) {
return Some((stringify!($name), Some(stringify!($namespace))));
}
};
}
macro_rules! impl_element_match_attributes {
(
$(#[$attr:meta])*
$name:ident None {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
stringify!($name) => match attr{
$(
impl_attribute_match!(
$(#[$attr_method])*
$fil: $vil ($extra),
),
)*
_ => None,
}
};
(
$(#[$attr:meta])*
$name:ident $namespace:tt {
$(
$(#[$attr_method:meta])*
$fil:ident: $vil:ident $extra:tt,
)*
}
) => {
stringify!($name) => match attr{
$(
impl_attribute_match!(
$(#[$attr_method])*
$fil: $vil in $namespace $extra
),
)*
_ => None,
}
}
}
macro_rules! builder_constructors { macro_rules! builder_constructors {
( (
$( $(
@@ -111,18 +205,54 @@ macro_rules! builder_constructors {
)* )*
}; };
)* )*
) => { ) => {
$( pub struct Html;
impl_element!(
$(#[$attr])* impl HotReloadingContext for Html {
$name $namespace { fn map_attribute(element: &str, attr: &str) -> Option<(&'static str, Option<&'static str>)> {
$( match element {
$(#[$attr_method])* // $(
$fil: $vil $extra, // impl_element_match_attributes!(
)* // $(#[$attr])*
// $name $namespace {
// $(
// $(#[$attr_method])*
// $fil: $vil $extra,
// )*
// }
// )
// )*
_ => None
} }
); }
)*
fn map_element(element: &str) -> Option<(&'static str, Option<&'static str>)> {
$(
impl_element_match!(
$(#[$attr])*
$name $namespace {
$(
$(#[$attr_method])*
$fil: $vil $extra,
)*
}
);
)*
unreachable!()
}
}
// $(
// impl_element!(
// $(#[$attr])*
// $name $namespace {
// $(
// $(#[$attr_method])*
// $fil: $vil $extra,
// )*
// }
// );
// )*
}; };
} }
+2 -1
View File
@@ -25,7 +25,8 @@ use std::{collections::HashMap, hash::Hash};
pub use component::*; pub use component::*;
use dioxus_core::{Template, TemplateAttribute, TemplateNode}; use dioxus_core::{Template, TemplateAttribute, TemplateNode};
pub use element::*; pub use element::*;
use hot_reloading_context::{Empty, HotReloadingContext}; use hot_reloading_context::Empty;
pub use hot_reloading_context::HotReloadingContext;
pub use ifmt::*; pub use ifmt::*;
use internment::Intern; use internment::Intern;
pub use node::*; pub use node::*;