From 7f0b236747229fbdab44386b613b886c5b2e2aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 7 May 2019 14:33:01 +0200 Subject: [PATCH] [FIX] store: properly call patch on connected components A previous refactoring broke it by adding a [] arguments to updateprops. --- src/component.ts | 2 +- src/store.ts | 4 ++-- tests/store.test.ts | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/component.ts b/src/component.ts index d93a5cf7..a5c2be24 100644 --- a/src/component.ts +++ b/src/component.ts @@ -332,7 +332,7 @@ export class Component< async _updateProps( nextProps: Props, forceUpdate: boolean = false, - patchQueue: any[] + patchQueue?: any[] ): Promise { const shouldUpdate = forceUpdate || this.shouldUpdate(nextProps); if (shouldUpdate) { diff --git a/src/store.ts b/src/store.ts index 73e5603a..7f187d98 100644 --- a/src/store.ts +++ b/src/store.ts @@ -212,10 +212,10 @@ export function connect(mapStateToProps, options: any = {}) { } if (didChange) { (this.__owl__).currentStoreProps = storeProps; - this._updateProps(ownProps, false, []); + this._updateProps(ownProps, false); } } - _updateProps(nextProps, forceUpdate, patchQueue: any[]) { + _updateProps(nextProps, forceUpdate, patchQueue?: any[]) { if ((this.__owl__).ownProps !== nextProps) { (this.__owl__).currentStoreProps = mapStateToProps( this.env.store.state, diff --git a/tests/store.test.ts b/tests/store.test.ts index 49cb54d7..cdaaec00 100644 --- a/tests/store.test.ts +++ b/tests/store.test.ts @@ -714,4 +714,39 @@ describe("connecting a component to store", () => { await nextTick(); 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 { + inlineTemplate = `
`; + 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 }); + (env).store = store; + const app = new ConnectedApp(env); + + await app.mount(fixture); + expect(fixture.innerHTML).toBe("
a
"); + + store.commit("setMsg", "b"); + await nextTick(); + expect(fixture.innerHTML).toBe("
b
"); + expect(steps).toEqual(["willpatch", "patched"]); + }); });