Skip to content

Commit 20e5b33

Browse files
committed
support for EventTarget; closes #8
1 parent 8d22a79 commit 20e5b33

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/intercept.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export default function intercept<V>(value: V, key: string, interceptCallback: (
66
const mapMutatingMethods = ['clear', 'delete', 'set']
77
const setMutatingMethods = ['add', 'clear', 'delete']
88
const functionMutatingMethods: string[] = []
9+
const eventTargetMutatingMethods = ['dispatchEvent']
910
const mutatingMethods = new Map()
1011
mutatingMethods.set(Array, arrayMutatingMethods)
1112
mutatingMethods.set({}.constructor, objectMutatingMethods)
1213
mutatingMethods.set(Map, mapMutatingMethods)
1314
mutatingMethods.set(Set, setMutatingMethods)
1415
mutatingMethods.set(Function, functionMutatingMethods)
16+
mutatingMethods.set(EventTarget, eventTargetMutatingMethods)
1517

1618
const registeredClasses = Array.from(registeredClassesMap.values())
1719

src/serialize.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export function serialize(value: any): any | void {
5757
.map(([key, value]) => [key, serialize(value)])
5858
)
5959
}
60+
} else if (value instanceof EventTarget) {
61+
return {
62+
$$iposType: 'EventTarget',
63+
}
6064
} else if (!deSerialize.has(value.constructor) && isNativeObject(value)) {
6165
throw new Error(`Could not serialise: \`${value.constructor.name}\`.`)
6266
} else {
@@ -103,6 +107,8 @@ export function deserialize(value: string | number | Array<any> | { $$iposType?:
103107
Array.from(Object.entries(value.data))
104108
.map(deserialize)
105109
)
110+
} else if (value.$$iposType === 'EventTarget') {
111+
return new EventTarget()
106112
} else if (classes.has(value.$$iposType)) {
107113
const constructor = classes.get(value.$$iposType) as Function
108114
const deserializeMethod = deSerialize.get(constructor)?.deserialize ??

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"lib": ["ESNext"],
3+
"lib": ["ESNext", "dom"],
44
"module": "esnext",
55
"target": "esnext",
66
"moduleResolution": "node",

0 commit comments

Comments
 (0)