Skip to content

Commit 34be1d8

Browse files
committed
🔊 Add helpful warnings in __DEV__
1 parent 96b4a81 commit 34be1d8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@
2525

2626
"react/jsx-filename-extension": 0,
2727
"react/prefer-stateless-function": 0
28+
},
29+
30+
"globals": {
31+
"__DEV__": true
2832
}
2933
}

src/ImmutableListView.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Immutable from 'immutable';
22
import React, { PureComponent, PropTypes } from 'react';
33
import { ListView, InteractionManager } from 'react-native';
44

5+
const isImmutableIterable = Immutable.Iterable.isIterable;
6+
57
/**
68
* Return the keys from a set of data.
79
*
@@ -13,6 +15,10 @@ import { ListView, InteractionManager } from 'react-native';
1315
* @returns {Array} An array of keys for the data.
1416
*/
1517
function getKeys(immutableData) {
18+
if (__DEV__ && !isImmutableIterable(immutableData)) {
19+
console.warn(`Can't get keys: Data is not Immutable: ${JSON.stringify(immutableData)}`);
20+
}
21+
1622
return immutableData.keySeq().toArray();
1723
}
1824

@@ -23,10 +29,14 @@ function getKeys(immutableData) {
2329
* - getRowIdentities({ section1: ['row1', 'row2'], section2: ['row1'] })
2430
* will return [[0, 1], [0]].
2531
*
26-
* @param immutableSectionData
32+
* @param {Immutable.Iterable} immutableSectionData
2733
* @returns {Array}
2834
*/
2935
function getRowIdentities(immutableSectionData) {
36+
if (__DEV__ && !isImmutableIterable(immutableSectionData)) {
37+
console.warn(`Can't get row identities: Data is not Immutable: ${JSON.stringify(immutableSectionData)}`);
38+
}
39+
3040
const sectionRowKeys = immutableSectionData.map(getKeys);
3141
return sectionRowKeys.valueSeq().toArray();
3242
}
@@ -58,7 +68,7 @@ class ImmutableListView extends PureComponent {
5868
immutableData: (props, propName, componentName) => {
5969
// Note: It's not enough to simply validate PropTypes.instanceOf(Immutable.Iterable),
6070
// because different imports of Immutable.js across files have different class prototypes.
61-
if (!Immutable.Iterable.isIterable(props[propName])) {
71+
if (!isImmutableIterable(props[propName])) {
6272
return new Error(`Invalid prop ${propName} supplied to ${componentName}: Must be Immutable.Iterable.`);
6373
}
6474
},

0 commit comments

Comments
 (0)