Skip to content

Commit af7c325

Browse files
committed
chore: add datastorage init listener
1 parent e7c4fff commit af7c325

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

examples/gauge/Lib/navigraph.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ if (!config.clientId || config.clientId.includes("<")) {
1616

1717
initializeApp(config)
1818

19-
// Wait 1s before accessing datastorage
20-
// This is a potential workaround for the issue where datastorage does not deliver credentials on startup.
21-
const dataStoreInit = new Promise(resolve => setTimeout(resolve, 1000))
19+
// Wait for DataStorage ready event before initializing SDK
20+
const dataStoreInit = new Promise<void>(res => {
21+
const lis = RegisterViewListener("JS_LISTENER_DATASTORAGE", () => {
22+
res()
23+
lis.unregister()
24+
})
25+
})
2226

2327
const isNavigraphClient = config.clientId.includes("navigraph")
2428
const clientPrefix = isNavigraphClient ? "NG" : config.clientId.toUpperCase().replace("-", "_") + "_NG"

0 commit comments

Comments
 (0)