mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: prevent crash when selector returns null
Because `typeof null === 'object'`.
This commit is contained in:
committed by
Géry Debongnie
parent
c8d9c0b50e
commit
bc2c7edff4
+1
-1
@@ -132,7 +132,7 @@ export function useStore(selector, options: SelectorOptions = {}): any {
|
|||||||
__destroy.call(component, parent);
|
__destroy.call(component, parent);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof result !== "object") {
|
if (typeof result !== "object" || result === null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return new Proxy(result, {
|
return new Proxy(result, {
|
||||||
|
|||||||
@@ -49,10 +49,13 @@ describe("connecting a component to store", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("useStore can observe primitive types and call onUpdate", async () => {
|
test("useStore can observe primitive types and call onUpdate", async () => {
|
||||||
const state = { isBoolean: false };
|
const state = { isBoolean: false, nullValue: null };
|
||||||
const actions = {
|
const actions = {
|
||||||
setTrue({ state }) {
|
setTrue({ state }) {
|
||||||
state.isBoolean = true;
|
state.isBoolean = true;
|
||||||
|
},
|
||||||
|
setNotNull({ state }) {
|
||||||
|
state.nullValue = "ok";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const store = new Store({ state, actions });
|
const store = new Store({ state, actions });
|
||||||
@@ -61,8 +64,10 @@ describe("connecting a component to store", () => {
|
|||||||
static template = xml`
|
static template = xml`
|
||||||
<div>
|
<div>
|
||||||
<span t-if="isBoolean">ok</span>
|
<span t-if="isBoolean">ok</span>
|
||||||
|
<span t-if="nullValue !== null">not null</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
isBoolean: boolean;
|
isBoolean: boolean;
|
||||||
|
nullValue: string;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.isBoolean = useStore(state => state.isBoolean, {
|
this.isBoolean = useStore(state => state.isBoolean, {
|
||||||
@@ -70,6 +75,11 @@ describe("connecting a component to store", () => {
|
|||||||
this.isBoolean = isBoolean;
|
this.isBoolean = isBoolean;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.nullValue = useStore(state => state.nullValue, {
|
||||||
|
onUpdate: nullValue => {
|
||||||
|
this.nullValue = nullValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +92,10 @@ describe("connecting a component to store", () => {
|
|||||||
store.dispatch("setTrue");
|
store.dispatch("setTrue");
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(fixture.innerHTML).toBe("<div><span>ok</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>ok</span></div>");
|
||||||
|
|
||||||
|
store.dispatch("setNotNull");
|
||||||
|
await nextTick();
|
||||||
|
expect(fixture.innerHTML).toBe("<div><span>ok</span><span>not null</span></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("map works on the result of useStore when the resulting array changes for a bigger one", async () => {
|
test("map works on the result of useStore when the resulting array changes for a bigger one", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user