Append all pages with promises
This commit is contained in:
parent
22782cf7bd
commit
d5cd4964d7
@ -322,6 +322,7 @@ exports.copyTextToClipboard = copyTextToClipboard;
|
|||||||
exports.isNumeric = isNumeric;
|
exports.isNumeric = isNumeric;
|
||||||
exports.throttle = throttle;
|
exports.throttle = throttle;
|
||||||
exports.promisify = promisify;
|
exports.promisify = promisify;
|
||||||
|
exports.chainPromises = chainPromises;
|
||||||
function camelCaseToDash(str) {
|
function camelCaseToDash(str) {
|
||||||
return str.replace(/([A-Z])/g, function (g) {
|
return str.replace(/([A-Z])/g, function (g) {
|
||||||
return '-' + g[0].toLowerCase();
|
return '-' + g[0].toLowerCase();
|
||||||
@ -530,6 +531,12 @@ function promisify(fn) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function chainPromises(promises) {
|
||||||
|
return promises.reduce(function (prev, cur) {
|
||||||
|
return prev.then(cur);
|
||||||
|
}, Promise.resolve());
|
||||||
|
};
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
/* 2 */
|
/* 2 */
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
@ -2283,7 +2290,6 @@ var DataTable = function () {
|
|||||||
value: function render() {
|
value: function render() {
|
||||||
this.renderHeader();
|
this.renderHeader();
|
||||||
this.renderBody();
|
this.renderBody();
|
||||||
this.setDimensions();
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'renderHeader',
|
key: 'renderHeader',
|
||||||
@ -3040,17 +3046,10 @@ var BodyRenderer = function () {
|
|||||||
// empty body
|
// empty body
|
||||||
this.bodyScrollable.innerHTML = '\n <table class="data-table-body">\n ' + getBodyHTML([]) + '\n </table>\n ';
|
this.bodyScrollable.innerHTML = '\n <table class="data-table-body">\n ' + getBodyHTML([]) + '\n </table>\n ';
|
||||||
|
|
||||||
this.start = 0;
|
// Rows will be appended as promises, so we don't block
|
||||||
this.pageLength = 1000;
|
// even for the first page render
|
||||||
this.end = this.start + this.pageLength;
|
|
||||||
|
|
||||||
// only append ${this.pageLength} rows in the beginning,
|
|
||||||
// defer remaining
|
|
||||||
var rows = this.datamanager.getRows(this.start, this.end);
|
|
||||||
var initialData = this.getDataForClusterize(rows);
|
|
||||||
|
|
||||||
this.clusterize = new _clusterize2.default({
|
this.clusterize = new _clusterize2.default({
|
||||||
rows: initialData,
|
rows: [],
|
||||||
scrollElem: this.bodyScrollable,
|
scrollElem: this.bodyScrollable,
|
||||||
contentElem: (0, _dom2.default)('tbody', this.bodyScrollable),
|
contentElem: (0, _dom2.default)('tbody', this.bodyScrollable),
|
||||||
callbacks: {
|
callbacks: {
|
||||||
@ -3061,34 +3060,47 @@ var BodyRenderer = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.log('dataAppended', this.pageLength);
|
|
||||||
this.appendRemainingData();
|
this.appendRemainingData();
|
||||||
|
// setDimensions will work only if there is atleast one row appended
|
||||||
|
// so we call it as soon as the first Page is appended
|
||||||
|
this.firstPagePromise.then(function () {
|
||||||
|
return _this.instance.setDimensions();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'appendRemainingData',
|
key: 'appendRemainingData',
|
||||||
value: function appendRemainingData() {
|
value: function appendRemainingData() {
|
||||||
var dataAppended = this.pageLength;
|
var chunkSize = 1000;
|
||||||
|
var start = 0,
|
||||||
|
end = chunkSize;
|
||||||
|
var dataAppended = 0;
|
||||||
|
this.firstPagePromise = null;
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
var rowCount = this.datamanager.getRowCount();
|
var rowCount = this.datamanager.getRowCount();
|
||||||
|
|
||||||
while (dataAppended + this.pageLength < rowCount) {
|
while (dataAppended + chunkSize < rowCount) {
|
||||||
this.start = this.end;
|
var promise = this.appendNextPage(start, end);
|
||||||
this.end = this.start + this.pageLength;
|
if (!this.firstPagePromise) this.firstPagePromise = promise;
|
||||||
promises.push(this.appendNextPage(this.start, this.end));
|
promises.push(promise);
|
||||||
dataAppended += this.pageLength;
|
dataAppended += chunkSize;
|
||||||
|
start = end;
|
||||||
|
end += chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowCount % this.pageLength > 0) {
|
if (rowCount % chunkSize > 0) {
|
||||||
// last page
|
// last page
|
||||||
this.start = this.end;
|
var _promise = this.appendNextPage(start, end);
|
||||||
this.end = this.start + this.pageLength;
|
if (!this.firstPagePromise) this.firstPagePromise = _promise;
|
||||||
promises.push(this.appendNextPage(this.start, this.end));
|
promises.push(_promise);
|
||||||
|
dataAppended += rowCount % chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return promises.reduce(function (prev, cur) {
|
return (0, _utils.chainPromises)(promises);
|
||||||
return prev.then(cur);
|
|
||||||
}, Promise.resolve());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// promisified
|
||||||
|
|
||||||
}, {
|
}, {
|
||||||
key: 'appendNextPage',
|
key: 'appendNextPage',
|
||||||
value: function appendNextPage(start, end) {
|
value: function appendNextPage(start, end) {
|
||||||
@ -3096,7 +3108,6 @@ var BodyRenderer = function () {
|
|||||||
var data = this.getDataForClusterize(rows);
|
var data = this.getDataForClusterize(rows);
|
||||||
|
|
||||||
this.clusterize.append(data);
|
this.clusterize.append(data);
|
||||||
this.log('dataAppended', rows.length);
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getDataForClusterize',
|
key: 'getDataForClusterize',
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
|||||||
import $ from './dom';
|
import $ from './dom';
|
||||||
import Clusterize from 'clusterize.js';
|
import Clusterize from 'clusterize.js';
|
||||||
import { getRowHTML } from './rowmanager';
|
import { getRowHTML } from './rowmanager';
|
||||||
import { promisify } from './utils';
|
import { promisify, chainPromises } from './utils';
|
||||||
|
|
||||||
export default class BodyRenderer {
|
export default class BodyRenderer {
|
||||||
constructor(instance) {
|
constructor(instance) {
|
||||||
@ -42,17 +42,10 @@ export default class BodyRenderer {
|
|||||||
</table>
|
</table>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.start = 0;
|
// Rows will be appended as promises, so we don't block
|
||||||
this.pageLength = 1000;
|
// even for the first page render
|
||||||
this.end = this.start + this.pageLength;
|
|
||||||
|
|
||||||
// only append ${this.pageLength} rows in the beginning,
|
|
||||||
// defer remaining
|
|
||||||
const rows = this.datamanager.getRows(this.start, this.end);
|
|
||||||
const initialData = this.getDataForClusterize(rows);
|
|
||||||
|
|
||||||
this.clusterize = new Clusterize({
|
this.clusterize = new Clusterize({
|
||||||
rows: initialData,
|
rows: [],
|
||||||
scrollElem: this.bodyScrollable,
|
scrollElem: this.bodyScrollable,
|
||||||
contentElem: $('tbody', this.bodyScrollable),
|
contentElem: $('tbody', this.bodyScrollable),
|
||||||
callbacks: {
|
callbacks: {
|
||||||
@ -63,40 +56,47 @@ export default class BodyRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.log('dataAppended', this.pageLength);
|
|
||||||
this.appendRemainingData();
|
this.appendRemainingData();
|
||||||
|
// setDimensions will work only if there is atleast one row appended
|
||||||
|
// so we call it as soon as the first Page is appended
|
||||||
|
this.firstPagePromise.then(() => this.instance.setDimensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
appendRemainingData() {
|
appendRemainingData() {
|
||||||
let dataAppended = this.pageLength;
|
const chunkSize = 1000;
|
||||||
|
let start = 0, end = chunkSize;
|
||||||
|
let dataAppended = 0;
|
||||||
|
this.firstPagePromise = null;
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const rowCount = this.datamanager.getRowCount();
|
const rowCount = this.datamanager.getRowCount();
|
||||||
|
|
||||||
while (dataAppended + this.pageLength < rowCount) {
|
while (dataAppended + chunkSize < rowCount) {
|
||||||
this.start = this.end;
|
const promise = this.appendNextPage(start, end);
|
||||||
this.end = this.start + this.pageLength;
|
if (!this.firstPagePromise) this.firstPagePromise = promise;
|
||||||
promises.push(this.appendNextPage(this.start, this.end));
|
promises.push(promise);
|
||||||
dataAppended += this.pageLength;
|
dataAppended += chunkSize;
|
||||||
|
start = end;
|
||||||
|
end += chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rowCount % this.pageLength > 0) {
|
if (rowCount % chunkSize > 0) {
|
||||||
// last page
|
// last page
|
||||||
this.start = this.end;
|
const promise = this.appendNextPage(start, end);
|
||||||
this.end = this.start + this.pageLength;
|
if (!this.firstPagePromise) this.firstPagePromise = promise;
|
||||||
promises.push(this.appendNextPage(this.start, this.end));
|
promises.push(promise);
|
||||||
|
dataAppended += rowCount % chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return promises.reduce(
|
return chainPromises(promises);
|
||||||
(prev, cur) => prev.then(cur), Promise.resolve()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// promisified
|
||||||
appendNextPage(start, end) {
|
appendNextPage(start, end) {
|
||||||
const rows = this.datamanager.getRows(start, end);
|
const rows = this.datamanager.getRows(start, end);
|
||||||
const data = this.getDataForClusterize(rows);
|
const data = this.getDataForClusterize(rows);
|
||||||
|
|
||||||
this.clusterize.append(data);
|
this.clusterize.append(data);
|
||||||
this.log('dataAppended', rows.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDataForClusterize(rows) {
|
getDataForClusterize(rows) {
|
||||||
|
|||||||
@ -139,7 +139,6 @@ class DataTable {
|
|||||||
render() {
|
render() {
|
||||||
this.renderHeader();
|
this.renderHeader();
|
||||||
this.renderBody();
|
this.renderBody();
|
||||||
this.setDimensions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderHeader() {
|
renderHeader() {
|
||||||
|
|||||||
@ -193,3 +193,9 @@ export function promisify(fn, context = null) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function chainPromises(promises) {
|
||||||
|
return promises.reduce(
|
||||||
|
(prev, cur) => prev.then(cur), Promise.resolve()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user