,
+ element_name: Ident,
) -> Result<()> {
let mut name = Ident::parse_any(stream)?;
let name_str = name.to_string();
@@ -159,6 +148,7 @@ fn parse_element_body(
name,
value: ty,
namespace: None,
+ element_name: element_name.clone(),
});
return Ok(());
}
@@ -186,6 +176,7 @@ fn parse_element_body(
name,
value: ty,
namespace: Some("style".to_string()),
+ element_name: element_name.clone(),
});
}
@@ -227,13 +218,15 @@ fn parse_element_body(
name,
value: ty,
namespace: None,
+ element_name,
});
Ok(())
}
impl ToTokens for ElementAttr {
fn to_tokens(&self, tokens: &mut TokenStream2) {
- let name = self.name.to_string();
+ let el_name = &self.element_name;
+ let name_str = self.name.to_string();
let nameident = &self.name;
let namespace = match &self.namespace {
@@ -243,12 +236,22 @@ impl ToTokens for ElementAttr {
match &self.value {
AttrType::BumpText(value) => tokens.append_all(quote! {
- __cx.attr(#name, format_args_f!(#value), #namespace)
+ dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
}),
-
+ // __cx.attr(#name, format_args_f!(#value), #namespace, false)
+ //
+ // AttrType::BumpText(value) => tokens.append_all(quote! {
+ // __cx.attr(#name, format_args_f!(#value), #namespace, false)
+ // }),
AttrType::FieldTokens(exp) => tokens.append_all(quote! {
- __cx.attr(#name, #exp, #namespace)
+ dioxus_elements::#el_name.#nameident(__cx, #exp)
}),
+ // __cx.attr(#name_str, #exp, #namespace, false)
+
+ // AttrType::FieldTokens(exp) => tokens.append_all(quote! {
+ // dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
+ // __cx.attr(#name_str, #exp, #namespace, false)
+ // }),
// todo: move event handlers on to the elements or onto the nodefactory
AttrType::Event(event) => tokens.append_all(quote! {
diff --git a/packages/core-macro/src/rsx/mod.rs b/packages/core-macro/src/rsx/mod.rs
index 2c56acad9..6ad337238 100644
--- a/packages/core-macro/src/rsx/mod.rs
+++ b/packages/core-macro/src/rsx/mod.rs
@@ -97,12 +97,16 @@ impl ToTokens for RsxRender {
// The `in cx` pattern allows directly rendering
Some(ident) => out_tokens.append_all(quote! {
#ident.render(dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
+ use dioxus_elements::GlobalAttributes;
+
#inner
}))
}),
// Otherwise we just build the LazyNode wrapper
None => out_tokens.append_all(quote! {
dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
+ use dioxus_elements::GlobalAttributes;
+
#inner
})
}),
diff --git a/packages/core/.vscode/settings.json b/packages/core/.vscode/settings.json
index 2b58ae251..34a811347 100644
--- a/packages/core/.vscode/settings.json
+++ b/packages/core/.vscode/settings.json
@@ -1,3 +1,3 @@
{
- "rust-analyzer.inlayHints.enable": false
+ "rust-analyzer.inlayHints.enable": true
}
diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml
index eaa9ba214..c662c6732 100644
--- a/packages/core/Cargo.toml
+++ b/packages/core/Cargo.toml
@@ -41,5 +41,5 @@ smallvec = "1.6.1"
[features]
-default = []
+default = ["serialize"]
serialize = ["slotmap/serde", "serde"]
diff --git a/packages/core/examples/alternative.rs b/packages/core/examples/alternative.rs
index 3b74d0472..b12a8f69c 100644
--- a/packages/core/examples/alternative.rs
+++ b/packages/core/examples/alternative.rs
@@ -1,20 +1,20 @@
fn main() {}
-use dioxus::*;
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
+// use dioxus::*;
+// use dioxus_core as dioxus;
+// use dioxus_core::prelude::*;
-static Example: FC<()> = |cx| {
- let list = (0..10).map(|f| LazyNodes::new(move |f| todo!()));
+// static Example: FC<()> = |cx| {
+// let list = (0..10).map(|f| LazyNodes::new(move |f| todo!()));
- cx.render(LazyNodes::new(move |cx| {
- let bump = cx.bump();
- cx.raw_element("div")
- .children([
- cx.text(format_args!("hello")),
- cx.text(format_args!("hello")),
- cx.fragment_from_iter(list),
- ])
- .finish()
- }))
-};
+// cx.render(LazyNodes::new(move |cx| {
+// let bump = cx.bump();
+// cx.raw_element("div")
+// .children([
+// cx.text(format_args!("hello")),
+// cx.text(format_args!("hello")),
+// cx.fragment_from_iter(list),
+// ])
+// .finish()
+// }))
+// };
diff --git a/packages/core/examples/async.rs b/packages/core/examples/async.rs
index a6a0749a7..9b4509dc9 100644
--- a/packages/core/examples/async.rs
+++ b/packages/core/examples/async.rs
@@ -1,13 +1,13 @@
-use std::pin::Pin;
+
use dioxus_core::prelude::*;
-use std::future::Future;
+
fn main() {}
const App: FC<()> = |cx| {
// create a new future
- let mut fut = cx.use_hook(
+ let _fut = cx.use_hook(
|| {
//
async { loop {} }
@@ -22,3 +22,15 @@ const App: FC<()> = |cx| {
todo!()
};
+
+const Task: FC<()> = |cx| {
+ //
+
+ let _s = cx.use_task(|| async { "hello world".to_string() });
+
+ todo!()
+};
+
+fn use_mut(_cx: Context
, _f: impl FnOnce() -> T) -> &mut T {
+ todo!()
+}
diff --git a/packages/core/examples/borrowed.rs b/packages/core/examples/borrowed.rs
index f160e37c5..d0b20241c 100644
--- a/packages/core/examples/borrowed.rs
+++ b/packages/core/examples/borrowed.rs
@@ -7,7 +7,7 @@
fn main() {}
use dioxus_core::prelude::*;
-use dioxus_core::*;
+
use std::rc::Rc;
struct AppProps {
@@ -61,7 +61,7 @@ fn ChildItem<'a>(cx: Context<'a, ChildProps>) -> VNode {
}
impl PartialEq for ChildProps {
- fn eq(&self, other: &Self) -> bool {
+ fn eq(&self, _other: &Self) -> bool {
false
}
}
diff --git a/packages/core/examples/fragment.rs b/packages/core/examples/fragment.rs
index 479a2607d..3d4b97b8b 100644
--- a/packages/core/examples/fragment.rs
+++ b/packages/core/examples/fragment.rs
@@ -1,4 +1,4 @@
-use dioxus_core::prelude::*;
+
fn main() {
diff --git a/packages/core/examples/html.rs b/packages/core/examples/html.rs
index 67c56e856..96ce94986 100644
--- a/packages/core/examples/html.rs
+++ b/packages/core/examples/html.rs
@@ -68,7 +68,7 @@ impl BasicElement for div {
todo!()
}
- fn new(factory: Factory) -> Self {
+ fn new(_factory: Factory) -> Self {
todo!()
}
}
diff --git a/packages/core/src/arena.rs b/packages/core/src/arena.rs
index c8e519413..82415d45f 100644
--- a/packages/core/src/arena.rs
+++ b/packages/core/src/arena.rs
@@ -59,8 +59,8 @@ impl SharedArena {
pub fn with_scope<'b, O: 'static>(
&'b self,
- id: ScopeIdx,
- f: impl FnOnce(&'b mut Scope) -> O,
+ _id: ScopeIdx,
+ _f: impl FnOnce(&'b mut Scope) -> O,
) -> Result {
todo!()
}
@@ -69,8 +69,8 @@ impl SharedArena {
// this is useful for merging lifetimes
pub fn with_scope_vnode<'b>(
&self,
- id: ScopeIdx,
- f: impl FnOnce(&mut Scope) -> &VNode<'b>,
+ _id: ScopeIdx,
+ _f: impl FnOnce(&mut Scope) -> &VNode<'b>,
) -> Result<&VNode<'b>> {
todo!()
}
diff --git a/packages/core/src/bumpframe.rs b/packages/core/src/bumpframe.rs
index ade95d7db..ab28508af 100644
--- a/packages/core/src/bumpframe.rs
+++ b/packages/core/src/bumpframe.rs
@@ -1,20 +1,7 @@
-use crate::hooklist::HookList;
-use crate::{arena::SharedArena, innerlude::*};
-use appendlist::AppendList;
+use crate::innerlude::*;
use bumpalo::Bump;
-use slotmap::DefaultKey;
-use slotmap::SlotMap;
-use std::marker::PhantomData;
-use std::{
- any::{Any, TypeId},
- cell::{Cell, RefCell},
- collections::{HashMap, HashSet, VecDeque},
- fmt::Debug,
- future::Future,
- ops::Deref,
- pin::Pin,
- rc::{Rc, Weak},
-};
+
+use std::cell::RefCell;
pub struct ActiveFrame {
// We use a "generation" for users of contents in the bump frames to ensure their data isn't broken
pub generation: RefCell,
@@ -33,11 +20,11 @@ impl ActiveFrame {
Self::from_frames(
BumpFrame {
bump: Bump::new(),
- head_node: VNode::static_text(""),
+ head_node: NodeFactory::static_text(""),
},
BumpFrame {
bump: Bump::new(),
- head_node: VNode::static_text(""),
+ head_node: NodeFactory::static_text(""),
},
)
}
diff --git a/packages/core/src/component.rs b/packages/core/src/component.rs
index f5bc7ea79..c23e3d631 100644
--- a/packages/core/src/component.rs
+++ b/packages/core/src/component.rs
@@ -5,7 +5,7 @@
//! if the type suppports PartialEq. The Properties trait is used by the rsx! and html! macros to generate the type-safe builder
//! that ensures compile-time required and optional fields on cx.
-use crate::innerlude::FC;
+use crate::innerlude::{Context, LazyNodes, VNode, FC};
pub trait Properties: Sized {
type Builder;
@@ -50,7 +50,6 @@ pub fn fc_to_builder(_: FC) -> T::Builder {
///
/// Fragments are incredibly useful when necessary, but *do* add cost in the diffing phase.
/// Try to avoid nesting fragments if you can. Infinitely nested Fragments *will* cause diffing to crash.
-use crate::prelude::*;
#[allow(non_upper_case_globals, non_snake_case)]
pub fn Fragment<'a>(cx: Context<'a, ()>) -> VNode<'a> {
cx.render(LazyNodes::new(move |f| f.fragment_from_iter(cx.children())))
diff --git a/packages/core/src/context.rs b/packages/core/src/context.rs
index 6396d5e02..fdc35809f 100644
--- a/packages/core/src/context.rs
+++ b/packages/core/src/context.rs
@@ -1,15 +1,12 @@
-use crate::hooklist::HookList;
-use crate::{arena::SharedArena, innerlude::*};
-use appendlist::AppendList;
-use bumpalo::Bump;
-use slotmap::DefaultKey;
-use slotmap::SlotMap;
+use crate::innerlude::*;
+
+use futures_util::FutureExt;
+
use std::marker::PhantomData;
+
use std::{
- any::{Any, TypeId},
- cell::{Cell, RefCell},
- collections::{HashMap, HashSet, VecDeque},
- fmt::Debug,
+ any::TypeId,
+ cell::RefCell,
future::Future,
ops::Deref,
pin::Pin,
@@ -39,9 +36,8 @@ use std::{
pub struct Context<'src, T> {
pub props: &'src T,
pub scope: &'src Scope,
- pub tasks: &'src RefCell>,
}
-pub type PinnedTask = Pin>>;
+// pub type PinnedTask = Pin>>;
impl<'src, T> Copy for Context<'src, T> {}
impl<'src, T> Clone for Context<'src, T> {
@@ -49,7 +45,6 @@ impl<'src, T> Clone for Context<'src, T> {
Self {
props: self.props,
scope: self.scope,
- tasks: self.tasks,
}
}
}
@@ -134,7 +129,7 @@ impl<'src, P> Context<'src, P> {
self,
initializer: Init,
runner: Run,
- cleanup: Cleanup,
+ _cleanup: Cleanup,
) -> Output
where
State: 'static,
@@ -263,31 +258,13 @@ Any function prefixed with "use" should not be called conditionally.
)
}
- pub fn suspend VNode<'src> + 'src>(
- &'src self,
- fut: &'src mut Pin + 'static>>,
- callback: Fut,
- ) -> VNode<'src> {
- use futures_util::FutureExt;
- match fut.now_or_never() {
- Some(out) => {
- let suspended_cx = SuspendedContext {};
- let nodes = callback(suspended_cx, out);
- return nodes;
- }
- None => {
- // we need to register this task
- VNode::Suspended {
- real: Cell::new(RealDomNode::empty()),
- }
- }
- }
- }
-
/// `submit_task` will submit the future to be polled.
///
/// This is useful when you have some async task that needs to be progressed.
///
+ /// This method takes ownership over the task you've provided, and must return (). This means any work that needs to
+ /// happen must occur within the future or scheduled for after the future completes (through schedule_update )
+ ///
/// ## Explanation
/// Dioxus will step its internal event loop if the future returns if the future completes while waiting.
///
@@ -298,11 +275,102 @@ Any function prefixed with "use" should not be called conditionally.
///
///
///
- pub fn submit_task(&self, task: &'src mut PinnedTask) -> TaskHandle {
- self.tasks.borrow_mut().push(task);
+ pub fn submit_task(&self, task: FiberTask) -> TaskHandle {
+ let r = (self.scope.task_submitter)(task);
+ // self.scope.submit_task(task);
+ // let r = task.then(|f| async {
+ // //
+ // });
+ // self.use_hook(|| Box::new(r), |_| {}, |_| {});
+ // *task = task.then(|f| async {
+ // //
+ // t
+ // // ()
+ // });
+ // let new_fut = task.then(|f| async {
+ // //
+ // ()
+ // });
+ // self.tasks.borrow_mut().push(new_fut);
TaskHandle { _p: PhantomData {} }
}
+
+ /// Awaits the given task, forcing the component to re-render when the value is ready.
+ ///
+ ///
+ pub fn use_task(&self, task_initializer: Init) -> &mut Option
+ where
+ Out: 'static,
+ Fut: Future