From a308a779f210e8b8456c136382eaa6c1851d6c07 Mon Sep 17 00:00:00 2001 From: Bartosz Sypytkowski Date: Thu, 4 Jul 2024 19:49:32 +0200 Subject: [PATCH] add missing non-sync methods: Branch::observe_deep/Doc::observe_destroy --- yrs/src/branch.rs | 8 ++++++++ yrs/src/doc.rs | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/yrs/src/branch.rs b/yrs/src/branch.rs index 9b0c3e48..70cab9f7 100644 --- a/yrs/src/branch.rs +++ b/yrs/src/branch.rs @@ -579,6 +579,14 @@ impl Branch { self.deep_observers.subscribe(Box::new(f)) } + #[cfg(not(feature = "sync"))] + pub fn observe_deep(&self, f: F) -> Subscription + where + F: Fn(&TransactionMut, &Events) + 'static, + { + self.deep_observers.subscribe(Box::new(f)) + } + #[cfg(feature = "sync")] pub fn observe_deep_with(&self, key: Origin, f: F) where diff --git a/yrs/src/doc.rs b/yrs/src/doc.rs index c0ddd5cf..0c8c115b 100644 --- a/yrs/src/doc.rs +++ b/yrs/src/doc.rs @@ -570,6 +570,17 @@ impl Doc { Ok(events.destroy_events.subscribe(Box::new(f))) } + /// Subscribe callback function, that will be called whenever a [DocRef::destroy] has been called. + #[cfg(not(feature = "sync"))] + pub fn observe_destroy(&self, f: F) -> Result + where + F: Fn(&TransactionMut, &Doc) + 'static, + { + let mut r = self.store.try_borrow_mut()?; + let events = r.events.get_or_init(); + Ok(events.destroy_events.subscribe(Box::new(f))) + } + /// Subscribe callback function, that will be called whenever a [DocRef::destroy] has been called. #[cfg(feature = "sync")] pub fn observe_destroy_with(&self, key: K, f: F) -> Result<(), BorrowMutError>