chore: clean up some more of the scopes file

This commit is contained in:
Jonathan Kelley committed 2022-01-31 03:27:43 -05:00
1 parent 268b1b0c66
commit b4697fc9f9
3 files changed
+12 -32

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@ use crate::innerlude::*;
use fxhash::{FxHashMap, FxHashSet}; use fxhash::{FxHashMap, FxHashSet};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
pub(crate) struct AsyncDiffState<'bump> { pub(crate) struct DiffState<'bump> {
pub(crate) scopes: &'bump ScopeArena, pub(crate) scopes: &'bump ScopeArena,
pub(crate) mutations: Mutations<'bump>, pub(crate) mutations: Mutations<'bump>,
pub(crate) force_diff: bool, pub(crate) force_diff: bool,
@@ -10,7 +10,7 @@ pub(crate) struct AsyncDiffState<'bump> {
pub(crate) scope_stack: SmallVec<[ScopeId; 5]>, pub(crate) scope_stack: SmallVec<[ScopeId; 5]>,
} }
impl<'b> AsyncDiffState<'b> { impl<'b> DiffState<'b> {
pub fn new(scopes: &'b ScopeArena) -> Self { pub fn new(scopes: &'b ScopeArena) -> Self {
Self { Self {
scopes, scopes,
+7 -27
View File
@@ -186,7 +186,7 @@ impl ScopeArena {
let scope = unsafe { &mut *self.scopes.borrow_mut().remove(&id).unwrap() }; let scope = unsafe { &mut *self.scopes.borrow_mut().remove(&id).unwrap() };
scope.reset(); scope.reset();
// self.free_scopes.borrow_mut().push(scope); self.free_scopes.borrow_mut().push(scope);
Some(()) Some(())
} }
@@ -202,14 +202,11 @@ impl ScopeArena {
} }
pub fn update_node<'a>(&self, node: &'a VNode<'a>, id: ElementId) { pub fn update_node<'a>(&self, node: &'a VNode<'a>, id: ElementId) {
let node = unsafe { extend_vnode(node) }; *self
.nodes
let mut nodes = self.nodes.borrow_mut(); .borrow_mut()
let entry = nodes.get_mut(id.0); .get_mut(id.0)
match entry { .expect("node to exist if it's being updated") = unsafe { extend_vnode(node) };
Some(_node) => *_node = node,
None => panic!("cannot update node {}", id),
}
} }
pub fn collect_garbage(&self, id: ElementId) { pub fn collect_garbage(&self, id: ElementId) {
@@ -259,24 +256,13 @@ impl ScopeArena {
// todo: we *know* that this is aliased by the contents of the scope itself // todo: we *know* that this is aliased by the contents of the scope itself
let scope = unsafe { &mut *self.get_scope_raw(id).expect("could not find scope") }; let scope = unsafe { &mut *self.get_scope_raw(id).expect("could not find scope") };
// if cfg!(debug_assertions) { log::trace!("running scope {:?} symbol: {:?}", id, scope.fnptr);
// log::debug!("running scope {:?} symbol: {:?}", id, scope.fnptr);
// todo: resolve frames properly
backtrace::resolve(scope.fnptr, |symbol| {
// backtrace::resolve(scope.fnptr as *mut std::os::raw::c_void, |symbol| {
// panic!("asd");
// log::trace!("Running scope {:?}, ptr {:?}", id, scope.fnptr);
log::debug!("running scope {:?} symbol: {:?}", id, symbol.name());
});
// }
// Safety: // Safety:
// - We dropped the listeners, so no more &mut T can be used while these are held // - We dropped the listeners, so no more &mut T can be used while these are held
// - All children nodes that rely on &mut T are replaced with a new reference // - All children nodes that rely on &mut T are replaced with a new reference
scope.hook_idx.set(0); scope.hook_idx.set(0);
// book keeping to ensure safety around the borrowed data
{ {
// Safety: // Safety:
// - We've dropped all references to the wip bump frame with "ensure_drop_safety" // - We've dropped all references to the wip bump frame with "ensure_drop_safety"
@@ -289,8 +275,6 @@ impl ScopeArena {
debug_assert!(items.borrowed_props.is_empty()); debug_assert!(items.borrowed_props.is_empty());
} }
// safety: this is definitely not dropped
/* /*
If the component returns None, then we fill in a placeholder node. This will wipe what was there. If the component returns None, then we fill in a placeholder node. This will wipe what was there.
An alternate approach is to leave the Real Dom the same, but that can lead to safety issues and a lot more checks. An alternate approach is to leave the Real Dom the same, but that can lead to safety issues and a lot more checks.
@@ -332,14 +316,10 @@ impl ScopeArena {
while let Some(id) = cur_el.take() { while let Some(id) = cur_el.take() {
if let Some(el) = nodes.get(id.0) { if let Some(el) = nodes.get(id.0) {
log::trace!("Found valid receiver element");
let real_el = unsafe { &**el }; let real_el = unsafe { &**el };
if let VNode::Element(real_el) = real_el { if let VNode::Element(real_el) = real_el {
for listener in real_el.listeners.borrow().iter() { for listener in real_el.listeners.borrow().iter() {
if listener.event == event.name { if listener.event == event.name {
log::trace!("Found valid receiver event");
if state.canceled.get() { if state.canceled.get() {
// stop bubbling if canceled // stop bubbling if canceled
break; break;
+3 -3
View File
@@ -2,7 +2,7 @@
//! //!
//! This module provides the primary mechanics to create a hook-based, concurrent VDOM for Rust. //! This module provides the primary mechanics to create a hook-based, concurrent VDOM for Rust.
use crate::diff::AsyncDiffState as DiffState; use crate::diff::DiffState;
use crate::innerlude::*; use crate::innerlude::*;
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender}; use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
use futures_util::{future::poll_fn, StreamExt}; use futures_util::{future::poll_fn, StreamExt};
@@ -455,7 +455,7 @@ impl VirtualDom {
while !self.dirty_scopes.is_empty() { while !self.dirty_scopes.is_empty() {
let scopes = &self.scopes; let scopes = &self.scopes;
let mut diff_state = AsyncDiffState::new(scopes); let mut diff_state = DiffState::new(scopes);
let mut ran_scopes = FxHashSet::default(); let mut ran_scopes = FxHashSet::default();
@@ -479,7 +479,7 @@ impl VirtualDom {
diff_state.diff_scope(scopeid); diff_state.diff_scope(scopeid);
let AsyncDiffState { mutations, .. } = diff_state; let DiffState { mutations, .. } = diff_state;
log::debug!("succesffuly resolved scopes {:?}", mutations.dirty_scopes); log::debug!("succesffuly resolved scopes {:?}", mutations.dirty_scopes);
for scope in &mutations.dirty_scopes { for scope in &mutations.dirty_scopes {