mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
wip
This commit is contained in:
committed by
Lucas Perais (lpe)
parent
0931a4dc5b
commit
f6634df72c
@@ -29,6 +29,14 @@ export class Observer {
|
||||
// fun fact: typeof null === 'object'
|
||||
return value;
|
||||
}
|
||||
if (
|
||||
value instanceof Map ||
|
||||
value instanceof WeakMap ||
|
||||
value instanceof Set ||
|
||||
value instanceof WeakSet
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
let metadata = this.weakMap.get(value) || this._observe(value, parent);
|
||||
return metadata.proxy;
|
||||
}
|
||||
|
||||
@@ -429,4 +429,15 @@ describe("observer", () => {
|
||||
obj.a.push(2);
|
||||
}).toThrow('Observed state cannot be changed here! (key: "1", val: "2")');
|
||||
});
|
||||
|
||||
test("functions are not observed, but are properly bound", () => {
|
||||
const observer = new Observer();
|
||||
const obj: any = observer.observe({ m: new Map() });
|
||||
expect(observer.rev).toBe(1);
|
||||
obj.m.set("a", 1);
|
||||
expect(obj.m.get("a")).toBe(1);
|
||||
|
||||
// should be 2, but we do not support reactivity on maps/weakmaps/set/weakset
|
||||
expect(observer.rev).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user