[REF] web: remove useWidget compatibility helper
Now that the last Component using that helper have been fully converted to Owl (AceEditorWrapper -> ResourceEditor), we can remove it. Part of task~3439226 Part-of: odoo/odoo#139154
This commit is contained in:
@@ -1,16 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {
|
||||
App,
|
||||
Component,
|
||||
onMounted,
|
||||
onWillStart,
|
||||
onWillUnmount,
|
||||
useEnv,
|
||||
useRef,
|
||||
useState,
|
||||
xml,
|
||||
} from "@odoo/owl";
|
||||
import { App, Component, useState, xml } from "@odoo/owl";
|
||||
import { templates } from "@web/core/assets";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
@@ -41,26 +31,6 @@ export function createWidgetParent(env) {
|
||||
};
|
||||
}
|
||||
|
||||
export function useWidget(refName, widgetClass, params = []) {
|
||||
const ref = useRef(refName);
|
||||
const env = useEnv();
|
||||
|
||||
const parent = createWidgetParent(env);
|
||||
const widget = new widgetClass(parent, ...params);
|
||||
|
||||
onWillStart(() => {
|
||||
return widget._widgetRenderAndInsert(() => {});
|
||||
});
|
||||
onMounted(() => {
|
||||
ref.el.append(widget.el);
|
||||
});
|
||||
onWillUnmount(() => {
|
||||
widget.destroy();
|
||||
});
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
const rootTemplate = xml`<SubComp t-props="state"/>`;
|
||||
export async function attachComponent(parent, element, componentClass, props = {}) {
|
||||
class Root extends Component {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { attachComponent, useWidget } from "@web/legacy/utils";
|
||||
import { attachComponent } from "@web/legacy/utils";
|
||||
|
||||
import { makeTestEnv } from "@web/../tests/helpers/mock_env";
|
||||
import { getFixture, mount } from "@web/../tests/helpers/utils";
|
||||
import { getFixture } from "@web/../tests/helpers/utils";
|
||||
import Widget from "@web/legacy/js/core/widget";
|
||||
import {
|
||||
Component,
|
||||
@@ -13,75 +11,11 @@
|
||||
onWillDestroy,
|
||||
onWillStart,
|
||||
onWillUpdateProps,
|
||||
useRef,
|
||||
useState,
|
||||
xml,
|
||||
} from "@odoo/owl";
|
||||
import { nextTick } from "./helpers/test_utils";
|
||||
|
||||
QUnit.module("Owl Compatibility", function () {
|
||||
QUnit.test("useWidget", async (assert) => {
|
||||
assert.expect(9);
|
||||
|
||||
let widget = null;
|
||||
const CustomWidget = Widget.extend({
|
||||
init(_, ...params) {
|
||||
this._super(...arguments);
|
||||
widget = this;
|
||||
assert.step("widget initialized");
|
||||
assert.deepEqual(params, ["a", 1]);
|
||||
this.params = params;
|
||||
},
|
||||
start() {
|
||||
this.$el.text("Hello World!");
|
||||
},
|
||||
callTriggerUp() {
|
||||
this.call("test", "call", { [this.params[0]]: this.params[1] });
|
||||
},
|
||||
});
|
||||
|
||||
class ComponentAdapter extends Component {
|
||||
static template = xml`<div id="adapter" t-ref="container"/>`;
|
||||
setup() {
|
||||
this.containerRef = useRef("container");
|
||||
this.widget = useWidget("container", CustomWidget, ["a", 1]);
|
||||
assert.strictEqual(this.widget, widget);
|
||||
}
|
||||
}
|
||||
|
||||
class Toggle extends Component {
|
||||
static components = { ComponentAdapter };
|
||||
static template = xml`<ComponentAdapter t-if="state.active"/>`;
|
||||
state = useState({ active: true });
|
||||
}
|
||||
|
||||
const target = getFixture();
|
||||
registry.category("services").add("test", {
|
||||
start: () => ({
|
||||
call: (p) => {
|
||||
assert.step("triggered up");
|
||||
assert.deepEqual(p, { a: 1 });
|
||||
},
|
||||
}),
|
||||
});
|
||||
const component = await mount(Toggle, target, {
|
||||
env: await makeTestEnv(),
|
||||
});
|
||||
assert.verifySteps(["widget initialized"]);
|
||||
|
||||
assert.strictEqual(
|
||||
target.querySelector("#adapter").textContent,
|
||||
"Hello World!"
|
||||
);
|
||||
|
||||
widget.callTriggerUp();
|
||||
assert.verifySteps(["triggered up"]);
|
||||
|
||||
component.state.active = false;
|
||||
await nextTick();
|
||||
assert.ok(widget.isDestroyed());
|
||||
});
|
||||
|
||||
QUnit.test("attachComponent", async (assert) => {
|
||||
assert.expect(13);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user