From 9f5e34c5987d3023ee843456f4f4e9cf1391d154 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Fri, 14 May 2021 17:03:43 -0400 Subject: [PATCH 1/2] feat(ClassHierarchy): hierarchy subclasses Array --- Sources/Common/Core/ClassHierarchy/index.js | 7 +++++++ Sources/macro.js | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Sources/Common/Core/ClassHierarchy/index.js 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; From c64e70ba476e7f482eb2ec48e605dad0a1380a8e Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Fri, 14 May 2021 17:05:19 -0400 Subject: [PATCH 2/2] fix(AbstractWidgetFactory): Fix view widget model Widgets should not take on the WidgetFactory's model. Instead, explicitly specify what members we want from the factory object. This avoids populating widgetModel.classHierarchy with unnecessary classes. --- Sources/Widgets/Core/AbstractWidgetFactory/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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,