Skip to content

Commit

Permalink
fix(provider): correct event handler binding for document updates and…
Browse files Browse the repository at this point in the history
… awareness
  • Loading branch information
RubaXa committed Oct 28, 2024
1 parent de38e44 commit e3c616c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/provider/src/HocuspocusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export class HocuspocusProvider extends EventEmitter {
this.emit('awarenessChange', { states: awarenessStatesToArray(this.awareness!.getStates()) })
})

this.document.on('update', this.documentUpdateHandler.bind(this))
this.awareness?.on('update', this.awarenessUpdateHandler.bind(this))
this.document.on('update', this.boundDocumentUpdateHandler)
this.awareness?.on('update', this.boundAwarenessUpdateHandler)
this.registerEventListeners()

if (
Expand All @@ -229,6 +229,9 @@ export class HocuspocusProvider extends EventEmitter {
this.configuration.websocketProvider.attach(this)
}

boundDocumentUpdateHandler = this.documentUpdateHandler.bind(this)
boundAwarenessUpdateHandler = this.awarenessUpdateHandler.bind(this)

Check failure on line 233 in packages/provider/src/HocuspocusProvider.ts

View workflow job for this annotation

GitHub Actions / lint (16)

Expected blank line between class members

boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)

boundPageHide = this.pageHide.bind(this)
Expand Down Expand Up @@ -490,11 +493,11 @@ export class HocuspocusProvider extends EventEmitter {

if (this.awareness) {
removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy')
this.awareness.off('update', this.awarenessUpdateHandler)
this.awareness.off('update', this.boundAwarenessUpdateHandler)
this.awareness.destroy()
}

this.document.off('update', this.documentUpdateHandler)
this.document.off('update', this.boundDocumentUpdateHandler)

this.removeAllListeners()

Expand Down

0 comments on commit e3c616c

Please sign in to comment.