import Dep from './deps' ; import { isArray , isObject } from '../utils/typeOf' ; export function reactive < T > ( target ) { const depMap = new Map ( ) ; function proxy < T > ( obj ) { return new Proxy ( obj , { get ( target , key , receiver ) { const res = Reflect . get ( target , key , receiver ) ; if ( ! depMap . has ( key ) ) { depMap . set ( key , new Dep ( ) ) ; } if ( Dep . target ) depMap . get ( key ) . depend ( ) ; if ( isObject ( target [ key ] ) || isArray ( target [ key ] ) ) { return proxy ( res ) ; } return res ; } , set ( target , key , value , receiver ) { if ( target [ key ] !== value ) { depMap . get ( key ) ?. notify ( ) ; } return Reflect . set ( target , key , value , receiver ) ; } , } ) ; } return proxy ( target ) ; }