Skip to content

Commit 11af53c

Browse files
committed
counting entries of iterable structure
1 parent 04f15f6 commit 11af53c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/react/JSONTree/JSONIterableNode.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ export default class JSONIterableNode extends React.Component {
8787
if (!this.itemString) {
8888
const { data } = this.props;
8989
let count = 0;
90-
if (typeof data.count === 'function') {
91-
count = data.count();
90+
if (typeof data.size !== 'undefined') {
91+
count = data.size;
9292
} else {
93-
count = data.length;
93+
for (const entry of data) { // eslint-disable-line no-unused-vars
94+
count += 1;
95+
}
9496
}
9597
this.itemString = count + ' entr' + (count !== 1 ? 'ies' : 'y');
9698
}

0 commit comments

Comments
 (0)