@@ -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