DEV: Use scheduleOnce correctly (#8865)

* DEV: Use scheduleOnce correctly

* remove jquery usage here
This commit is contained in:
Osama Sayegh 2020-02-05 21:21:00 +03:00 committed by GitHub
parent 926d5f1c0a
commit 6f52bbefb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 27 deletions

View File

@ -10,34 +10,13 @@ export default class ComponentConnector {
}
init() {
const $elem = $(
'<div style="display: inline-flex;" class="widget-component-connector"></div>'
);
const elem = $elem[0];
const { opts, widget, componentName } = this;
const elem = document.createElement("div");
elem.style.display = "inline-flex";
elem.className = "widget-component-connector";
this.elem = elem;
scheduleOnce("afterRender", this, this.connectComponent);
scheduleOnce("afterRender", this, () => {
const mounted = widget._findView();
const view = widget.register
.lookupFactory(`component:${componentName}`)
.create(opts);
if (setOwner) {
setOwner(view, getOwner(mounted));
}
// component connector is not triggering didReceiveAttrs
// we force it for selectKit components
if (view.selectKit) {
view.didReceiveAttrs();
}
mounted._connected.push(view);
view.renderer.appendTo(view, $elem[0]);
});
return elem;
return this.elem;
}
update(prev) {
@ -56,6 +35,27 @@ export default class ComponentConnector {
return null;
}
connectComponent() {
const { elem, opts, widget, componentName } = this;
const mounted = widget._findView();
const view = widget.register
.lookupFactory(`component:${componentName}`)
.create(opts);
if (setOwner) {
setOwner(view, getOwner(mounted));
}
// component connector is not triggering didReceiveAttrs
// we force it for selectKit components
if (view.selectKit) {
view.didReceiveAttrs();
}
mounted._connected.push(view);
view.renderer.appendTo(view, elem);
}
}
ComponentConnector.prototype.type = "Widget";