From b1b9853f92bd779af831b4852e2900f1d66da9fb Mon Sep 17 00:00:00 2001 From: novacrazy Date: Thu, 6 Apr 2023 20:26:58 -0500 Subject: [PATCH] Replace with_scope_property with push_scope_property Avoids duplicate codegen --- leptos_reactive/src/effect.rs | 4 ++-- leptos_reactive/src/resource.rs | 4 ++-- leptos_reactive/src/scope.rs | 7 ++----- leptos_reactive/src/signal.rs | 4 ++-- leptos_reactive/src/stored_value.rs | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/leptos_reactive/src/effect.rs b/leptos_reactive/src/effect.rs index 5cb9e5ed7..b2e31f8ee 100644 --- a/leptos_reactive/src/effect.rs +++ b/leptos_reactive/src/effect.rs @@ -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( { 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)] diff --git a/leptos_reactive/src/resource.rs b/leptos_reactive/src/resource.rs index d256474b0..7acad0f2d 100644 --- a/leptos_reactive/src/resource.rs +++ b/leptos_reactive/src/resource.rs @@ -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, diff --git a/leptos_reactive/src/scope.rs b/leptos_reactive/src/scope.rs index e5299cc4b..2f5e8a567 100644 --- a/leptos_reactive/src/scope.rs +++ b/leptos_reactive/src/scope.rs @@ -290,14 +290,11 @@ impl Scope { }) } - pub(crate) fn with_scope_property( - &self, - f: impl FnOnce(&mut Vec), - ) { + 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", diff --git a/leptos_reactive/src/signal.rs b/leptos_reactive/src/signal.rs index 8026e9e0b..d4aa47f4d 100644 --- a/leptos_reactive/src/signal.rs +++ b/leptos_reactive/src/signal.rs @@ -340,7 +340,7 @@ pub fn create_signal( value: T, ) -> (ReadSignal, WriteSignal) { 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 Copy for WriteSignal {} #[track_caller] pub fn create_rw_signal(cx: Scope, value: T) -> RwSignal { 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 } diff --git a/leptos_reactive/src/stored_value.rs b/leptos_reactive/src/stored_value.rs index 25c8463fe..3a890f6b3 100644 --- a/leptos_reactive/src/stored_value.rs +++ b/leptos_reactive/src/stored_value.rs @@ -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,