Skip to content

Commit

Permalink
Merge pull request Kitware#1984 from thewtex/globalThis
Browse files Browse the repository at this point in the history
fix(macro): global object to globalThis
  • Loading branch information
jourdain authored Jul 9, 2021
2 parents b1a9fe4 + a734528 commit 9962dd8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Sources/macro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vtk from './vtk';
import vtk, { vtkGlobal } from './vtk';
import ClassHierarchy from './Common/Core/ClassHierarchy';

let globalMTime = 0;
Expand Down Expand Up @@ -33,14 +33,14 @@ consoleMethods.forEach((methodName) => {
fakeConsole[methodName] = noOp;
});

global.console = console.hasOwnProperty('log') ? console : fakeConsole;
vtkGlobal.console = console.hasOwnProperty('log') ? console : fakeConsole;

const loggerFunctions = {
debug: noOp, // Don't print debug by default
error: global.console.error || noOp,
info: global.console.info || noOp,
log: global.console.log || noOp,
warn: global.console.warn || noOp,
error: vtkGlobal.console.error || noOp,
info: vtkGlobal.console.info || noOp,
log: vtkGlobal.console.log || noOp,
warn: vtkGlobal.console.warn || noOp,
};

export function setLoggerFunction(name, fn) {
Expand Down
12 changes: 8 additions & 4 deletions Sources/vtk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import globalThisShim from 'globalthis';

export const vtkGlobal = globalThisShim(); // returns native globalThis if compliant

const factoryMapping = {
vtkObject: () => null,
};
Expand All @@ -10,15 +14,15 @@ export default function vtk(obj) {
return obj;
}
if (!obj.vtkClass) {
if (global.console && global.console.error) {
global.console.error('Invalid VTK object');
if (vtkGlobal.console && vtkGlobal.console.error) {
vtkGlobal.console.error('Invalid VTK object');
}
return null;
}
const constructor = factoryMapping[obj.vtkClass];
if (!constructor) {
if (global.console && global.console.error) {
global.console.error(
if (vtkGlobal.console && vtkGlobal.console.error) {
vtkGlobal.console.error(
`No vtk class found for Object of type ${obj.vtkClass}`
);
}
Expand Down
5 changes: 1 addition & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"commander": "6.2.1",
"d3-scale": "3.2.4",
"gl-matrix": "3.3.0",
"globalthis": "^1.0.2",
"jszip": "3.2.0",
"pako": "2.0.3",
"seedrandom": "3.0.5",
Expand Down

0 comments on commit 9962dd8

Please sign in to comment.