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
Samuel Degueldre
parent
525029b682
commit
de584b01a8
+9
-8
@@ -20,6 +20,7 @@ export type Reactive<T extends Target = Target> = T & {
|
|||||||
type NonReactive<T extends Target = Target> = T & {
|
type NonReactive<T extends Target = Target> = T & {
|
||||||
[SKIP]: any;
|
[SKIP]: any;
|
||||||
};
|
};
|
||||||
|
const objectToString = Object.prototype.toString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a given value can be made into a reactive object.
|
* 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
|
* @returns whether the value can be made reactive
|
||||||
*/
|
*/
|
||||||
function canBeMadeReactive(value: any): boolean {
|
function canBeMadeReactive(value: any): boolean {
|
||||||
return (
|
if (typeof value !== "object") {
|
||||||
typeof value === "object" &&
|
return false;
|
||||||
value !== null &&
|
}
|
||||||
!(value instanceof Date) &&
|
// extract "RawType" from strings like "[object RawType]" => this lets us
|
||||||
!(value instanceof Promise) &&
|
// ignore many native objects such as Promise (whose toString is [object Promise])
|
||||||
!(value instanceof String) &&
|
// or Date ([object Date]).
|
||||||
!(value instanceof Number)
|
const rawType = objectToString.call(value).slice(8, -1);
|
||||||
);
|
return rawType === "Object" || rawType === "Array";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1093,6 +1093,19 @@ describe("Reactivity", () => {
|
|||||||
expect(n).toBe(1);
|
expect(n).toBe(1);
|
||||||
expect(state.k).toEqual({ n: 2 });
|
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", () => {
|
describe("markRaw", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user