JSFiddle - React, Tailwind, and code Playground
by Sam Wray
JavaScript
const state = {};
const privateState = {};
class State {
constructor () {
this._bpm = 120;
}
get bpm () {
return this._bpm;
}
set bpm () {
}
}
function definePropertyOnState (property, watcher, initialValue = undefined) {
Object.defineProperty(state, property, {
get() {
return privateState.bpm;
},
set: watcher.bind(this),
enumerable: true,
configurable: true
});
state[property] = initialValue;
}
definePropertyOnState ('bpm', (newValue) => {
console.log(newValue);
privateState.bpm = newValue;
}, 120);
state.bpm = 240;