wip: docs and router

This commit is contained in:
Jonathan Kelley committed 2021-11-19 00:49:04 -05:00
1 parent 8bf57dc21d
commit a5f05d73ac
50 files changed
+1263 -234

No files matched your search

+61 -12
View File
@@ -434,8 +434,15 @@ impl<'bump> DiffState<'bump> {
}
if !children.is_empty() {
self.stack.create_children(children, MountType::Append);
if children.len() == 1 {
if let VNode::Text(vtext) = children[0] {
self.mutations.set_text(vtext.text, real_id.as_u64());
return;
}
}
}
self.stack.create_children(children, MountType::Append);
}
fn create_fragment_node(&mut self, frag: &'bump VFragment<'bump>) {
@@ -645,17 +652,59 @@ impl<'bump> DiffState<'bump> {
}
}
if old.children.is_empty() && !new.children.is_empty() {
self.mutations.edits.push(PushRoot {
root: root.as_u64(),
});
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.stack.create_children(new.children, MountType::Append);
} else {
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.diff_children(old.children, new.children);
match (old.children.len(), new.children.len()) {
(0, 0) => {}
(1, 1) => {
let old1 = &old.children[0];
let new1 = &new.children[0];
match (old1, new1) {
(VNode::Text(old_text), VNode::Text(new_text)) => {
if old_text.text != new_text.text {
self.mutations.set_text(new_text.text, root.as_u64());
}
}
(VNode::Text(old_text), _) => {
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.stack.create_node(new1, MountType::Append);
}
(_, VNode::Text(new_text)) => {
self.remove_nodes([old1], false);
self.mutations.set_text(new_text.text, root.as_u64());
}
_ => {
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.diff_children(old.children, new.children);
}
}
}
(0, 1) => {
if let VNode::Text(text) = &new.children[0] {
self.mutations.set_text(text.text, root.as_u64());
} else {
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
}
}
(0, _) => {
self.mutations.edits.push(PushRoot {
root: root.as_u64(),
});
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.stack.create_children(new.children, MountType::Append);
}
(_, 0) => {
self.remove_nodes(old.children, false);
self.mutations.set_text("", root.as_u64());
}
(_, _) => {
self.stack.element_stack.push(root);
self.stack.instructions.push(DiffInstruction::PopElement);
self.diff_children(old.children, new.children);
}
}
}
+1 -1
View File
@@ -196,7 +196,7 @@ impl Scope {
let chan = self.sender.clone();
let id = self.scope_id();
Rc::new(move || {
log::debug!("set on channel an update for scope {:?}", id);
// log::debug!("set on channel an update for scope {:?}", id);
let _ = chan.unbounded_send(SchedulerMsg::Immediate(id));
})
}
+8 -8
View File
@@ -92,15 +92,15 @@ impl ScopeArena {
let new_scope_id = ScopeId(self.scope_counter.get());
self.scope_counter.set(self.scope_counter.get() + 1);
log::debug!("new scope {:?} with parent {:?}", new_scope_id, container);
// log::debug!("new scope {:?} with parent {:?}", new_scope_id, container);
if let Some(old_scope) = self.free_scopes.borrow_mut().pop() {
let scope = unsafe { &mut *old_scope };
log::debug!(
"reusing scope {:?} as {:?}",
scope.our_arena_idx,
new_scope_id
);
// log::debug!(
// "reusing scope {:?} as {:?}",
// scope.our_arena_idx,
// new_scope_id
// );
scope.caller = caller;
scope.parent_scope = parent_scope;
@@ -202,7 +202,7 @@ impl ScopeArena {
pub fn try_remove(&self, id: &ScopeId) -> Option<()> {
self.ensure_drop_safety(id);
log::debug!("removing scope {:?}", id);
// log::debug!("removing scope {:?}", id);
// Safety:
// - ensure_drop_safety ensures that no references to this scope are in use
@@ -311,7 +311,7 @@ impl ScopeArena {
let scope = unsafe { &mut *self.get_scope_mut(id).expect("could not find scope") };
log::debug!("found scope, about to run: {:?}", id);
// log::debug!("found scope, about to run: {:?}", id);
// Safety:
// - We dropped the listeners, so no more &mut T can be used while these are held
+1 -1
View File
@@ -352,7 +352,7 @@ impl VirtualDom {
let mut committed_mutations = vec![];
while !self.dirty_scopes.is_empty() {
log::debug!("working with deadline");
// log::debug!("working with deadline");
let scopes = &self.scopes;
let mut diff_state = DiffState::new(scopes);