Skip to content

Commit 22f72b8

Browse files
committed
refactor(WebSocketPolyfill): cleanup redundant open handling
Remove return value from `syncService.open` and redundant handler in `WebSocketPolyfill`. `syncService.open` triggers `opened` and `loaded` events which both set the `version` and `session`. Signed-off-by: Max <[email protected]>
1 parent a6c13a0 commit 22f72b8

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

src/services/SyncService.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class SyncService {
106106

107107
async open({ fileId, initialSession }) {
108108
if (this.hasActiveConnection) {
109-
return this.connectionState
109+
return
110110
}
111111
const connect = initialSession
112112
? Promise.resolve(new Connection({ data: initialSession }, {}))
@@ -115,15 +115,13 @@ class SyncService {
115115
this.#connection = await connect
116116
if (!this.#connection) {
117117
// Error was already emitted in connect
118-
return null
118+
return
119119
}
120120
this.backend = new PollingBackend(this, this.#connection)
121121
this.version = this.#connection.docStateVersion
122122
this.baseVersionEtag = this.#connection.document.baseVersionEtag
123123
this.emit('opened', this.connectionState)
124124
this.emit('loaded', this.connectionState)
125-
126-
return this.connectionState
127125
}
128126

129127
startSync() {

src/services/WebSocketPolyfill.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
4040
this.#version = version
4141
this.#session = session
4242
},
43-
loaded: ({ version, session, content }) => {
44-
logger.debug('loaded ', { version, session })
45-
this.#version = version
46-
this.#session = session
47-
},
4843
sync: ({ steps, version }) => {
4944
logger.debug('synced ', { version, steps })
5045
this.#version = version
@@ -57,15 +52,7 @@ export default function initWebSocketPolyfill(syncService, fileId, initialSessio
5752
},
5853
})
5954

60-
syncService.open({ fileId, initialSession }).then((data) => {
61-
if (syncService.hasActiveConnection) {
62-
const { version, session } = data
63-
this.#version = version
64-
this.#session = session
65-
66-
this.onopen?.()
67-
}
68-
})
55+
syncService.open({ fileId, initialSession }).then(() => this.onopen?.())
6956
}
7057

7158
#registerHandlers(handlers) {

0 commit comments

Comments
 (0)