mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: connected component with undefined, null and string props
This commit is contained in:
committed by
Géry Debongnie
parent
85eb30626d
commit
9f77344c3a
+1
-1
@@ -290,7 +290,7 @@ export function connect(mapStateToProps, options: any = {}) {
|
||||
let areKeyObservable = false;
|
||||
for (let key in storeProps) {
|
||||
areKeyObservable =
|
||||
areKeyObservable || "__owl__" in storeProps[key];
|
||||
areKeyObservable || (storeProps[key] && typeof (storeProps[key]) === "object" && "__owl__" in storeProps[key]);
|
||||
}
|
||||
if (areKeyObservable) {
|
||||
hashFunction = function({ storeProps }) {
|
||||
|
||||
@@ -736,4 +736,58 @@ describe("connecting a component to store", () => {
|
||||
await app.updateState({ beerId: 2 });
|
||||
expect(fixture.innerHTML).toBe("<div><span>kwak</span></div>");
|
||||
});
|
||||
|
||||
test("connected component with undefined, null and string props", async () => {
|
||||
class Beer extends Component<any, any, any> {
|
||||
inlineTemplate = `<div>
|
||||
<span>taster:<t t-esc="props.taster"/></span>
|
||||
<span t-if="props.selected">selected:<t t-esc="props.selected.name"/></span>
|
||||
<span t-if="props.consumed">consumed:<t t-esc="props.consumed.name"/></span>
|
||||
</div>`;
|
||||
}
|
||||
const ConnectedBeer = connect((state, props) => {
|
||||
return {
|
||||
selected: state.beers[props.id],
|
||||
consumed: state.beers[state.consumedID] || null,
|
||||
taster: state.taster,
|
||||
};
|
||||
})(Beer);
|
||||
|
||||
class App extends Component<any, any, any> {
|
||||
inlineTemplate = `<div>
|
||||
<t t-widget="ConnectedBeer" t-props="{id: state.beerId}"/>
|
||||
</div>`;
|
||||
widgets = { ConnectedBeer };
|
||||
state = { beerId: 0 };
|
||||
}
|
||||
|
||||
const mutations = {
|
||||
consume({ state }, beerId) {
|
||||
state.consumedID = beerId;
|
||||
}
|
||||
};
|
||||
const state = {
|
||||
beers: {
|
||||
1: { name: "jupiler" }
|
||||
},
|
||||
consumedID: null,
|
||||
taster: "aaron"
|
||||
};
|
||||
const store = new Store({ state, mutations });
|
||||
(<any>env).store = store;
|
||||
const app = new App(env);
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span></div></div>");
|
||||
|
||||
await app.updateState({ beerId: 1 });
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span><span>selected:jupiler</span></div></div>");
|
||||
|
||||
store.commit('consume', 1);
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span><span>selected:jupiler</span><span>consumed:jupiler</span></div></div>");
|
||||
|
||||
await app.updateState({ beerId: 0 });
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span><span>consumed:jupiler</span></div></div>");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user