diff --git a/packages/core-macro/src/htm.rs b/packages/core-macro/src/htm.rs index 55c849c6b..a61106756 100644 --- a/packages/core-macro/src/htm.rs +++ b/packages/core-macro/src/htm.rs @@ -149,7 +149,7 @@ impl ToTokens for ToToksCtx<&Element> { // let ctx = self.ctx; let name = &self.inner.name; tokens.append_all(quote! { - dioxus::builder::#name(bump) + dioxus::builder::ElementBuilder::new(ctx, "#name") }); for attr in self.inner.attrs.iter() { self.recurse(attr).to_tokens(tokens); diff --git a/packages/core-macro/src/rsxt.rs b/packages/core-macro/src/rsxt.rs index 4b3c9eb16..d36ca48e8 100644 --- a/packages/core-macro/src/rsxt.rs +++ b/packages/core-macro/src/rsxt.rs @@ -146,7 +146,7 @@ impl ToTokens for ToToksCtx<&Element> { // // let ctx = self.ctx; let name = &self.inner.name; tokens.append_all(quote! { - dioxus::builder::#name(bump) + dioxus::builder::ElementBuilder::new(ctx, "#name") }); for attr in self.inner.attrs.iter() { self.recurse(attr).to_tokens(tokens); diff --git a/packages/core/examples/alternative.rs b/packages/core/examples/alternative.rs index 6cf18fb6f..637c5d4f0 100644 --- a/packages/core/examples/alternative.rs +++ b/packages/core/examples/alternative.rs @@ -1,93 +1,93 @@ -//! An alternative function syntax -//! +// //! An alternative function syntax +// //! -use bumpalo::Bump; -use dioxus_core::prelude::VNode; +// use bumpalo::Bump; +// use dioxus_core::prelude::VNode; fn main() {} -struct Context2<'a, P> { - _props: &'a P, // _p: PhantomData<&'a ()>, - rops: &'a P, // _p: PhantomData<&'a ()>, -} -impl<'a, P> Context2<'a, P> { - fn render(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree { - DTree {} - } +// struct Context2<'a, P> { +// _props: &'a P, // _p: PhantomData<&'a ()>, +// rops: &'a P, // _p: PhantomData<&'a ()>, +// } +// impl<'a, P> Context2<'a, P> { +// fn render(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree { +// DTree {} +// } - fn props(&self) -> &'a P { - todo!() - } +// fn props(&self) -> &'a P { +// todo!() +// } - pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>( - &'scope self, - _initializer: impl FnOnce() -> InternalHookState, - _runner: impl FnOnce(&'a mut InternalHookState) -> Output, - _cleanup: impl FnOnce(InternalHookState), - ) -> Output { - todo!() - } -} +// pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>( +// &'scope self, +// _initializer: impl FnOnce() -> InternalHookState, +// _runner: impl FnOnce(&'a mut InternalHookState) -> Output, +// _cleanup: impl FnOnce(InternalHookState), +// ) -> Output { +// todo!() +// } +// } -trait Properties {} +// trait Properties {} -struct DTree; -// type FC2<'a, T: 'a> = fn(Context2) -> DTree; -fn virtual_child<'a, T: 'a>(_bump: &'a Bump, _props: T, _f: FC2) -> VNode<'a> { - todo!() -} +// struct DTree; +// // type FC2<'a, T: 'a> = fn(Context2) -> DTree; +// fn virtual_child<'a, T: 'a>(_bump: &'a Bump, _props: T, _f: FC2) -> VNode<'a> { +// todo!() +// } -struct Props { - c: String, -} +// struct Props { +// c: String, +// } -fn Example(ctx: Context2) -> DTree { - let val = use_state(&ctx, || String::from("asd")); - let props = ctx.props(); +// fn Example(ctx: Context2) -> DTree { +// let val = use_state(&ctx, || String::from("asd")); +// let props = ctx.props(); - ctx.render(move |b| { - dioxus_core::nodebuilder::div(b) - .child(dioxus_core::nodebuilder::text(props.c.as_str())) - .child(virtual_child(b, Props2 { a: val }, AltChild)) - .finish() - }) -} +// ctx.render(move |b| { +// dioxus_core::nodebuilder::div(b) +// .child(dioxus_core::nodebuilder::text(props.c.as_str())) +// .child(virtual_child(b, Props2 { a: val }, AltChild)) +// .finish() +// }) +// } -// #[fc] -fn Example2(ctx: Context2<()>, name: &str, _blah: &str) -> DTree { - let val = use_state(&ctx, || String::from("asd")); +// // #[fc] +// fn Example2(ctx: Context2<()>, name: &str, _blah: &str) -> DTree { +// let val = use_state(&ctx, || String::from("asd")); - ctx.render(move |b| { - dioxus_core::nodebuilder::div(b) - .child(dioxus_core::nodebuilder::text(name)) - .child(virtual_child(b, Props2 { a: val }, AltChild)) - .finish() - }) -} +// ctx.render(move |ctx| { +// dioxus_core::builder::ElementBuilder::new(b, "div") +// .child(dioxus_core::nodebuilder::text(name)) +// .child(virtual_child(b, Props2 { a: val }, AltChild)) +// .finish() +// }) +// } -type FC2<'a, T> = fn(Context2) -> DTree; +// type FC2<'a, T> = fn(Context2) -> DTree; -// still works if you don't take any references in your props (ie, something copy or cloneable) -static CHILD: FC2 = |_ctx: Context2| { - // - todo!() -}; +// // still works if you don't take any references in your props (ie, something copy or cloneable) +// static CHILD: FC2 = |_ctx: Context2| { +// // +// todo!() +// }; -struct Props2<'a> { - a: &'a String, -} -impl Properties for Props2<'_> {} +// struct Props2<'a> { +// a: &'a String, +// } +// impl Properties for Props2<'_> {} -fn AltChild(ctx: Context2) -> DTree { - ctx.render(|_b| { - // - todo!() - }) -} +// fn AltChild(ctx: Context2) -> DTree { +// ctx.render(|_b| { +// // +// todo!() +// }) +// } -fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>( - _ctx: &'_ Context2<'a, P>, - _initial_state_fn: F, -) -> &'a T { - todo!() -} +// fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>( +// _ctx: &'_ Context2<'a, P>, +// _initial_state_fn: F, +// ) -> &'a T { +// todo!() +// } diff --git a/packages/core/examples/borrowed.rs b/packages/core/examples/borrowed.rs index e88999390..700b615c7 100644 --- a/packages/core/examples/borrowed.rs +++ b/packages/core/examples/borrowed.rs @@ -22,12 +22,12 @@ fn app(ctx: Context, props: &Props) -> DomTree { let (f, setter) = use_state(&ctx, || 0); ctx.render(move |b| { - let mut root = builder::div(b); + let mut root = builder::ElementBuilder::new(b, "div"); for child in &props.items { // notice that the child directly borrows from our vec // this makes lists very fast (simply views reusing lifetimes) root = root.child(builder::virtual_child( - b, + b.bump, ChildProps { item: child, item_handler: setter, diff --git a/packages/core/examples/contextapi.rs b/packages/core/examples/contextapi.rs index 99bbcf168..bef23122a 100644 --- a/packages/core/examples/contextapi.rs +++ b/packages/core/examples/contextapi.rs @@ -1,4 +1,3 @@ -use builder::button; use dioxus_core::prelude::*; fn main() {} @@ -15,7 +14,7 @@ static Example: FC = |ctx, props| { let value = ctx.use_context(|c: &SomeContext| c.items.last().unwrap()); ctx.render(move |bump| { - button(bump) + builder::ElementBuilder::new(bump, "button") .on("click", move |_| { println!("Value is {}", props.name); println!("Value is {}", value.as_str()); diff --git a/packages/core/examples/nested.rs b/packages/core/examples/nested.rs index 2a53282c9..4a0f1d5a5 100644 --- a/packages/core/examples/nested.rs +++ b/packages/core/examples/nested.rs @@ -13,7 +13,7 @@ static Header: FC<()> = |ctx, props| { let handler1 = move || println!("Value is {}", inner.current()); ctx.render(|bump| { - builder::div(bump) + builder::ElementBuilder::new(bump, "div") .child(VNode::Component(VComponent::new( Bottom, // diff --git a/packages/core/old/builderconstructors.rs b/packages/core/old/builderconstructors.rs new file mode 100644 index 000000000..deac5e343 --- /dev/null +++ b/packages/core/old/builderconstructors.rs @@ -0,0 +1,589 @@ +// we don't want to necessarily adhere to the spec for dioxus core +// 3rd party libs can implement their own builders if they want + +// macro_rules! builder_constructors { +// ( $( +// $(#[$attr:meta])* +// $name:ident; +// )* ) => { +// $( +// $(#[$attr])* +// #[inline] +// pub fn $name<'a, B>( +// bump: B, +// ) -> ElementBuilder< +// 'a, +// bumpalo::collections::Vec<'a, Listener<'a>>, +// bumpalo::collections::Vec<'a, Attribute<'a>>, +// bumpalo::collections::Vec<'a, VNode<'a>>, +// > +// where +// B: Into<&'a Bump> +// { +// ElementBuilder::new(bump, stringify!($name)) +// } +// )* +// }; +// ( $( +// $(#[$attr:meta])* +// $name:ident <> $namespace:tt; +// )* ) => { +// $( +// $(#[$attr])* +// #[inline] +// pub fn $name<'a>( +// bump: &'a Bump, +// ) -> ElementBuilder< +// 'a, +// bumpalo::collections::Vec<'a, Listener<'a>>, +// bumpalo::collections::Vec<'a, Attribute<'a>>, +// bumpalo::collections::Vec<'a, VNode<'a>>, +// > { +// let builder = ElementBuilder::new(bump, stringify!($name)); +// builder.namespace(Some($namespace)) +// } +// )* +// } +// } + +// // Organized in the same order as +// // https://developer.mozilla.org/en-US/docs/Web/HTML/Element +// // +// // Does not include obsolete elements. +// builder_constructors! { +// // Document metadata + +// /// Build a +// /// [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) +// /// element. +// base; +// /// Build a +// /// [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head) +// /// element. +// head; +// /// Build a +// /// [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) +// /// element. +// link; +// /// Build a +// /// [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta) +// /// element. +// meta; +// /// Build a +// /// [`