-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove global window and localStorage dependecy #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ export default class LNC { | |
} | ||
|
||
private get wasm() { | ||
return window[this._namespace] as WasmGlobal; | ||
return globalThis[this._namespace] as WasmGlobal; | ||
} | ||
|
||
get isReady() { | ||
|
@@ -195,7 +195,11 @@ export default class LNC { | |
); | ||
|
||
// add an event listener to disconnect if the page is unloaded | ||
window.addEventListener('unload', this.wasm.wasmClientDisconnect); | ||
if (typeof window !== "undefined") { | ||
window.addEventListener('unload', this.wasm.wasmClientDisconnect); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we can add an eventListener only when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call on this one |
||
} else { | ||
log.info("No unload event listener added. window is not available"); | ||
} | ||
|
||
// repeatedly check if the connection was successful | ||
return new Promise<void>((resolve, reject) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually looks a bit dangerous because this could overwrite something. if
this._namespace
is already a defined property.