wip: docs
This commit is contained in:
1 parent
52c7154897
commit
8814977eee
14 files changed
+335
-384
No files matched your search
@@ -109,7 +109,6 @@ pub struct DiffState<'bump> {
|
||||
scopes: &'bump ScopeArena,
|
||||
pub mutations: Mutations<'bump>,
|
||||
pub(crate) stack: DiffStack<'bump>,
|
||||
pub seen_scopes: FxHashSet<ScopeId>,
|
||||
pub force_diff: bool,
|
||||
}
|
||||
|
||||
@@ -119,7 +118,6 @@ impl<'bump> DiffState<'bump> {
|
||||
scopes,
|
||||
mutations: Mutations::new(),
|
||||
stack: DiffStack::new(),
|
||||
seen_scopes: Default::default(),
|
||||
force_diff: false,
|
||||
}
|
||||
}
|
||||
@@ -492,7 +490,7 @@ impl<'bump> DiffState<'bump> {
|
||||
}
|
||||
|
||||
// Finally, insert this scope as a seen node.
|
||||
self.seen_scopes.insert(new_idx);
|
||||
self.mutations.dirty_scopes.insert(new_idx);
|
||||
}
|
||||
|
||||
fn create_linked_node(&mut self, link: &'bump VPortal) {
|
||||
|
||||
@@ -35,6 +35,14 @@ enum StackNodeStorage<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> LazyNodes<'a, 'b> {
|
||||
|
||||
pub fn new_some<F>(_val: F) -> Option<Self>
|
||||
where
|
||||
F: FnOnce(NodeFactory<'a>) -> VNode<'a> + 'b,
|
||||
{
|
||||
Some(Self::new(_val))
|
||||
}
|
||||
|
||||
pub fn new<F>(_val: F) -> Self
|
||||
where
|
||||
F: FnOnce(NodeFactory<'a>) -> VNode<'a> + 'b,
|
||||
@@ -221,7 +229,7 @@ fn it_works() {
|
||||
|
||||
let factory = NodeFactory { bump: &bump };
|
||||
|
||||
let caller = NodeFactory::annotate_lazy(|f| {
|
||||
let caller = LazyNodes::new_some(|f| {
|
||||
//
|
||||
f.text(format_args!("hello world!"))
|
||||
})
|
||||
@@ -254,7 +262,7 @@ fn it_drops() {
|
||||
.map(|i| {
|
||||
let val = val.clone();
|
||||
|
||||
NodeFactory::annotate_lazy(move |f| {
|
||||
LazyNodes::new_some(move |f| {
|
||||
log::debug!("hell closure");
|
||||
let inner = DropInner { id: i };
|
||||
f.text(format_args!("hello world {:?}, {:?}", inner.id, val))
|
||||
@@ -262,7 +270,7 @@ fn it_drops() {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
NodeFactory::annotate_lazy(|f| {
|
||||
LazyNodes::new_some(|f| {
|
||||
log::debug!("main closure");
|
||||
f.fragment_from_iter(it)
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ use std::{any::Any, fmt::Debug};
|
||||
/// Mutations are the only link between the RealDOM and the VirtualDOM.
|
||||
pub struct Mutations<'a> {
|
||||
pub edits: Vec<DomEdit<'a>>,
|
||||
pub dirty_scopes: FxHashSet<ScopeId>,
|
||||
pub refs: Vec<NodeRefMutation<'a>>,
|
||||
pub effects: Vec<&'a dyn FnMut()>,
|
||||
}
|
||||
@@ -103,6 +104,7 @@ pub enum DomEdit<'bump> {
|
||||
},
|
||||
}
|
||||
|
||||
use fxhash::FxHashSet;
|
||||
use DomEdit::*;
|
||||
|
||||
impl<'a> Mutations<'a> {
|
||||
@@ -110,6 +112,7 @@ impl<'a> Mutations<'a> {
|
||||
Self {
|
||||
edits: Vec::new(),
|
||||
refs: Vec::new(),
|
||||
dirty_scopes: Default::default(),
|
||||
effects: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,12 +732,6 @@ impl<'a> NodeFactory<'a> {
|
||||
node: unsafe { std::mem::transmute(ptr) },
|
||||
})
|
||||
}
|
||||
|
||||
pub fn annotate_lazy<'z, 'b>(
|
||||
f: impl FnOnce(NodeFactory<'z>) -> VNode<'z> + 'b,
|
||||
) -> Option<LazyNodes<'z, 'b>> {
|
||||
Some(LazyNodes::new(f))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NodeFactory<'_> {
|
||||
|
||||
@@ -44,6 +44,7 @@ pub type Context<'a> = &'a Scope;
|
||||
pub struct Scope {
|
||||
pub(crate) parent_scope: Option<*mut Scope>,
|
||||
|
||||
// parent element I think?
|
||||
pub(crate) container: ElementId,
|
||||
|
||||
pub(crate) our_arena_idx: ScopeId,
|
||||
@@ -79,8 +80,8 @@ pub struct SelfReferentialItems<'a> {
|
||||
|
||||
/// A component's unique identifier.
|
||||
///
|
||||
/// `ScopeId` is a `usize` that is unique across the entire VirtualDOM - but not unique across time. If a component is
|
||||
/// unmounted, then the `ScopeId` will be reused for a new component.
|
||||
/// `ScopeId` is a `usize` that is unique across the entire VirtualDOM and across time. ScopeIDs will never be reused
|
||||
/// once a component has been unmounted.
|
||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct ScopeId(pub usize);
|
||||
@@ -141,7 +142,7 @@ impl Scope {
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
|
||||
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
|
||||
/// dom.rebuild();
|
||||
///
|
||||
/// let base = dom.base_scope();
|
||||
@@ -161,7 +162,7 @@ impl Scope {
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
|
||||
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
|
||||
/// dom.rebuild();
|
||||
///
|
||||
/// let base = dom.base_scope();
|
||||
@@ -180,7 +181,7 @@ impl Scope {
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let mut dom = VirtualDom::new(|cx, props|cx.render(rsx!{ div {} }));
|
||||
/// let mut dom = VirtualDom::new(|cx, props| cx.render(rsx!{ div {} }));
|
||||
/// dom.rebuild();
|
||||
/// let base = dom.base_scope();
|
||||
///
|
||||
|
||||
@@ -347,12 +347,6 @@ impl VirtualDom {
|
||||
pub fn work_with_deadline(&mut self, mut deadline: impl FnMut() -> bool) -> Vec<Mutations> {
|
||||
let mut committed_mutations = vec![];
|
||||
|
||||
log::debug!(
|
||||
"Working with deadline. \nDirty scopes: {:?}. \nPending messages: {:?}",
|
||||
self.dirty_scopes,
|
||||
self.pending_messages
|
||||
);
|
||||
|
||||
while !self.dirty_scopes.is_empty() {
|
||||
let scopes = &self.scopes;
|
||||
let mut diff_state = DiffState::new(scopes);
|
||||
@@ -370,7 +364,6 @@ impl VirtualDom {
|
||||
});
|
||||
|
||||
if let Some(scopeid) = self.dirty_scopes.pop() {
|
||||
log::debug!("Analyzing dirty scope {:?}", scopeid);
|
||||
if !ran_scopes.contains(&scopeid) {
|
||||
ran_scopes.insert(scopeid);
|
||||
|
||||
@@ -379,7 +372,6 @@ impl VirtualDom {
|
||||
self.scopes.wip_head(&scopeid),
|
||||
self.scopes.fin_head(&scopeid),
|
||||
);
|
||||
log::debug!("Diffing old: {:?}, new: {:?}", old, new);
|
||||
diff_state.stack.push(DiffInstruction::Diff { new, old });
|
||||
diff_state.stack.scope_stack.push(scopeid);
|
||||
|
||||
@@ -390,20 +382,16 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
if diff_state.work(&mut deadline) {
|
||||
let DiffState {
|
||||
mutations,
|
||||
seen_scopes,
|
||||
..
|
||||
} = diff_state;
|
||||
let DiffState { mutations, .. } = diff_state;
|
||||
|
||||
for scope in seen_scopes {
|
||||
self.dirty_scopes.remove(&scope);
|
||||
for scope in &mutations.dirty_scopes {
|
||||
self.dirty_scopes.remove(scope);
|
||||
}
|
||||
log::debug!("Working generated mutations: {:?}", mutations);
|
||||
|
||||
committed_mutations.push(mutations);
|
||||
} else {
|
||||
log::debug!("Could not finish work in time");
|
||||
|
||||
// leave the work in an incomplete state
|
||||
return committed_mutations;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user