Skip to content

Commit

Permalink
Aligning rs and py on observation id term
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlopashev committed Dec 30, 2024
1 parent ab67b97 commit 1d7a5b5
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 152 deletions.
2 changes: 1 addition & 1 deletion src/shared_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl DefaultPyErr for IntegratedOperationException {

#[pyclass]
#[derive(Clone)]
pub struct PyOrigin(pub Origin);
pub struct ObservationId(pub Origin);

#[derive(Clone)]
pub enum CompatiblePyType<'a> {
Expand Down
24 changes: 12 additions & 12 deletions src/y_array.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::json_builder::JsonBuilder;
use crate::shared_types::{
CompatiblePyType, DefaultPyErr, PreliminaryObservationException, PyOrigin, TypeWithDoc,
CompatiblePyType, DefaultPyErr, ObservationId, PreliminaryObservationException, TypeWithDoc,
};
use crate::type_conversions::{events_into_py, WithDocToPython};
use crate::y_doc::{WithDoc, YDocInner};
Expand Down Expand Up @@ -364,8 +364,8 @@ impl YArray {

/// Subscribes to all operations happening over this instance of `YArray`. All changes are
/// batched and eventually triggered during transaction commit phase.
/// Returns a `PyOrigin` which can be used to cancel the callback with `unobserve`.
pub fn observe(&mut self, f: PyObject) -> PyResult<PyOrigin> {
/// Returns a `ObservationId` which can be used to cancel the callback with `unobserve`.
pub fn observe(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(array) => {
let doc = array.doc.clone();
Expand All @@ -378,13 +378,13 @@ impl YArray {
}
})
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}
/// Observes YArray events and events of all child elements.
pub fn observe_deep(&mut self, f: PyObject) -> PyResult<PyOrigin> {
pub fn observe_deep(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(array) => {
let doc = array.doc.clone();
Expand All @@ -399,24 +399,24 @@ impl YArray {
}
})
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the callback of an observer using the `sub_id` returned from the `observe` method.
pub fn unobserve(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the callback of an observer using the `observation_d` returned from the `observe` method.
pub fn unobserve(&mut self, observation_d: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(arr) => Ok(arr.unobserve(Origin::from(origin.0))),
SharedType::Integrated(arr) => Ok(arr.unobserve(observation_d.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the callback of an observer using the `sub_id` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the callback of an observer using the `observation_d` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, observation_d: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(arr) => Ok(arr.unobserve_deep(Origin::from(origin.0))),
SharedType::Integrated(arr) => Ok(arr.unobserve_deep(observation_d.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/y_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::RefCell;
use std::rc::Rc;
use std::rc::Weak;

use crate::shared_types::PyOrigin;
use crate::shared_types::ObservationId;
use crate::y_array::YArray;
use crate::y_map::YMap;
use crate::y_text::YText;
Expand Down Expand Up @@ -282,7 +282,7 @@ impl YDoc {
}

/// Subscribes a callback to a `YDoc` lifecycle event.
pub fn observe_after_transaction(&mut self, callback: PyObject) -> PyOrigin {
pub fn observe_after_transaction(&mut self, callback: PyObject) -> ObservationId {
let origin = Origin::from(uuid_v4().to_string());
self.0
.borrow()
Expand All @@ -296,7 +296,7 @@ impl YDoc {
})
})
.unwrap();
PyOrigin(origin)
ObservationId(origin)
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/y_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use yrs::{uuid_v4, Map, MapRef, Observable, Origin, TransactionMut};

use crate::json_builder::JsonBuilder;
use crate::shared_types::{
DefaultPyErr, PreliminaryObservationException, PyOrigin, SharedType, TypeWithDoc,
DefaultPyErr, ObservationId, PreliminaryObservationException, SharedType, TypeWithDoc,
};
use crate::type_conversions::{events_into_py, PyObjectWrapper, ToPython, WithDocToPython};
use crate::y_doc::{WithDoc, YDocInner};
Expand Down Expand Up @@ -261,7 +261,7 @@ impl YMap {
ValueView::new(self)
}

pub fn observe(&mut self, f: PyObject) -> PyResult<PyOrigin> {
pub fn observe(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(v) => {
let doc = v.doc.clone();
Expand All @@ -275,13 +275,13 @@ impl YMap {
}
})
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

pub fn observe_deep(&mut self, f: PyObject) -> PyResult<PyOrigin> {
pub fn observe_deep(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(map) => {
let doc = map.doc.clone();
Expand All @@ -295,24 +295,24 @@ impl YMap {
}
})
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the observer callback associated with the `sub_id` returned from the `observe` method.
pub fn unobserve(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the observer callback associated with the `observation_id` returned from the `observe` method.
pub fn unobserve(&mut self, observation_id: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(map) => Ok(map.unobserve(Origin::from(origin.0))),
SharedType::Integrated(map) => Ok(map.unobserve(observation_id.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the observer callback associated with the `sub_id` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the observer callback associated with the `observation_id` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, observation_id: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(map) => Ok(map.unobserve_deep(Origin::from(origin.0))),
SharedType::Integrated(map) => Ok(map.unobserve_deep(observation_id.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/y_text.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::shared_types::{
CompatiblePyType, DefaultPyErr, IntegratedOperationException, PreliminaryObservationException,
PyOrigin, SharedType, TypeWithDoc,
CompatiblePyType, DefaultPyErr, IntegratedOperationException, ObservationId,
PreliminaryObservationException, SharedType, TypeWithDoc,
};
use crate::type_conversions::{events_into_py, ToPython, WithDocToPython};
use crate::y_doc::{WithDoc, YDocInner};
Expand Down Expand Up @@ -237,7 +237,7 @@ impl YText {
}

/// Observes updates from the `YText` instance.
pub fn observe(&mut self, f: PyObject) -> PyResult<PyOrigin> {
pub fn observe(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(text) => {
let doc = text.doc.clone();
Expand All @@ -250,14 +250,14 @@ impl YText {
}
});
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Observes updates from the `YText` instance and all of its nested children.
pub fn observe_deep(&mut self, f: PyObject) -> PyResult<PyOrigin> {
pub fn observe_deep(&mut self, f: PyObject) -> PyResult<ObservationId> {
match &mut self.0 {
SharedType::Integrated(text) => {
let doc = text.doc.clone();
Expand All @@ -271,24 +271,24 @@ impl YText {
}
})
});
Ok(PyOrigin(origin))
Ok(ObservationId(origin))
}
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the observer callback associated with the `sub_id` returned from the `observe` method.
pub fn unobserve(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the observer callback associated with the `observation_id` returned from the `observe` method.
pub fn unobserve(&mut self, observation_id: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(text) => Ok(text.unobserve(Origin::from(origin.0))),
SharedType::Integrated(text) => Ok(text.unobserve(observation_id.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}

/// Cancels the observer callback associated with the `sub_id` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, origin: PyOrigin) -> PyResult<bool> {
/// Cancels the observer callback associated with the `observation_id` returned from the `observe_deep` method.
pub fn unobserve_deep(&mut self, observation_id: ObservationId) -> PyResult<bool> {
match &mut self.0 {
SharedType::Integrated(text) => Ok(text.unobserve_deep(Origin::from(origin.0))),
SharedType::Integrated(text) => Ok(text.unobserve_deep(observation_id.0)),
SharedType::Prelim(_) => Err(PreliminaryObservationException::default_message()),
}
}
Expand Down
Loading

0 comments on commit 1d7a5b5

Please sign in to comment.