From 9c03d68d888453c96be7f1c5ad68b2ec16d64756 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 21 Aug 2023 14:33:52 -0500 Subject: [PATCH] expose new_in_scope for signals --- packages/signals/src/signal.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/signals/src/signal.rs b/packages/signals/src/signal.rs index a5599a1ce..f41624f96 100644 --- a/packages/signals/src/signal.rs +++ b/packages/signals/src/signal.rs @@ -145,6 +145,21 @@ impl Signal { } } + /// Create a new signal with a custom owner scope. The signal will be dropped when the owner scope is dropped instead of the current scope. + pub fn new_in_scope(value: T, owner: ScopeId) -> Self { + Self { + inner: CopyValue::new_in_scope( + SignalData { + subscribers: Default::default(), + effect_subscribers: Default::default(), + update_any: schedule_update_any().expect("in a virtual dom"), + value, + }, + owner, + ), + } + } + /// Get the scope the signal was created in. pub fn origin_scope(&self) -> ScopeId { self.inner.origin_scope()