wip: try to get lifetimes passed in properly
This commit is contained in:
1 parent
27d891934a
commit
f70b5b4e4a
6 files changed
+312
-184
No files matched your search
@@ -21,16 +21,27 @@ pub(crate) struct BumpFrame {
|
||||
|
||||
impl ActiveFrame {
|
||||
pub fn new() -> Self {
|
||||
let b1 = Bump::new();
|
||||
let b2 = Bump::new();
|
||||
|
||||
let frame_a = BumpFrame {
|
||||
bump: Bump::new(),
|
||||
head_node: NodeFactory::unstable_place_holder(),
|
||||
head_node: VNode::Fragment(VFragment {
|
||||
key: None,
|
||||
children: &[],
|
||||
is_static: false,
|
||||
}),
|
||||
bump: b1,
|
||||
|
||||
#[cfg(test)]
|
||||
_name: "wip",
|
||||
};
|
||||
let frame_b = BumpFrame {
|
||||
bump: Bump::new(),
|
||||
head_node: NodeFactory::unstable_place_holder(),
|
||||
head_node: VNode::Fragment(VFragment {
|
||||
key: None,
|
||||
children: &[],
|
||||
is_static: false,
|
||||
}),
|
||||
bump: b2,
|
||||
|
||||
#[cfg(test)]
|
||||
_name: "fin",
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
//!
|
||||
//! We unsafely implement `send` for the VirtualDom, but those guarantees can only be
|
||||
|
||||
use bumpalo::Bump;
|
||||
|
||||
use crate::innerlude::*;
|
||||
use std::{any::TypeId, ops::Deref, rc::Rc};
|
||||
|
||||
@@ -122,6 +124,11 @@ impl<'src> Context<'src> {
|
||||
self.scope.our_arena_idx
|
||||
}
|
||||
|
||||
pub fn bump(&self) -> &'src Bump {
|
||||
let bump = &self.scope.frames.wip_frame().bump;
|
||||
bump
|
||||
}
|
||||
|
||||
/// Take a lazy VNode structure and actually build it with the context of the VDom's efficient VNode allocator.
|
||||
///
|
||||
/// This function consumes the context and absorb the lifetime, so these VNodes *must* be returned.
|
||||
|
||||
@@ -421,6 +421,10 @@ impl<'bump> DiffMachine<'bump> {
|
||||
) => self
|
||||
.stack
|
||||
.create_node(new_node, MountType::Replace { old: old_node }),
|
||||
|
||||
(Placeholder, _) | (_, Placeholder) => {
|
||||
unreachable!("placeholder should never be diffed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,6 +1129,7 @@ impl<'bump> DiffMachine<'bump> {
|
||||
|
||||
self.remove_nodes(e.children, false);
|
||||
}
|
||||
|
||||
VNode::Fragment(f) => {
|
||||
self.remove_nodes(f.children, gen_muts);
|
||||
}
|
||||
|
||||
+11
-12
@@ -10,7 +10,6 @@ use bumpalo::{boxed::Box as BumpBox, Bump};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
fmt::{Arguments, Debug, Formatter},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
/// A composable "VirtualNode" to declare a User Interface in the Dioxus VirtualDOM.
|
||||
@@ -33,7 +32,7 @@ pub enum VNode<'src> {
|
||||
/// assert_eq!(vtext.is_static, true);
|
||||
/// }
|
||||
/// ```
|
||||
Text(VText<'src>),
|
||||
Text(&'src VText<'src>),
|
||||
|
||||
/// Element VNodes are VNodes that may contain attributes, listeners, a key, a tag, and children.
|
||||
///
|
||||
@@ -116,7 +115,7 @@ pub enum VNode<'src> {
|
||||
/// assert_eq!(root, VNode::Anchor);
|
||||
/// }
|
||||
/// ```
|
||||
Anchor(VAnchor),
|
||||
Anchor(&'src VAnchor),
|
||||
}
|
||||
|
||||
impl<'src> VNode<'src> {
|
||||
@@ -328,21 +327,21 @@ impl<'a> NodeFactory<'a> {
|
||||
self.bump
|
||||
}
|
||||
|
||||
pub fn unstable_place_holder() -> VNode<'static> {
|
||||
VNode::Text(VText {
|
||||
pub(crate) fn unstable_place_holder(&self) -> VNode {
|
||||
VNode::Text(self.bump.alloc(VText {
|
||||
text: "",
|
||||
dom_id: empty_cell(),
|
||||
is_static: true,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Directly pass in text blocks without the need to use the format_args macro.
|
||||
pub fn static_text(&self, text: &'static str) -> VNode<'a> {
|
||||
VNode::Text(VText {
|
||||
VNode::Text(self.bump.alloc(VText {
|
||||
dom_id: empty_cell(),
|
||||
text,
|
||||
is_static: true,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Parses a lazy text Arguments and returns a string and a flag indicating if the text is 'static
|
||||
@@ -365,11 +364,11 @@ impl<'a> NodeFactory<'a> {
|
||||
pub fn text(&self, args: Arguments) -> VNode<'a> {
|
||||
let (text, is_static) = self.raw_text(args);
|
||||
|
||||
VNode::Text(VText {
|
||||
VNode::Text(self.bump.alloc(VText {
|
||||
text,
|
||||
is_static,
|
||||
dom_id: empty_cell(),
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn element<L, A, V>(
|
||||
@@ -556,9 +555,9 @@ impl<'a> NodeFactory<'a> {
|
||||
}
|
||||
|
||||
if nodes.is_empty() {
|
||||
nodes.push(VNode::Anchor(VAnchor {
|
||||
nodes.push(VNode::Anchor(bump.alloc(VAnchor {
|
||||
dom_id: empty_cell(),
|
||||
}));
|
||||
})));
|
||||
}
|
||||
|
||||
let children = nodes.into_bump_slice();
|
||||
|
||||
Reference in new issue
Block a user