fix recursive runtime drop impl

This commit is contained in:
Evan Almloff committed 2023-08-04 14:14:56 -07:00
1 parent cb4c46154d
commit b09e528aaa
2 files changed
+6 -9

No files matched your search

-8
View File
@@ -49,13 +49,6 @@ pub struct Runtime {
pub(crate) scope_stack: RefCell<Vec<ScopeId>>, pub(crate) scope_stack: RefCell<Vec<ScopeId>>,
} }
impl Drop for Runtime {
fn drop(&mut self) {
// todo: do this better
pop_runtime();
}
}
impl Runtime { impl Runtime {
pub(crate) fn new(scheduler: Rc<Scheduler>) -> Rc<Self> { pub(crate) fn new(scheduler: Rc<Scheduler>) -> Rc<Self> {
let runtime = Rc::new(Self { let runtime = Rc::new(Self {
@@ -65,7 +58,6 @@ impl Runtime {
scope_stack: Default::default(), scope_stack: Default::default(),
}); });
push_runtime(runtime.clone());
runtime runtime
} }
+6 -1
View File
@@ -9,7 +9,7 @@ use crate::{
mutations::Mutation, mutations::Mutation,
nodes::RenderReturn, nodes::RenderReturn,
nodes::{Template, TemplateId}, nodes::{Template, TemplateId},
runtime::Runtime, runtime::{pop_runtime, push_runtime, Runtime},
scopes::{ScopeId, ScopeState}, scopes::{ScopeId, ScopeState},
AttributeValue, Element, Event, Scope, AttributeValue, Element, Event, Scope,
}; };
@@ -275,6 +275,9 @@ impl VirtualDom {
// the root element is always given element ID 0 since it's the container for the entire tree // the root element is always given element ID 0 since it's the container for the entire tree
dom.elements.insert(ElementRef::none()); dom.elements.insert(ElementRef::none());
// Set this as the current runtime
push_runtime(dom.runtime.clone());
dom dom
} }
@@ -648,5 +651,7 @@ impl Drop for VirtualDom {
fn drop(&mut self) { fn drop(&mut self) {
// Simply drop this scope which drops all of its children // Simply drop this scope which drops all of its children
self.drop_scope(ScopeId(0), true); self.drop_scope(ScopeId(0), true);
// remove the current runtime
pop_runtime();
} }
} }