mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: properly call patch on connected components
A previous refactoring broke it by adding a [] arguments to updateprops.
This commit is contained in:
+1
-1
@@ -332,7 +332,7 @@ export class Component<
|
|||||||
async _updateProps(
|
async _updateProps(
|
||||||
nextProps: Props,
|
nextProps: Props,
|
||||||
forceUpdate: boolean = false,
|
forceUpdate: boolean = false,
|
||||||
patchQueue: any[]
|
patchQueue?: any[]
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const shouldUpdate = forceUpdate || this.shouldUpdate(nextProps);
|
const shouldUpdate = forceUpdate || this.shouldUpdate(nextProps);
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
|
|||||||
+2
-2
@@ -212,10 +212,10 @@ export function connect(mapStateToProps, options: any = {}) {
|
|||||||
}
|
}
|
||||||
if (didChange) {
|
if (didChange) {
|
||||||
(<any>this.__owl__).currentStoreProps = storeProps;
|
(<any>this.__owl__).currentStoreProps = storeProps;
|
||||||
this._updateProps(ownProps, false, []);
|
this._updateProps(ownProps, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_updateProps(nextProps, forceUpdate, patchQueue: any[]) {
|
_updateProps(nextProps, forceUpdate, patchQueue?: any[]) {
|
||||||
if ((<any>this.__owl__).ownProps !== nextProps) {
|
if ((<any>this.__owl__).ownProps !== nextProps) {
|
||||||
(<any>this.__owl__).currentStoreProps = mapStateToProps(
|
(<any>this.__owl__).currentStoreProps = mapStateToProps(
|
||||||
this.env.store.state,
|
this.env.store.state,
|
||||||
|
|||||||
@@ -714,4 +714,39 @@ describe("connecting a component to store", () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
expect(steps).toEqual(["parent", "child", "parent", "child", "child"]);
|
expect(steps).toEqual(["parent", "child", "parent", "child", "child"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("connected component willpatch/patch hooks are called on store updates", async () => {
|
||||||
|
const steps: string[] = [];
|
||||||
|
class App extends Component<any, any, any> {
|
||||||
|
inlineTemplate = `<div><t t-esc="props.msg"/></div>`;
|
||||||
|
willPatch() {
|
||||||
|
steps.push("willpatch");
|
||||||
|
}
|
||||||
|
patched() {
|
||||||
|
steps.push("patched");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const ConnectedApp = connect(function(s) {
|
||||||
|
return { msg: s.msg };
|
||||||
|
})(App);
|
||||||
|
|
||||||
|
const state = { msg: "a" };
|
||||||
|
const mutations = {
|
||||||
|
setMsg({ state }, c) {
|
||||||
|
state.msg = c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const store = new Store({ state, mutations });
|
||||||
|
(<any>env).store = store;
|
||||||
|
const app = new ConnectedApp(env);
|
||||||
|
|
||||||
|
await app.mount(fixture);
|
||||||
|
expect(fixture.innerHTML).toBe("<div>a</div>");
|
||||||
|
|
||||||
|
store.commit("setMsg", "b");
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<div>b</div>");
|
||||||
|
expect(steps).toEqual(["willpatch", "patched"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user