From 9f5e34c5987d3023ee843456f4f4e9cf1391d154 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Fri, 14 May 2021 17:03:43 -0400 Subject: [PATCH] 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;