parent
0c1f801971
commit
8540c39c31
@ -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…
Reference in new issue