counting entries of iterable structure

This commit is contained in:
FredyC 2015-08-22 17:38:43 +02:00
parent 04f15f6d4d
commit 11af53ccfb

View File

@ -87,10 +87,12 @@ export default class JSONIterableNode extends React.Component {
if (!this.itemString) {
const { data } = this.props;
let count = 0;
if (typeof data.count === 'function') {
count = data.count();
if (typeof data.size !== 'undefined') {
count = data.size;
} else {
count = data.length;
for (const entry of data) { // eslint-disable-line no-unused-vars
count += 1;
}
}
this.itemString = count + ' entr' + (count !== 1 ? 'ies' : 'y');
}