Is there any way to listen for changes to an instance variable in plain Javascript, and then have a method invoke on change?
I would like to update a table with this pattern, starting with this class:
class TableUpdater {
tabledata;
async setData(editedRow) {
const response = await fetch('http://example.com/api', {
method : 'post'
, headers : {
"Content-Type" : "application/json"
}
, body : JSON.stringify(editedRow)
});
const updatedData = await response.json();
this.tabledata = updatedData;
}
async updateTable(arg1) {
// can do the below, but it would be nice to decouple setData() from updateTable()
// await this.setData(arg1);
// table creation logic
}
}
const tableUpdater = new TableUpdater();