From 76778071c90501f76df781cdc3d04a32ecf96049 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Sat, 8 Feb 2025 11:50:49 -0500 Subject: [PATCH] setting up watch func for state --- index.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 9141146..d2c905f 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,9 @@ -const state = new Proxy( - { - fun:true - }, - { - set: (target, prop, value) => { - console.log(`Property ${prop} changed from ${target[prop]} to ${value}`); - target[prop] = value - } - } -) +const watch = (value, callback)=>{ + return new Proxy(value, { set: callback }) +} -console.log(state); -state.fun = false -console.log(state); +const state = watch({ name: 'matt' }, (newValue) => { + console.log(newValue); +}) + +state.name = 'Matthew'