JSFiddle - React, Tailwind, and code Playground
JavaScript
function ItemsCollection() {
//this.someHandler = $('#some_table_id');
this.data = [];
var self = this;
this.getData = function () {
return new Promise(function (resolve, reject) {
console.log('getting the data');
$.get('https://jsonplaceholder.typicode.com/posts/1', function (data) {
resolve(data);
});
});
};
this.prepareData = function (data) {
console.log('preparing the data');
return new Promise(function (resolve, reject) {
for (var x = 0; x < data.length; x++) {
self.data.push(
new Item(data[x])
);
}
resolve(self.data);
});
};
this.updateTable = function () {
console.log('updateing the table');
};
}
var mydata = new ItemsCollection();
mydata.getData().then(
(data) => {
return mydata.prepareData(data);
}) //this is done second
.then((data) => {
return mydata.updateTable(data)
});