Skip to content

Instantly share code, notes, and snippets.

@Kudo
Last active February 19, 2016 19:49
Show Gist options
  • Save Kudo/f73cfd8fe2ad8cad7c1a to your computer and use it in GitHub Desktop.
Save Kudo/f73cfd8fe2ad8cad7c1a to your computer and use it in GitHub Desktop.
ReactNative DataSource + Immutable.js
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