Skip to content

Commit

Permalink
Merge pull request #27 from dginsburg/ready-race
Browse files Browse the repository at this point in the history
Fix race condition when setting up Strada components
  • Loading branch information
joemasilotti authored Mar 1, 2024
2 parents 0b4b6c0 + f25ad20 commit e2e8a7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Source/strada.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
class NativeBridge {
constructor() {
this.supportedComponents = []
document.addEventListener("web-bridge:ready", () => this.webBridge.setAdapter(this))
this.registerCalled = new Promise(resolve => this.registerResolver = resolve)
document.addEventListener("web-bridge:ready", async () => {
await this.setAdapter()
})
}

async setAdapter() {
await this.registerCalled
this.webBridge.setAdapter(this)
}

register(component) {
Expand All @@ -15,6 +23,7 @@
this.supportedComponents.push(component)
}

this.registerResolver()
this.notifyBridgeOfSupportedComponentsUpdate()
}

Expand Down

0 comments on commit e2e8a7c

Please sign in to comment.