|
|
|
|
@ -4,7 +4,15 @@ const watch = (target, callback)=>{
|
|
|
|
|
target[key] = watch(target[key], callback)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Proxy(target, { set: callback })
|
|
|
|
|
return new Proxy(
|
|
|
|
|
target,
|
|
|
|
|
{
|
|
|
|
|
set: (target, prop, newValue) => {
|
|
|
|
|
target[prop] = newValue
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const state = watch(
|
|
|
|
|
@ -14,10 +22,11 @@ const state = watch(
|
|
|
|
|
name: 'bob'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
(target, prop, newValue) => {
|
|
|
|
|
console.log(newValue);
|
|
|
|
|
() => {
|
|
|
|
|
console.log(state);
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//state.name = 'Matthew'
|
|
|
|
|
state.friend.name = 'Bilbo'
|
|
|
|
|
state.name = 'Matthew'
|
|
|
|
|
|