File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -116,12 +116,14 @@ impl Doc {
116
116
pub fn observe ( & mut self , py : Python < ' _ > , f : PyObject ) -> PyResult < Py < Subscription > > {
117
117
let sub = self . doc
118
118
. observe_transaction_cleanup ( move |txn, event| {
119
- Python :: with_gil ( |py| {
120
- let event = TransactionEvent :: new ( event, txn) ;
121
- if let Err ( err) = f. call1 ( py, ( event, ) ) {
122
- err. restore ( py)
123
- }
124
- } )
119
+ if event. before_state != event. after_state {
120
+ Python :: with_gil ( |py| {
121
+ let event = TransactionEvent :: new ( event, txn) ;
122
+ if let Err ( err) = f. call1 ( py, ( event, ) ) {
123
+ err. restore ( py)
124
+ }
125
+ } )
126
+ }
125
127
} )
126
128
. unwrap ( ) ;
127
129
let s: Py < Subscription > = Py :: new ( py, Subscription :: from ( sub) ) ?;
Original file line number Diff line number Diff line change @@ -179,3 +179,15 @@ def test_roots():
179
179
# assert str(roots["a"]) == "foo"
180
180
# assert list(roots["b"]) == [5, 2, 8]
181
181
# assert dict(roots["c"]) == None # {"k1": 1, "k2": 2}
182
+
183
+
184
+ def test_empty_update ():
185
+ doc = Doc ()
186
+ doc ["text" ] = Text ()
187
+ events = []
188
+ sub = doc .observe (partial (callback , events )) # noqa: F841
189
+
190
+ # this triggers an empty update
191
+ doc ["text" ]
192
+ # empty updates should not emit an event
193
+ assert not events
You can’t perform that action at this time.
0 commit comments