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
This commit is contained in:
Michael Sippel 2021-01-12 22:31:19 +01:00
parent 5007fdea3c
commit ceb0a8a5a9
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -111,15 +111,17 @@ impl<V: View + ?Sized + 'static> OuterViewPort<V> {
self.get_view_arc() self.get_view_arc()
} }
/* pub fn add_reset_fn<F: Fn(Option<Arc<V>>) + Send + Sync + 'static>(&self, reset: F) -> Arc<RwLock<ResetFnObserver<V, F>>> {
pub fn add_reset_fn(&self, reset: impl Fn(Option<Arc<V>>) + Send + Sync + 'static) -> Arc<RwLock<Option<Arc<V>>>> { let obs = Arc::new(RwLock::new(ResetFnObserver::new(reset)));
self.add_observer(Arc::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<RwLock<Option<Arc<V>>>> { pub fn add_notify_fn<F: Fn(&V::Msg) + Send + Sync + 'static>(&self, notify: F) -> Arc<RwLock<NotifyFnObserver<V, F>>> {
self.add_observer(Arc::new(NotifyFnObserver::new(notify))) let obs = Arc::new(RwLock::new(NotifyFnObserver::new(notify)));
self.add_observer(obs.clone());
obs
} }
*/
} }
/* /*