Skip to content

Commit e40407b

Browse files
committed
Avoid 9.2 breaking change in Widget base class (#9814)
1 parent d69996c commit e40407b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

modules/core/src/lib/widget-manager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,11 @@ export class WidgetManager {
201201
widget.deck = this.deck;
202202

203203
// Create an attach the HTML root element
204-
widget.rootElement = widget.onCreateRootElement();
204+
widget.rootElement = widget._onAdd({deck: this.deck, viewId});
205205
if (widget.rootElement) {
206206
this._getContainer(viewId, placement).append(widget.rootElement);
207207
}
208208

209-
widget.onAdd?.({deck: this.deck, viewId});
210209
widget.updateHTML();
211210
}
212211

modules/core/src/lib/widget.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,14 @@ export abstract class Widget<
9090
}
9191
}
9292

93-
// WIDGET LIFECYCLE
94-
9593
// @note empty method calls have an overhead in V8 but it is very low, ~1ns
9694

9795
/**
98-
* Called to create the root DOM element for this widget
96+
* Common utility to create the root DOM element for this widget
9997
* Configures the top-level styles and adds basic class names for theming
100-
* @returns an optional UI element that should be appended to the Deck container
98+
* @returns an UI element that should be appended to the Deck container
10199
*/
102-
onCreateRootElement(): HTMLDivElement {
100+
protected onCreateRootElement(): HTMLDivElement {
103101
const CLASS_NAMES = [
104102
// Add class names for theming
105103
'deck-widget',
@@ -116,16 +114,25 @@ export abstract class Widget<
116114
return element;
117115
}
118116

117+
// WIDGET LIFECYCLE
118+
119119
/** Called to render HTML into the root element */
120120
abstract onRenderHTML(rootElement: HTMLElement): void;
121121

122-
/** Called after the widget is added to a Deck instance and the DOM rootElement has been created */
122+
/** Internal API called by Deck when the widget is first added to a Deck instance */
123+
_onAdd(params: {deck: Deck<any>; viewId: string | null}): HTMLDivElement {
124+
return this.onAdd(params) ?? this.onCreateRootElement();
125+
}
126+
127+
/** Overridable by subclass - called when the widget is first added to a Deck instance
128+
* @returns an optional UI element that should be appended to the Deck container
129+
*/
123130
onAdd(params: {
124131
/** The Deck instance that the widget is attached to */
125132
deck: Deck<any>;
126133
/** The id of the view that the widget is attached to */
127134
viewId: string | null;
128-
}) {}
135+
}): HTMLDivElement | void {}
129136

130137
/** Called when the widget is removed */
131138
onRemove(): void {}

0 commit comments

Comments
 (0)