chore: clean up some more of the scopes file
This commit is contained in:
1 parent
268b1b0c66
commit
b4697fc9f9
3 files changed
+12
-32
No files matched your search
@@ -2,7 +2,7 @@ use crate::innerlude::*;
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
pub(crate) struct AsyncDiffState<'bump> {
|
||||
pub(crate) struct DiffState<'bump> {
|
||||
pub(crate) scopes: &'bump ScopeArena,
|
||||
pub(crate) mutations: Mutations<'bump>,
|
||||
pub(crate) force_diff: bool,
|
||||
@@ -10,7 +10,7 @@ pub(crate) struct AsyncDiffState<'bump> {
|
||||
pub(crate) scope_stack: SmallVec<[ScopeId; 5]>,
|
||||
}
|
||||
|
||||
impl<'b> AsyncDiffState<'b> {
|
||||
impl<'b> DiffState<'b> {
|
||||
pub fn new(scopes: &'b ScopeArena) -> Self {
|
||||
Self {
|
||||
scopes,
|
||||
|
||||
@@ -186,7 +186,7 @@ impl ScopeArena {
|
||||
let scope = unsafe { &mut *self.scopes.borrow_mut().remove(&id).unwrap() };
|
||||
scope.reset();
|
||||
|
||||
// self.free_scopes.borrow_mut().push(scope);
|
||||
self.free_scopes.borrow_mut().push(scope);
|
||||
|
||||
Some(())
|
||||
}
|
||||
@@ -202,14 +202,11 @@ impl ScopeArena {
|
||||
}
|
||||
|
||||
pub fn update_node<'a>(&self, node: &'a VNode<'a>, id: ElementId) {
|
||||
let node = unsafe { extend_vnode(node) };
|
||||
|
||||
let mut nodes = self.nodes.borrow_mut();
|
||||
let entry = nodes.get_mut(id.0);
|
||||
match entry {
|
||||
Some(_node) => *_node = node,
|
||||
None => panic!("cannot update node {}", id),
|
||||
}
|
||||
*self
|
||||
.nodes
|
||||
.borrow_mut()
|
||||
.get_mut(id.0)
|
||||
.expect("node to exist if it's being updated") = unsafe { extend_vnode(node) };
|
||||
}
|
||||
|
||||
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
|
||||
let scope = unsafe { &mut *self.get_scope_raw(id).expect("could not find scope") };
|
||||
|
||||
// if cfg!(debug_assertions) {
|
||||
// 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());
|
||||
});
|
||||
// }
|
||||
log::trace!("running scope {:?} symbol: {:?}", id, scope.fnptr);
|
||||
|
||||
// Safety:
|
||||
// - 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
|
||||
scope.hook_idx.set(0);
|
||||
|
||||
// book keeping to ensure safety around the borrowed data
|
||||
{
|
||||
// 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());
|
||||
}
|
||||
|
||||
// safety: this is definitely not dropped
|
||||
|
||||
/*
|
||||
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.
|
||||
@@ -332,14 +316,10 @@ impl ScopeArena {
|
||||
|
||||
while let Some(id) = cur_el.take() {
|
||||
if let Some(el) = nodes.get(id.0) {
|
||||
log::trace!("Found valid receiver element");
|
||||
|
||||
let real_el = unsafe { &**el };
|
||||
if let VNode::Element(real_el) = real_el {
|
||||
for listener in real_el.listeners.borrow().iter() {
|
||||
if listener.event == event.name {
|
||||
log::trace!("Found valid receiver event");
|
||||
|
||||
if state.canceled.get() {
|
||||
// stop bubbling if canceled
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! 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 futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use futures_util::{future::poll_fn, StreamExt};
|
||||
@@ -455,7 +455,7 @@ impl VirtualDom {
|
||||
|
||||
while !self.dirty_scopes.is_empty() {
|
||||
let scopes = &self.scopes;
|
||||
let mut diff_state = AsyncDiffState::new(scopes);
|
||||
let mut diff_state = DiffState::new(scopes);
|
||||
|
||||
let mut ran_scopes = FxHashSet::default();
|
||||
|
||||
@@ -479,7 +479,7 @@ impl VirtualDom {
|
||||
|
||||
diff_state.diff_scope(scopeid);
|
||||
|
||||
let AsyncDiffState { mutations, .. } = diff_state;
|
||||
let DiffState { mutations, .. } = diff_state;
|
||||
|
||||
log::debug!("succesffuly resolved scopes {:?}", mutations.dirty_scopes);
|
||||
for scope in &mutations.dirty_scopes {
|
||||
|
||||
Reference in new issue
Block a user