Skip to content

Commit

Permalink
SDK sync agent: Stop register view functions getting called twice (#474)
Browse files Browse the repository at this point in the history
When implemented in the browser, if we wait to register views until
after we’re connected we end up registering them twice.
  • Loading branch information
texuf authored Jul 26, 2024
1 parent 48387c4 commit 0161790
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/sdk/src/sync-agent/river-connection/riverConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class RiverConnection extends PersistedObservable<RiverConnectionModel> {
if (!urls) {
return
}
logger.log(`RiverConnection: setting rpcClient with urls: "${urls}"`)
logger.log(`setting rpcClient with urls: "${urls}"`)
const rpcClient = makeStreamRpcClient(urls, this.clientParams.rpcRetryParams, () =>
this.riverRegistryDapp.getOperationalNodeUrls(),
)
Expand All @@ -130,6 +130,13 @@ export class RiverConnection extends PersistedObservable<RiverConnectionModel> {
this.clientParams.highPriorityStreamIds,
)
this.client = client
// initialize views
this.store.withTransaction('RiverConnection::onNewClient', () => {
this.views.forEach((viewFn) => {
const onStopFn = viewFn(client)
this.onStoppedFns.push(onStopFn)
})
})
// try to log in
logger.log('attempting login after new client')
this.login().catch((err) => {
Expand Down Expand Up @@ -174,13 +181,6 @@ export class RiverConnection extends PersistedObservable<RiverConnectionModel> {
await client.initializeUser(this.newUserMetadata)
client.startSync()
this.setData({ userExists: true })
// initialize views
this.store.withTransaction('RiverConnection::login', () => {
this.views.forEach((viewFn) => {
const onStopFn = viewFn(client)
this.onStoppedFns.push(onStopFn)
})
})
this.authStatus.setValue(AuthStatus.ConnectedToRiver)
// New rpcClient is available, resolve all queued requests
this.clientQueue.flush(client)
Expand Down

0 comments on commit 0161790

Please sign in to comment.