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) { if (!this.itemString) {
const { data } = this.props; const { data } = this.props;
let count = 0; let count = 0;
if (typeof data.count === 'function') { if (typeof data.size !== 'undefined') {
count = data.count(); count = data.size;
} else { } 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'); this.itemString = count + ' entr' + (count !== 1 ? 'ies' : 'y');
} }