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

View file

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

View file

@ -340,7 +340,7 @@ pub fn create_signal<T>(
value: T, value: T,
) -> (ReadSignal<T>, WriteSignal<T>) { ) -> (ReadSignal<T>, WriteSignal<T>) {
let s = cx.runtime.create_signal(value); 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 s
} }
@ -1107,7 +1107,7 @@ impl<T> Copy for WriteSignal<T> {}
#[track_caller] #[track_caller]
pub fn create_rw_signal<T>(cx: Scope, value: T) -> RwSignal<T> { pub fn create_rw_signal<T>(cx: Scope, value: T) -> RwSignal<T> {
let s = cx.runtime.create_rw_signal(value); 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 s
} }

View file

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