This commit is contained in:
Géry Debongnie
2019-10-29 16:18:30 +01:00
committed by Lucas Perais (lpe)
parent 0931a4dc5b
commit f6634df72c
2 changed files with 19 additions and 0 deletions
+8
View File
@@ -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;
}
+11
View File
@@ -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);
});
});