Skip to content

Commit

Permalink
Fix destory (#48)
Browse files Browse the repository at this point in the history
* Fix destory

* In case disconnect when the doc is not loaded
  • Loading branch information
ulion authored Jan 15, 2021
1 parent 24dca9a commit d141da4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/client/src/automerge-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export const AutomergeEditor = {
garbageCursor: (e: AutomergeEditor, docId: string) => {
const doc = e.docSet.getDoc(docId)

if (!doc) {
return
}

const changed = Automerge.change<SyncDoc>(doc, (d: any) => {
delete d.cursors
})
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/withSocketIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const withSocketIO = <T extends AutomergeEditor>(
*/

e.destroy = () => {
e.socket.removeListener('disconnect')

e.socket.close()

e.closeConnection()
Expand Down

0 comments on commit d141da4

Please sign in to comment.