mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: properly handle null values
This commit is contained in:
@@ -202,6 +202,10 @@ export function makeObserver(): Observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function observe(value: any) {
|
function observe(value: any) {
|
||||||
|
if (value === null) {
|
||||||
|
// fun fact: typeof null === 'object'
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (typeof value !== "object") {
|
if (typeof value !== "object") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,25 @@ describe("observer", () => {
|
|||||||
expect(ob2.__rev__).toBe(2);
|
expect(ob2.__rev__).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("properly handle null or undefined", () => {
|
||||||
|
const observer = makeObserver();
|
||||||
|
const obj: any = { a: null, b: undefined };
|
||||||
|
|
||||||
|
observer.observe(obj);
|
||||||
|
expect(obj.__rev__).toBe(0);
|
||||||
|
expect(observer.__rev__).toBe(0);
|
||||||
|
|
||||||
|
obj.a = 3;
|
||||||
|
expect(obj.__rev__).toBe(1);
|
||||||
|
|
||||||
|
obj.b = 5;
|
||||||
|
expect(obj.__rev__).toBe(2);
|
||||||
|
|
||||||
|
obj.a = null;
|
||||||
|
obj.b = undefined;
|
||||||
|
expect(obj.__rev__).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
test("can change values in array", () => {
|
test("can change values in array", () => {
|
||||||
const observer = makeObserver();
|
const observer = makeObserver();
|
||||||
const obj: any = { arr: [1, 2] };
|
const obj: any = { arr: [1, 2] };
|
||||||
|
|||||||
Reference in New Issue
Block a user