Skip to content

Commit

Permalink
reset unsyncedChanges onOpen and on startSync (#826)
Browse files Browse the repository at this point in the history
* reset unsyncedChanges onOpen and on startSync

* emit event after resetting counter
  • Loading branch information
janthurau authored Jun 6, 2024
1 parent 194f43e commit 4ebf818
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/provider/src/HocuspocusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ export class HocuspocusProvider extends EventEmitter {
return this.unsyncedChanges > 0
}

private resetUnsyncedChanges() {
this.unsyncedChanges = 1
this.emit('unsyncedChanges', this.unsyncedChanges)
}

incrementUnsyncedChanges() {
this.unsyncedChanges += 1
this.emit('unsyncedChanges', this.unsyncedChanges)
Expand All @@ -296,6 +301,8 @@ export class HocuspocusProvider extends EventEmitter {
}

forceSync() {
this.resetUnsyncedChanges()

this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
}

Expand Down Expand Up @@ -364,7 +371,7 @@ export class HocuspocusProvider extends EventEmitter {
return !!this.configuration.token && !this.isAuthenticated
}

// not needed, but provides backward compatibility with e.g. lexicla/yjs
// not needed, but provides backward compatibility with e.g. lexical/yjs
async connect() {
if (this.configuration.broadcast) {
this.subscribeToBroadcastChannel()
Expand Down Expand Up @@ -420,7 +427,8 @@ export class HocuspocusProvider extends EventEmitter {
}

startSync() {
this.incrementUnsyncedChanges()
this.resetUnsyncedChanges()

this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })

if (this.awareness && this.awareness.getLocalState() !== null) {
Expand Down

0 comments on commit 4ebf818

Please sign in to comment.