diff --git a/Sources/Common/Core/ClassHierarchy/index.js b/Sources/Common/Core/ClassHierarchy/index.js new file mode 100644 index 00000000000..5e12212f1d4 --- /dev/null +++ b/Sources/Common/Core/ClassHierarchy/index.js @@ -0,0 +1,7 @@ +export default class ClassHierarchy extends Array { + push(...args) { + // no perf issue since args.length should be small + const newArgs = args.filter((arg) => !this.includes(arg)); + return super.push(...newArgs); + } +} diff --git a/Sources/macro.js b/Sources/macro.js index 222f3b9ab74..b10446e7b88 100644 --- a/Sources/macro.js +++ b/Sources/macro.js @@ -1,4 +1,5 @@ import vtk from './vtk'; +import ClassHierarchy from './Common/Core/ClassHierarchy'; let globalMTime = 0; @@ -214,7 +215,12 @@ export function obj(publicAPI = {}, model = {}) { if (!Number.isInteger(model.mtime)) { model.mtime = ++globalMTime; } - model.classHierarchy = ['vtkObject']; + + if (!('classHierarchy' in model)) { + model.classHierarchy = new ClassHierarchy('vtkObject'); + } else if (!(model.classHierarchy instanceof ClassHierarchy)) { + model.classHierarchy = ClassHierarchy.from(model.classHierarchy); + } function off(index) { callbacks[index] = null;