mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] connected child components with custom hooks
This commit is contained in:
committed by
Géry Debongnie
parent
d6e61c2203
commit
e7a4ad99de
@@ -27,9 +27,11 @@ export function connect(mapStateToProps) {
|
|||||||
this.updateProps(nextProps, false);
|
this.updateProps(nextProps, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
super.mounted();
|
||||||
}
|
}
|
||||||
willUnmount() {
|
willUnmount() {
|
||||||
this.env.store.off("update", this);
|
this.env.store.off("update", this);
|
||||||
|
super.willUnmount();
|
||||||
}
|
}
|
||||||
updateProps(nextProps, forceUpdate) {
|
updateProps(nextProps, forceUpdate) {
|
||||||
nextProps = Object.assign(nextProps, this.__widget__.currentStoreProps);
|
nextProps = Object.assign(nextProps, this.__widget__.currentStoreProps);
|
||||||
|
|||||||
@@ -106,4 +106,52 @@ describe("connecting a component to store", () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toMatchSnapshot();
|
expect(fixture.innerHTML).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("connected child components with custom hooks", async () => {
|
||||||
|
let steps: any = [];
|
||||||
|
class Child extends Component<any, any, any> {
|
||||||
|
inlineTemplate = `<div/>`;
|
||||||
|
mounted() {
|
||||||
|
steps.push('child:mounted');
|
||||||
|
}
|
||||||
|
willUnmount() {
|
||||||
|
steps.push('child:willUnmount')
|
||||||
|
}
|
||||||
|
destroyed() {
|
||||||
|
steps.push('child:destroyed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ConnectedChild = connect(s => s)(Child);
|
||||||
|
|
||||||
|
class Parent extends Component<any, any, any> {
|
||||||
|
inlineTemplate = `
|
||||||
|
<div>
|
||||||
|
<t t-if="state.child" t-widget="ConnectedChild"/>
|
||||||
|
</div>`;
|
||||||
|
widgets = { ConnectedChild };
|
||||||
|
|
||||||
|
constructor(env: Env) {
|
||||||
|
super(env);
|
||||||
|
this.state = { child: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = new Store({ state: {} });
|
||||||
|
(<any>env).store = store;
|
||||||
|
const parent = new Parent(env);
|
||||||
|
|
||||||
|
await parent.mount(fixture);
|
||||||
|
expect(steps).toEqual([
|
||||||
|
'child:mounted',
|
||||||
|
]);
|
||||||
|
|
||||||
|
await parent.updateState({ child: false });
|
||||||
|
expect(steps).toEqual([
|
||||||
|
'child:mounted',
|
||||||
|
'child:willUnmount',
|
||||||
|
'child:destroyed',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user