@hocuspocus/provider 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1782,7 +1782,7 @@ class MessageReceiver {
1782
1782
  }
1783
1783
  if (syncMessageType === messageYjsUpdate || syncMessageType === messageYjsSyncStep2) {
1784
1784
  if (provider.unsyncedChanges > 0) {
1785
- provider.unsyncedChanges -= 1;
1785
+ provider.updateUnsyncedChanges(-1);
1786
1786
  }
1787
1787
  }
1788
1788
  }
@@ -2379,6 +2379,10 @@ class HocuspocusProvider extends EventEmitter {
2379
2379
  get hasUnsyncedChanges() {
2380
2380
  return this.unsyncedChanges > 0;
2381
2381
  }
2382
+ updateUnsyncedChanges(unsyncedChanges = 0) {
2383
+ this.unsyncedChanges += unsyncedChanges;
2384
+ this.emit('unsyncedChanges', this.unsyncedChanges);
2385
+ }
2382
2386
  forceSync() {
2383
2387
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
2384
2388
  }
@@ -2398,7 +2402,7 @@ class HocuspocusProvider extends EventEmitter {
2398
2402
  if (origin === this) {
2399
2403
  return;
2400
2404
  }
2401
- this.unsyncedChanges += 1;
2405
+ this.updateUnsyncedChanges(1);
2402
2406
  this.send(UpdateMessage, { update, documentName: this.configuration.name }, true);
2403
2407
  }
2404
2408
  awarenessUpdateHandler({ added, updated, removed }, origin) {
@@ -2416,6 +2420,9 @@ class HocuspocusProvider extends EventEmitter {
2416
2420
  if (this.isSynced === state) {
2417
2421
  return;
2418
2422
  }
2423
+ if (state && this.unsyncedChanges > 0) {
2424
+ this.updateUnsyncedChanges(-1 * this.unsyncedChanges);
2425
+ }
2419
2426
  this.isSynced = state;
2420
2427
  this.emit('synced', { state });
2421
2428
  this.emit('sync', { state });