Skip to content

Instantly share code, notes, and snippets.

@jherr
Created September 22, 2023 21:54
Show Gist options
  • Save jherr/b21f81b6a7a8cfa6a1bf60cdd9f1c638 to your computer and use it in GitHub Desktop.
Save jherr/b21f81b6a7a8cfa6a1bf60cdd9f1c638 to your computer and use it in GitHub Desktop.
runify.js
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