Created
September 22, 2023 21:54
-
-
Save jherr/b21f81b6a7a8cfa6a1bf60cdd9f1c638 to your computer and use it in GitHub Desktop.
runify.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function runify(obj) { | |
if(Array.isArray(obj)) { | |
return obj.map(runify); | |
} else if(typeof obj === 'object') { | |
let rune = $state(obj); | |
let output = {}; | |
for(let key in rune) { | |
if(typeof obj[key] === 'object') { | |
obj[key] = runify(obj[key]); | |
} | |
Object.defineProperty(output, key, { | |
get() { return rune[key]; }, | |
set(val) { | |
console.log('setting', key, val); | |
rune[key] = val; | |
}, | |
enumerable: true, | |
}); | |
} | |
return output; | |
} else { | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment