mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-02 11:06:14 +00:00
fix: empty diff emits event (#292)
This commit is contained in:
parent
f7fe0d4b26
commit
83d4950a4e
2 changed files with 15 additions and 1 deletions
|
@ -292,7 +292,7 @@ impl DocState {
|
|||
/// Panic when the diff cannot be merged with the previous diff.
|
||||
/// Caller should call [pre_txn] before calling this to avoid panic.
|
||||
fn record_diff(&mut self, diff: InternalDocDiff) {
|
||||
if !self.event_recorder.recording_diff {
|
||||
if !self.event_recorder.recording_diff || diff.diff.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -878,3 +878,17 @@ fn missing_event_when_checkout() {
|
|||
doc.attach();
|
||||
assert!(value.lock().unwrap().contains_key("b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_event() {
|
||||
let doc = LoroDoc::new_auto_commit();
|
||||
doc.get_map("map").insert("key", 123).unwrap();
|
||||
doc.commit_then_renew();
|
||||
let fire = Arc::new(AtomicBool::new(false));
|
||||
let fire_clone = Arc::clone(&fire);
|
||||
doc.subscribe_root(Arc::new(move |_e| {
|
||||
fire_clone.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}));
|
||||
doc.import(&doc.export_snapshot()).unwrap();
|
||||
assert!(!fire.load(std::sync::atomic::Ordering::Relaxed));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue