From 9beecd0d60f4caca353eaecccebfa5d770e571ad Mon Sep 17 00:00:00 2001 From: Johan Briglia Date: Thu, 21 Mar 2024 11:48:39 +0100 Subject: [PATCH] 15549487: Remove _initialize methods from Widget2 It is a good practice to prefer composition over inheritance. And since we don't make widgets inheriting from other widgets anymore, we don't have to separate the initialization of instance variables and the initialization of subwidgets. This is removing _initialize and _initializeSubwidgets in favor of always using the object constructor instead. --- src/Widget2.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/Widget2.js b/src/Widget2.js index 5b18ec4..143ab4f 100644 --- a/src/Widget2.js +++ b/src/Widget2.js @@ -12,17 +12,17 @@ import { newId } from "./idGenerator.js"; * @example * * class TitleWidget extends Widget { - * _initialize(spec) { - * this._title = spec.title || "Hello World"; + * constructor({ title }) { + * this._title = title || "Hello World"; * } * * renderContentOn(html) { - * html.h1(title); + * html.h1(this._title); * } * * }; * - * let helloWorldWidget = new TitleWidget({title: "Hello Widget!"}); + * let helloWorldWidget = new TitleWidget({ title: "Hello Widget!" }); * * $(document).ready(() => { * helloWorldWidget.appendTo("BODY"); @@ -79,24 +79,8 @@ export default class Widget2 { this._getParameters = this._router.getParameters; this._getParameter = this._router.getParameter; this._setParameters = this._router.setParameters; - - this._initialize(...arguments); - this._initializeSubwidgets(...arguments); } - /** - * Hook evaluated at the beginning of initialization. Always - * implement initialization code in overrides of this method (or - * of `_initializeSubwidgets()`). In particular, don't override - * `constructor()`. - */ - _initialize(_spec) {} - - /** - * Hook evaluated at the end of initialization. - */ - _initializeSubwidgets(_spec) {} - // // Public //