Skip to content

Commit

Permalink
add missing non-sync methods: Branch::observe_deep/Doc::observe_destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Jul 4, 2024
1 parent fc9026e commit a308a77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions yrs/src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ impl Branch {
self.deep_observers.subscribe(Box::new(f))
}

#[cfg(not(feature = "sync"))]
pub fn observe_deep<F>(&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<F>(&self, key: Origin, f: F)
where
Expand Down
11 changes: 11 additions & 0 deletions yrs/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F>(&self, f: F) -> Result<Subscription, BorrowMutError>
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<K, F>(&self, key: K, f: F) -> Result<(), BorrowMutError>
Expand Down

0 comments on commit a308a77

Please sign in to comment.