diff --git a/src/doc.rs b/src/doc.rs index de16b37..dbf1e41 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -116,12 +116,14 @@ impl Doc { pub fn observe(&mut self, py: Python<'_>, f: PyObject) -> PyResult> { let sub = self.doc .observe_transaction_cleanup(move |txn, event| { - Python::with_gil(|py| { - let event = TransactionEvent::new(event, txn); - if let Err(err) = f.call1(py, (event,)) { - err.restore(py) - } - }) + if event.before_state != event.after_state { + Python::with_gil(|py| { + let event = TransactionEvent::new(event, txn); + if let Err(err) = f.call1(py, (event,)) { + err.restore(py) + } + }) + } }) .unwrap(); let s: Py = Py::new(py, Subscription::from(sub))?; diff --git a/tests/test_doc.py b/tests/test_doc.py index deea585..e54f3b1 100644 --- a/tests/test_doc.py +++ b/tests/test_doc.py @@ -179,3 +179,15 @@ def test_roots(): # assert str(roots["a"]) == "foo" # assert list(roots["b"]) == [5, 2, 8] # assert dict(roots["c"]) == None # {"k1": 1, "k2": 2} + + +def test_empty_update(): + doc = Doc() + doc["text"] = Text() + events = [] + sub = doc.observe(partial(callback, events)) # noqa: F841 + + # this triggers an empty update + doc["text"] + # empty updates should not emit an event + assert not events