watch works with arrays

main
Matthew Huntington 11 months ago
parent 7ac2232f39
commit 0c1f801971

@ -9,7 +9,11 @@ const watch = (target, callback)=>{
{ {
set: (target, prop, newValue) => { set: (target, prop, newValue) => {
target[prop] = newValue target[prop] = newValue
if(Array.isArray(target) && prop === 'length'){
return true
}
callback() callback()
return true
} }
} }
) )
@ -20,13 +24,16 @@ const state = watch(
name: 'matt', name: 'matt',
friend: { friend: {
name: 'bob' name: 'bob'
} },
stuff: ['bag', 123, true]
}, },
() => { () => {
console.log(state); console.log(state);
} }
) )
//state.name = 'Matthew' console.log(state);
state.friend.name = 'Bilbo'
state.name = 'Matthew' state.name = 'Matthew'
state.friend.name = 'Bilbo'
state.stuff[0] = 'fun'
state.stuff.push('weeee')

Loading…
Cancel
Save