JSFiddle - React, Tailwind, and code Playground
by koehr
HTML
<h1>
Look into your Javascript console!
</h1>
JavaScript
function reactive (obj) {
for (let key in obj) {
let value = obj[key]
obj.__defineGetter__(key, function reactiveGetter () {
return value
})
obj.__defineSetter__(key, function reactiveGetter (newValue) {
console.log('setting value from', value, 'to', newValue)
value = newValue
})
}
}
const reactiveData = {
foo: 1
}
reactive(reactiveData)
reactiveData.foo++
console.log(reactiveData.foo)