From 8540c39c3143a928c3f916920778a8c408b0b30c Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Mon, 10 Feb 2025 17:58:02 -0500 Subject: [PATCH] moving watch to its own file --- index.js | 21 +-------------------- package.json | 12 ++++++++++++ watch.js | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 package.json create mode 100644 watch.js diff --git a/index.js b/index.js index 7892f3a..65e5dab 100644 --- a/index.js +++ b/index.js @@ -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( { diff --git a/package.json b/package.json new file mode 100644 index 0000000..a9c0a4c --- /dev/null +++ b/package.json @@ -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": "" +} diff --git a/watch.js b/watch.js new file mode 100644 index 0000000..fc57fe1 --- /dev/null +++ b/watch.js @@ -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