wip: working on re-enabling components
This commit is contained in:
1 parent
15c31d545a
commit
fffc7ea061
4 files changed
+75
-79
No files matched your search
@@ -13,6 +13,7 @@ fn Parent(cx: Context, props: &()) -> Element {
|
|||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
Child { name: value }
|
Child { name: value }
|
||||||
|
Fragment { "asd" }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ impl EmptyBuilder {
|
|||||||
|
|
||||||
/// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern
|
/// This utility function launches the builder method so rsx! and html! macros can use the typed-builder pattern
|
||||||
/// to initialize a component's props.
|
/// to initialize a component's props.
|
||||||
pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Context<'a>, &T) -> Element) -> T::Builder {
|
pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Context<'a>, &'a T) -> Element) -> T::Builder {
|
||||||
// pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element) -> T::Builder {
|
// pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element) -> T::Builder {
|
||||||
T::builder()
|
T::builder()
|
||||||
}
|
}
|
||||||
+69
-74
@@ -531,89 +531,84 @@ impl<'a> NodeFactory<'a> {
|
|||||||
- if the props aren't static, then we convert them into a box which we pass off between renders
|
- if the props aren't static, then we convert them into a box which we pass off between renders
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// let bump = self.bump();
|
||||||
|
|
||||||
|
// // later, we'll do a hard allocation
|
||||||
|
// let raw_ptr = bump.alloc(props);
|
||||||
let bump = self.bump();
|
let bump = self.bump();
|
||||||
|
let props = bump.alloc(props);
|
||||||
// later, we'll do a hard allocation
|
let bump_props = props as *mut P as *mut ();
|
||||||
let raw_ptr = bump.alloc(props);
|
|
||||||
// let caller = Box::new(|f: &ScopeInner| -> Element {
|
|
||||||
// //
|
|
||||||
// component((f, &props))
|
|
||||||
// });
|
|
||||||
|
|
||||||
let user_fc = component as *const ();
|
let user_fc = component as *const ();
|
||||||
|
|
||||||
// let comparator: &mut dyn Fn(&VComponent) -> bool = bump.alloc_with(|| {
|
let comparator: &mut dyn Fn(&VComponent) -> bool = bump.alloc_with(|| {
|
||||||
// move |other: &VComponent| {
|
move |other: &VComponent| {
|
||||||
// if user_fc == other.user_fc {
|
if user_fc == other.user_fc {
|
||||||
// // Safety
|
// Safety
|
||||||
// // - We guarantee that FC<P> is the same by function pointer
|
// - We guarantee that FC<P> is the same by function pointer
|
||||||
// // - Because FC<P> is the same, then P must be the same (even with generics)
|
// - Because FC<P> is the same, then P must be the same (even with generics)
|
||||||
// // - Non-static P are autoderived to memoize as false
|
// - Non-static P are autoderived to memoize as false
|
||||||
// // - This comparator is only called on a corresponding set of bumpframes
|
// - This comparator is only called on a corresponding set of bumpframes
|
||||||
// let props_memoized = unsafe {
|
let props_memoized = unsafe {
|
||||||
// let real_other: &P = &*(other.raw_props as *const _ as *const P);
|
let real_other: &P = &*(other.bump_props as *const _ as *const P);
|
||||||
// props.memoize(real_other)
|
props.memoize(real_other)
|
||||||
// };
|
};
|
||||||
|
|
||||||
// // It's only okay to memoize if there are no children and the props can be memoized
|
// It's only okay to memoize if there are no children and the props can be memoized
|
||||||
// // Implementing memoize is unsafe and done automatically with the props trait
|
// Implementing memoize is unsafe and done automatically with the props trait
|
||||||
// props_memoized
|
props_memoized
|
||||||
// } else {
|
} else {
|
||||||
// false
|
false
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// let comparator = Some(unsafe { BumpBox::from_raw(comparator) });
|
|
||||||
|
let drop_props = {
|
||||||
|
// create a closure to drop the props
|
||||||
|
let mut has_dropped = false;
|
||||||
|
|
||||||
|
let drop_props: &mut dyn FnMut() = bump.alloc_with(|| {
|
||||||
|
move || unsafe {
|
||||||
|
log::debug!("dropping props!");
|
||||||
|
if !has_dropped {
|
||||||
|
let real_other = bump_props as *mut _ as *mut P;
|
||||||
|
let b = BumpBox::from_raw(real_other);
|
||||||
|
std::mem::drop(b);
|
||||||
|
|
||||||
|
has_dropped = true;
|
||||||
|
} else {
|
||||||
|
panic!("Drop props called twice - this is an internal failure of Dioxus");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let drop_props = unsafe { BumpBox::from_raw(drop_props) };
|
||||||
|
|
||||||
|
RefCell::new(Some(drop_props))
|
||||||
|
};
|
||||||
|
|
||||||
let key = key.map(|f| self.raw_text(f).0);
|
let key = key.map(|f| self.raw_text(f).0);
|
||||||
|
|
||||||
// let caller = match P::IS_STATIC {
|
let caller: &'a mut dyn Fn(&Scope) -> Element =
|
||||||
// true => {
|
bump.alloc(move |scope: &Scope| -> Element {
|
||||||
// // it just makes sense to box the props
|
log::debug!("calling component renderr {:?}", scope.our_arena_idx);
|
||||||
// let boxed_props: Box<P> = Box::new(props);
|
let props: &'_ P = unsafe { &*(bump_props as *const P) };
|
||||||
// let props_we_know_are_static = todo!();
|
let res = component(scope, props);
|
||||||
// VCompCaller::Owned(Box::new(|f| {
|
// let res = component((Context { scope }, props));
|
||||||
// //
|
unsafe { std::mem::transmute(res) }
|
||||||
|
});
|
||||||
|
|
||||||
// let p = todo!();
|
let can_memoize = P::IS_STATIC;
|
||||||
|
|
||||||
// todo!()
|
VNode::Component(bump.alloc(VComponent {
|
||||||
// }))
|
user_fc,
|
||||||
// }
|
comparator,
|
||||||
// false => VCompCaller::Borrowed({
|
bump_props,
|
||||||
// //
|
caller,
|
||||||
|
key,
|
||||||
// todo!()
|
can_memoize,
|
||||||
// // let caller = bump.alloc()
|
drop_props,
|
||||||
// }),
|
associated_scope: Cell::new(None),
|
||||||
// };
|
}))
|
||||||
|
|
||||||
todo!()
|
|
||||||
// let caller: &'a mut dyn for<'b> Fn(&'b ScopeInner) -> Element<'b> =
|
|
||||||
// bump.alloc(move |scope: &ScopeInner| -> Element {
|
|
||||||
// log::debug!("calling component renderr {:?}", scope.our_arena_idx);
|
|
||||||
// let props: &'_ P = unsafe { &*(raw_props as *const P) };
|
|
||||||
|
|
||||||
// let scp: &'a ScopeInner = unsafe { std::mem::transmute(scope) };
|
|
||||||
// let s: Scope<'a, P> = (scp, props);
|
|
||||||
|
|
||||||
// let res: Element = component(s);
|
|
||||||
// unsafe { std::mem::transmute(res) }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// let caller = unsafe { BumpBox::from_raw(caller) };
|
|
||||||
|
|
||||||
// VNode::Component(bump.alloc(VComponent {
|
|
||||||
// user_fc,
|
|
||||||
// comparator,
|
|
||||||
// raw_props,
|
|
||||||
// caller,
|
|
||||||
// is_static: P::IS_STATIC,
|
|
||||||
// key,
|
|
||||||
// can_memoize: P::IS_STATIC,
|
|
||||||
// drop_props,
|
|
||||||
// associated_scope: Cell::new(None),
|
|
||||||
// }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listener(
|
pub fn listener(
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ fn create() {
|
|||||||
"Hello, world!"
|
"Hello, world!"
|
||||||
div {
|
div {
|
||||||
div {
|
div {
|
||||||
// Fragment {
|
Fragment {
|
||||||
// "hello"
|
"hello"
|
||||||
// "world"
|
"world"
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user