Skip to content

Commit

Permalink
15549487: Remove _initialize methods from Widget2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohanBriglia committed Mar 21, 2024
1 parent f27e703 commit 9beecd0
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/Widget2.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 9beecd0

Please sign in to comment.