diff --git a/index.js b/index.js index d2c905f..1121023 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,23 @@ -const watch = (value, callback)=>{ - return new Proxy(value, { set: callback }) +const watch = (target, callback)=>{ + for(const key in target){ + if(typeof target[key] === 'object'){ + target[key] = watch(target[key], callback) + } + } + return new Proxy(target, { set: callback }) } -const state = watch({ name: 'matt' }, (newValue) => { - console.log(newValue); -}) +const state = watch( + { + name: 'matt', + friend: { + name: 'bob' + } + }, + (target, prop, newValue) => { + console.log(newValue); + } +) -state.name = 'Matthew' +//state.name = 'Matthew' +state.friend.name = 'Bilbo'