moving watch to its own file

main
Matthew Huntington 11 months ago
parent 0c1f801971
commit 8540c39c31

@ -1,23 +1,4 @@
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: (target, prop, newValue) => {
target[prop] = newValue
if(Array.isArray(target) && prop === 'length'){
return true
}
callback()
return true
}
}
)
}
import watch from './watch.js'
const state = watch(
{

@ -0,0 +1,12 @@
{
"name": "framework",
"type":"module",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}

@ -0,0 +1,21 @@
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: (target, prop, newValue) => {
target[prop] = newValue
if(Array.isArray(target) && prop === 'length'){
return true
}
callback()
return true
}
}
)
}
export default watch
Loading…
Cancel
Save