1+ import { classes as registeredClassesMap } from './serialize.js'
2+
13export default function intercept < V > ( value : V , key : string , interceptCallback : ( key : string , method : string , ...args : any ) => void ) : V {
24 const arrayMutatingMethods = [ 'copyWithin' , 'fill' , 'pop' , 'push' , 'reverse' , 'shift' , 'sort' , 'splice' , 'unshift' ]
35 const objectMutatingMethods : string [ ] = [ ]
@@ -11,12 +13,18 @@ export default function intercept<V>(value: V, key: string, interceptCallback: (
1113 mutatingMethods . set ( Set , setMutatingMethods )
1214 mutatingMethods . set ( Function , functionMutatingMethods )
1315
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 ) ) )
1519 return value
1620
1721 return new Proxy ( value , {
1822 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 ) ) ) {
2028 const method = Reflect . get ( target , name )
2129 return ( ...args : any ) => {
2230 interceptCallback ( key , name , ...args )
0 commit comments