parent
76778071c9
commit
a5c1a735e1
@ -1,9 +1,23 @@
|
|||||||
const watch = (value, callback)=>{
|
const watch = (target, callback)=>{
|
||||||
return new Proxy(value, { set: 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) => {
|
const state = watch(
|
||||||
|
{
|
||||||
|
name: 'matt',
|
||||||
|
friend: {
|
||||||
|
name: 'bob'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(target, prop, newValue) => {
|
||||||
console.log(newValue);
|
console.log(newValue);
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
state.name = 'Matthew'
|
//state.name = 'Matthew'
|
||||||
|
state.friend.name = 'Bilbo'
|
||||||
|
|||||||
Loading…
Reference in new issue