mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: fix lifecycle order
This commit is contained in:
committed by
Samuel Degueldre
parent
9e285e1e0a
commit
fb6aab8b70
@@ -17,7 +17,7 @@ export function onWillUpdateProps(fn: (nextProps: any) => Promise<void> | void |
|
||||
|
||||
export function onMounted(fn: () => void | any) {
|
||||
const node = getCurrent()!;
|
||||
node.mounted.unshift(fn);
|
||||
node.mounted.push(fn);
|
||||
}
|
||||
|
||||
export function onWillPatch(fn: () => Promise<void> | any | void) {
|
||||
@@ -32,7 +32,7 @@ export function onPatched(fn: () => void | any) {
|
||||
|
||||
export function onWillUnmount(fn: () => Promise<void> | void | any) {
|
||||
const node = getCurrent()!;
|
||||
node.willUnmount.push(fn);
|
||||
node.willUnmount.unshift(fn);
|
||||
}
|
||||
|
||||
export function onDestroyed(fn: () => Promise<void> | void | any) {
|
||||
|
||||
@@ -96,10 +96,10 @@ describe("hooks", () => {
|
||||
await app.mount(fixture);
|
||||
app.destroy();
|
||||
expect(steps).toEqual([
|
||||
"hook:mounted2",
|
||||
"hook:mounted1",
|
||||
"hook:willUnmount1",
|
||||
"hook:mounted2",
|
||||
"hook:willUnmount2",
|
||||
"hook:willUnmount1",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -939,37 +939,6 @@ describe("lifecycle hooks", () => {
|
||||
expect(created).toBe(true);
|
||||
});
|
||||
|
||||
test.skip("two different call to mounted/willunmount should work", async () => {
|
||||
/*const steps: string[] = [];
|
||||
function useMyHook(i) {
|
||||
onMounted(() => {
|
||||
steps.push("hook:mounted" + i);
|
||||
});
|
||||
onWillUnmount(() => {
|
||||
steps.push("hook:willunmount" + i);
|
||||
});
|
||||
}
|
||||
class MyComponent extends Component {
|
||||
static template = xml`<div>hey</div>`;
|
||||
constructor() {
|
||||
super();
|
||||
useMyHook(1);
|
||||
useMyHook(2);
|
||||
}
|
||||
}
|
||||
const component = new MyComponent();
|
||||
await component.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>hey</div>");
|
||||
component.unmount();
|
||||
expect(fixture.innerHTML).toBe("");
|
||||
expect(steps).toEqual([
|
||||
"hook:mounted1",
|
||||
"hook:mounted2",
|
||||
"hook:willunmount2",
|
||||
"hook:willunmount1",
|
||||
]);*/
|
||||
});
|
||||
|
||||
// TODO: rename (corresponds to https://github.com/odoo/owl/blob/master/doc/reference/concurrency_model.md#semantics)
|
||||
test("component semantics", async () => {
|
||||
let steps: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user