Skip to content

Commit

Permalink
Fix global access in browsers (#178)
Browse files Browse the repository at this point in the history
global is only available on Node, use window on browsers instead.
  • Loading branch information
guyca authored Sep 21, 2024
1 parent 5e3b5a7 commit 3236a31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/react-obsidian/src/graph/registry/GraphRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Graph } from '../Graph';
import { Middleware } from './Middleware';
import GraphMiddlewareChain from './GraphMiddlewareChain';
import { ObtainLifecycleBoundGraphException } from './ObtainLifecycleBoundGraphException';
import { getGlobal } from '../../utils/getGlobal';

export class GraphRegistry {
private readonly constructorToInstance = new Map<Constructable<Graph>, Set<Graph>>();
Expand Down Expand Up @@ -151,7 +152,6 @@ export class GraphRegistry {
}
}

// @ts-ignore
global.graphRegistry = global.graphRegistry || new GraphRegistry();
// @ts-ignore
export default global.graphRegistry as GraphRegistry;
const globalObject = getGlobal();
globalObject.graphRegistry = globalObject.graphRegistry || new GraphRegistry();
export default globalObject.graphRegistry as GraphRegistry;
3 changes: 3 additions & 0 deletions packages/react-obsidian/src/utils/getGlobal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getGlobal(): any {
return typeof window !== 'undefined' ? window : global;
}

0 comments on commit 3236a31

Please sign in to comment.