Skip to content

Commit 8925478

Browse files
committed
refactor(fullscreenrenderwindow, macro): refactor on fullscreenrenderwindow constructor
Refactor of fullscreenrenderwindow constructor so that the setXXX() methods of correesponding properties are called when the fullScreenRenderWindow is instanciated (calling newInstance). In the macro.js newInstance() method, the set() method is called in order that the setXXX() methods for each entry of initial values is called if such methods exist. This is in order that side effects of setters are taken into account when creating new objects and avoid having custom handling in extend methods. BREAKING CHANGE: In the extend method in fullScreenRenderWindow, the parameter initialValues is not asked anymore. When extending this class, only default parameters defined in the fullScreenRenderWindow will be passed.
1 parent 7d2388c commit 8925478

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Sources/Rendering/Misc/FullScreenRenderWindow/index.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ function vtkFullScreenRenderWindow(publicAPI, model) {
9494
model.interactor.initialize();
9595
model.interactor.bindEvents(model.container);
9696

97+
const superClass = { ...publicAPI };
98+
9799
// Expose background
98-
publicAPI.setBackground = model.renderer.setBackground;
100+
publicAPI.setBackground = (background) => {
101+
// Synchronize the setting of background from here to renderer
102+
model.renderer.setBackground(background);
103+
superClass.setBackground(background);
104+
};
99105

100106
publicAPI.removeController = () => {
101107
const el = model.controlContainer;
@@ -188,19 +194,22 @@ function vtkFullScreenRenderWindow(publicAPI, model) {
188194
// Object factory
189195
// ----------------------------------------------------------------------------
190196

191-
const DEFAULT_VALUES = {
192-
background: [0.32, 0.34, 0.43],
193-
containerStyle: null,
194-
controlPanelStyle: null,
195-
listenWindowResize: true,
196-
resizeCallback: null,
197-
controllerVisibility: true,
198-
};
197+
function defaultValues(initialValues) {
198+
return {
199+
...initialValues,
200+
background: [0.32, 0.34, 0.43],
201+
containerStyle: null,
202+
controlPanelStyle: null,
203+
listenWindowResize: true,
204+
resizeCallback: null,
205+
controllerVisibility: true,
206+
};
207+
}
199208

200209
// ----------------------------------------------------------------------------
201210

202211
export function extend(publicAPI, model, initialValues = {}) {
203-
Object.assign(model, DEFAULT_VALUES, initialValues);
212+
Object.assign(model, defaultValues(initialValues));
204213

205214
// Object methods
206215
macro.obj(publicAPI, model);
@@ -213,7 +222,7 @@ export function extend(publicAPI, model, initialValues = {}) {
213222
'container',
214223
'controlContainer',
215224
]);
216-
225+
macro.setArray(publicAPI, model, ['background'], 3, 1.0);
217226
// Object specific methods
218227
vtkFullScreenRenderWindow(publicAPI, model);
219228
}

Sources/macros.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ export function newInstance(extend, className) {
972972
const model = {};
973973
const publicAPI = {};
974974
extend(publicAPI, model, initialValues);
975+
publicAPI.set(initialValues);
975976

976977
return Object.freeze(publicAPI);
977978
};

0 commit comments

Comments
 (0)