Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Created September 9, 2017 18:23
Show Gist options
  • Save NoMan2000/edb0aa020768cf77420fb1f03902c00f to your computer and use it in GitHub Desktop.
Save NoMan2000/edb0aa020768cf77420fb1f03902c00f to your computer and use it in GitHub Desktop.
Converting a regular object to an observable
function convert (obj) {
Object.keys(obj).forEach(key => {
let internalValue = obj[key]
Object.defineProperty(obj, key, {
get () {
console.log(`getting key "${key}": ${internalValue}`)
return internalValue
},
set (newValue) {
console.log(`setting key "${key}" to: ${newValue}`)
internalValue = newValue
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment