Skip to content

Commit

Permalink
Fix ignoring empty update (#111)
Browse files Browse the repository at this point in the history
* Add test for non-empty update

* Add fix for ignoring empty update
  • Loading branch information
davidbrochart authored May 12, 2024
1 parent f5a9104 commit 02d81f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Doc {
pub fn observe(&mut self, py: Python<'_>, f: PyObject) -> PyResult<Py<Subscription>> {
let sub = self.doc
.observe_transaction_cleanup(move |txn, event| {
if event.before_state != event.after_state {
if !event.delete_set.is_empty() || event.before_state != event.after_state {
Python::with_gil(|py| {
let event = TransactionEvent::new(event, txn);
if let Err(err) = f.call1(py, (event,)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,15 @@ def test_empty_update():
doc["text"]
# empty updates should not emit an event
assert not events


def test_not_empty_update():
doc = Doc()
doc["text"] = text = Text()
events = []
sub = doc.observe(partial(callback, events)) # noqa: F841

text += "helloo"
events.clear()
del text[5]
assert events

0 comments on commit 02d81f5

Please sign in to comment.