Replace with_scope_property with push_scope_property

Avoids duplicate codegen
This commit is contained in:
novacrazy 2023-04-06 20:26:58 -05:00
parent 5d6a083d1d
commit b1b9853f92
5 changed files with 9 additions and 12 deletions

View file

@ -66,7 +66,7 @@ where
if #[cfg(not(feature = "ssr"))] {
let e = cx.runtime.create_effect(f);
//eprintln!("created effect {e:?}");
cx.with_scope_property(|prop| prop.push(ScopeProperty::Effect(e)))
cx.push_scope_property(ScopeProperty::Effect(e))
} else {
// clear warnings
_ = cx;
@ -121,7 +121,7 @@ pub fn create_isomorphic_effect<T>(
{
let e = cx.runtime.create_effect(f);
//eprintln!("created effect {e:?}");
cx.with_scope_property(|prop| prop.push(ScopeProperty::Effect(e)))
cx.push_scope_property(ScopeProperty::Effect(e))
}
#[doc(hidden)]

View file

@ -216,7 +216,7 @@ where
}
});
cx.with_scope_property(|prop| prop.push(ScopeProperty::Resource(id)));
cx.push_scope_property(ScopeProperty::Resource(id));
Resource {
runtime: cx.runtime,
@ -339,7 +339,7 @@ where
move |_| r.load(false)
});
cx.with_scope_property(|prop| prop.push(ScopeProperty::Resource(id)));
cx.push_scope_property(ScopeProperty::Resource(id));
Resource {
runtime: cx.runtime,

View file

@ -290,14 +290,11 @@ impl Scope {
})
}
pub(crate) fn with_scope_property(
&self,
f: impl FnOnce(&mut Vec<ScopeProperty>),
) {
pub(crate) fn push_scope_property(&self, prop: ScopeProperty) {
_ = with_runtime(self.runtime, |runtime| {
let scopes = runtime.scopes.borrow();
if let Some(scope) = scopes.get(self.id) {
f(&mut scope.borrow_mut());
scope.borrow_mut().push(prop);
} else {
console_warn(
"tried to add property to a scope that has been disposed",

View file

@ -340,7 +340,7 @@ pub fn create_signal<T>(
value: T,
) -> (ReadSignal<T>, WriteSignal<T>) {
let s = cx.runtime.create_signal(value);
cx.with_scope_property(|prop| prop.push(ScopeProperty::Signal(s.0.id)));
cx.push_scope_property(ScopeProperty::Signal(s.0.id));
s
}
@ -1107,7 +1107,7 @@ impl<T> Copy for WriteSignal<T> {}
#[track_caller]
pub fn create_rw_signal<T>(cx: Scope, value: T) -> RwSignal<T> {
let s = cx.runtime.create_rw_signal(value);
cx.with_scope_property(|prop| prop.push(ScopeProperty::Signal(s.id)));
cx.push_scope_property(ScopeProperty::Signal(s.id));
s
}

View file

@ -418,7 +418,7 @@ where
.insert(Rc::new(RefCell::new(value)))
})
.unwrap_or_default();
cx.with_scope_property(|prop| prop.push(ScopeProperty::StoredValue(id)));
cx.push_scope_property(ScopeProperty::StoredValue(id));
StoredValue {
runtime: cx.runtime,
id,