Last active
February 19, 2016 19:49
-
-
Save Kudo/f73cfd8fe2ad8cad7c1a to your computer and use it in GitHub Desktop.
ReactNative DataSource + Immutable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let immutableDataList = Immutable.List.of( | |
Immutable.Map({id: 123, name: 'foo'}), | |
Immutable.Map({id: 456, name: 'bar'}), | |
); | |
let dataSource = new ListView.DataSource({ | |
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | |
getRowData: (dataBlob, sectionID, rowID) => { return dataBlob[sectionID].get(rowID); } | |
}); | |
let rowIds = (count => [...Array(count)].map((val, i) => i))(immutableDataList.size); | |
this.state = { | |
dataSource: dataSource.cloneWithRows(immutableDataList, rowIds), | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment