JSFiddle - React, Tailwind, and code Playground
by evgkch
JavaScript
class API {
constructor(path) {
this.model = {};
}
fetchItems() {
return this.model.call('search_read');
}
addItem(text) {
return this.model.call('create', [{ name: text.toString() }]);
}
deleteItems(ids) {
return Array.isArray(ids)
? this.model.call('unlink', [ids])
: this._showErrorMessage.call(this, `${ids} must be an array of ids`)
}
_showErrorMessage(message) {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(message.toString())
}, 0)
});
}
}
const target = new API('energy.saving.program.subprogram.target')
console.log(target)