From ceb0a8a5a9387cdffcd26ee19adc917f0c56ee28 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 12 Jan 2021 22:31:19 +0100 Subject: [PATCH] port: add_[observer|reset]_fn return the observer object instead of view now because we use Weak in ObserverBroadcast, we need at least one Arc somewhere else --- src/core/port.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/port.rs b/src/core/port.rs index 334941d..7ba8a25 100644 --- a/src/core/port.rs +++ b/src/core/port.rs @@ -111,15 +111,17 @@ impl OuterViewPort { self.get_view_arc() } -/* - pub fn add_reset_fn(&self, reset: impl Fn(Option>) + Send + Sync + 'static) -> Arc>>> { - self.add_observer(Arc::new(ResetFnObserver::new(reset))) + pub fn add_reset_fn>) + Send + Sync + 'static>(&self, reset: F) -> Arc>> { + let obs = Arc::new(RwLock::new(ResetFnObserver::new(reset))); + self.add_observer(obs.clone()); + obs } - pub fn add_notify_fn(&self, notify: impl Fn(&V::Msg) + Send + Sync + 'static) -> Arc>>> { - self.add_observer(Arc::new(NotifyFnObserver::new(notify))) + pub fn add_notify_fn(&self, notify: F) -> Arc>> { + let obs = Arc::new(RwLock::new(NotifyFnObserver::new(notify))); + self.add_observer(obs.clone()); + obs } -*/ } /*