Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignoring empty update #111

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading