define attachChild method in component

This commit is contained in:
Géry Debongnie
2019-03-11 17:00:42 +01:00
parent 98fe440a84
commit 77e071f4eb
2 changed files with 18 additions and 3 deletions
+17
View File
@@ -121,6 +121,23 @@ export class Component<
// Public
//--------------------------------------------------------------------------
/**
* Attach a child widget to a given html element
*
* This is most of the time not necessary, since widgets should primarily be
* created/managed with the t-widget directive in a qweb template. However,
* for the cases where we need more control, this method will do what is
* necessary to make sure all the proper hooks are called (for example,
* mounted/willUnmount)
*
* Note that this method makes a few assumptions:
* - the child widget is indeed a child of the current widget
* - the target is inside the dom of the current widget (typically a ref)
*/
attachChild(child: Component<T, any, any>, target: HTMLElement) {
target.appendChild(child.el!);
child.__mount();
}
async mount(target: HTMLElement): Promise<void> {
const vnode = await this._start();
if (this.__widget__.isDestroyed) {
+1 -3
View File
@@ -53,9 +53,7 @@ export class Root extends Widget<Store, State> {
async applyController(controller: Controller) {
const widget = await controller.create(this);
if (widget) {
// to do: call some public method of widget instead...
(<HTMLElement>this.refs.content).appendChild(widget.el!);
widget.__mount();
this.attachChild(widget, <HTMLElement>this.refs.content);
widget.el!.classList.add("o_action_controller");
this.store.activateController(controller);
}