1
+ import { classes as registeredClassesMap } from './serialize.js'
2
+
1
3
export default function intercept < V > ( value : V , key : string , interceptCallback : ( key : string , method : string , ...args : any ) => void ) : V {
2
4
const arrayMutatingMethods = [ 'copyWithin' , 'fill' , 'pop' , 'push' , 'reverse' , 'shift' , 'sort' , 'splice' , 'unshift' ]
3
5
const objectMutatingMethods : string [ ] = [ ]
@@ -11,12 +13,18 @@ export default function intercept<V>(value: V, key: string, interceptCallback: (
11
13
mutatingMethods . set ( Set , setMutatingMethods )
12
14
mutatingMethods . set ( Function , functionMutatingMethods )
13
15
14
- if ( ! value || typeof value !== 'object' || ! mutatingMethods . has ( value . constructor ) )
16
+ const registeredClasses = Array . from ( registeredClassesMap . values ( ) )
17
+
18
+ if ( ! value || typeof value !== 'object' || ! ( mutatingMethods . has ( value . constructor ) || registeredClasses . includes ( value . constructor ) ) )
15
19
return value
16
20
17
21
return new Proxy ( value , {
18
22
get ( target , name : string ) {
19
- if ( Reflect . has ( target , name ) && mutatingMethods . get ( value . constructor ) . includes ( name ) ) {
23
+ if ( name === '__proxy' )
24
+ return true
25
+ if ( name === '__original' )
26
+ return value
27
+ if ( Reflect . has ( target , name ) && ( mutatingMethods . get ( value . constructor ) ?. includes ( name ) || registeredClasses . includes ( value . constructor ) ) ) {
20
28
const method = Reflect . get ( target , name )
21
29
return ( ...args : any ) => {
22
30
interceptCallback ( key , name , ...args )
0 commit comments