All files / Sources vtk.js

76.92% Statements 20/26
62.96% Branches 17/27
100% Functions 4/4
76.92% Lines 20/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60    1x   1x 9x       1565x 58x   1507x 534x   973x           973x 973x                   973x     973x 3752x         603x         973x 973x 964x   973x       320x       1x  
import globalThisShim from 'globalthis';
 
export const vtkGlobal = globalThisShim(); // returns native globalThis if compliant
 
const factoryMapping = {
  vtkObject: () => null,
};
 
export default function vtk(obj) {
  if (obj === null || obj === undefined) {
    return obj;
  }
  if (obj.isA) {
    return obj;
  }
  Iif (!obj.vtkClass) {
    if (vtkGlobal.console && vtkGlobal.console.error) {
      vtkGlobal.console.error('Invalid VTK object');
    }
    return null;
  }
  const constructor = factoryMapping[obj.vtkClass];
  Iif (!constructor) {
    if (vtkGlobal.console && vtkGlobal.console.error) {
      vtkGlobal.console.error(
        `No vtk class found for Object of type ${obj.vtkClass}`
      );
    }
    return null;
  }
 
  // Shallow copy object
  const model = { ...obj };
 
  // Convert into vtkObject any nested key
  Object.keys(model).forEach((keyName) => {
    if (
      model[keyName] &&
      typeof model[keyName] === 'object' &&
      model[keyName].vtkClass
    ) {
      model[keyName] = vtk(model[keyName]);
    }
  });
 
  // Return the root
  const newInst = constructor(model);
  if (newInst && newInst.modified) {
    newInst.modified();
  }
  return newInst;
}
 
function register(vtkClassName, constructor) {
  factoryMapping[vtkClassName] = constructor;
}
 
// Nest register method under the vtk function
vtk.register = register;