set values in watch

main
Matthew Huntington 11 months ago
parent a5c1a735e1
commit 7ac2232f39

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

Loading…
Cancel
Save