Skip to content

Commit

Permalink
fix: Add globalThis to references of window
Browse files Browse the repository at this point in the history
- Also made small performance change in how URL-building functions work.
  • Loading branch information
webJose committed Feb 20, 2023
1 parent 3cffc61 commit 3bce5bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default class Builder implements IBuilder {
urlData.wsPropertyNames.forEach((value) => {
const obj = wjConfig[value];
if (isConfig(obj)) {
makeWsUrlFunctions(obj, urlData.routeValuesRegExp, window && window.location !== undefined);
makeWsUrlFunctions(obj, urlData.routeValuesRegExp, globalThis.window && globalThis.window.location !== undefined);
}
else {
throw new Error(`The level 1 property "${value}" is not a node value (object), but it was specified as being an object containing URL-building information.`);
Expand Down
4 changes: 2 additions & 2 deletions src/makeWsUrlFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function buildUrlImpl(
const rp = (this[rootPathFn] ?? noop)();
let url = `${rp}${(path ?? '')}`;
// Replace any replaceable route values.
if (routeRegex && routeRegex.test(url) && routeValuesFn) {
if (routeRegex && routeValuesFn && routeRegex.test(url)) {
url = url.replace(routeRegex, (m, g1) => encodeURIComponent((routeValuesFn ?? noop)(g1)));
}
// Add query string values, if provided.
Expand Down Expand Up @@ -71,7 +71,7 @@ function parentRootPath(this: IWsParent, isBrowser: boolean) {
// build a relative URL starting with the root path.
return this.rootPath ?? '';
}
return `${(this.scheme ?? 'http')}://${(this.host ?? window?.location?.hostname ?? '')}${(this.port ? `:${this.port}` : '')}${(this.rootPath ?? '')}`;
return `${(this.scheme ?? 'http')}://${(this.host ?? globalThis.window?.location?.hostname ?? '')}${(this.port ? `:${this.port}` : '')}${(this.rootPath ?? '')}`;
}

function pathRootPath(this: IWsPath, parent: IWsPath) {
Expand Down

0 comments on commit 3bce5bd

Please sign in to comment.