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/Widgets/Core/AbstractWidgetFactory/index.js b/Sources/Widgets/Core/AbstractWidgetFactory/index.js index 959f6cb81d3..a2846747870 100644 --- a/Sources/Widgets/Core/AbstractWidgetFactory/index.js +++ b/Sources/Widgets/Core/AbstractWidgetFactory/index.js @@ -31,10 +31,15 @@ function vtkAbstractWidgetFactory(publicAPI, model) { camera, } = extractRenderingComponents(renderer); const widgetModel = {}; - const widgetPublicAPI = { + const widgetPublicAPI = {}; + + macro.obj(widgetPublicAPI, widgetModel); + Object.assign(widgetPublicAPI, { onWidgetChange: publicAPI.onWidgetChange, - }; - Object.assign(widgetModel, model, { + }); + Object.assign(widgetModel, { + widgetState: model.widgetState, + manipulator: model.manipulator, viewType, renderer, camera, 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;