mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] reactivity: do not observe eventtarget and other stuff
This commit is contained in:
committed by
Aaron Bohy
parent
0a73154985
commit
d828f39a2d
+9
-8
@@ -20,6 +20,7 @@ export type Reactive<T extends Target = Target> = T & {
|
||||
type NonReactive<T extends Target = Target> = T & {
|
||||
[SKIP]: any;
|
||||
};
|
||||
const objectToString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Checks whether a given value can be made into a reactive object.
|
||||
@@ -28,14 +29,14 @@ type NonReactive<T extends Target = Target> = T & {
|
||||
* @returns whether the value can be made reactive
|
||||
*/
|
||||
function canBeMadeReactive(value: any): boolean {
|
||||
return (
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
!(value instanceof Date) &&
|
||||
!(value instanceof Promise) &&
|
||||
!(value instanceof String) &&
|
||||
!(value instanceof Number)
|
||||
);
|
||||
if (typeof value !== "object") {
|
||||
return false;
|
||||
}
|
||||
// extract "RawType" from strings like "[object RawType]" => this lets us
|
||||
// ignore many native objects such as Promise (whose toString is [object Promise])
|
||||
// or Date ([object Date]).
|
||||
const rawType = objectToString.call(value).slice(8, -1);
|
||||
return rawType === "Object" || rawType === "Array";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1093,6 +1093,19 @@ describe("Reactivity", () => {
|
||||
expect(n).toBe(1);
|
||||
expect(state.k).toEqual({ n: 2 });
|
||||
});
|
||||
|
||||
test("can add collections set/weakset/map/weakmap in a reactive object", () => {
|
||||
const rawSet = new Set();
|
||||
const rawWeakSet = new WeakSet();
|
||||
const rawMap = new Map();
|
||||
const rawWeakMap = new WeakMap();
|
||||
|
||||
const obj = reactive({ rawSet, rawWeakSet, rawMap, rawWeakMap });
|
||||
expect(obj.rawSet).toBe(rawSet);
|
||||
expect(obj.rawWeakSet).toBe(rawWeakSet);
|
||||
expect(obj.rawMap).toBe(rawMap);
|
||||
expect(obj.rawWeakMap).toBe(rawWeakMap);
|
||||
});
|
||||
});
|
||||
|
||||
describe("markRaw", () => {
|
||||
|
||||
Reference in New Issue
Block a user