Skip to content

Commit

Permalink
fix merge data with sections closes FaridSafi#98
Browse files Browse the repository at this point in the history
  • Loading branch information
Oxyaction committed Apr 7, 2017
1 parent 9b8d939 commit 50667da
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions GiftedListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var React = require('react');

var {
ListView,
Platform,
TouchableHighlight,
View,
Text,
Expand All @@ -14,19 +13,16 @@ var {


// small helper function which merged two objects into one
function MergeRecursive(obj1, obj2) {
for (var p in obj2) {
try {
if ( obj2[p].constructor==Object ) {
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch(e) {
obj1[p] = obj2[p];
function MergeRowsWithHeaders(obj1, obj2) {
const obj1Copy = { ...obj1 };
Object.keys(obj2).forEach((key) => {
if (Array.isArray(obj2[key]) && Array.isArray(obj1Copy[key])) {
obj1Copy[key] = [...obj1Copy[key], ...obj2[key]];
} else {
obj1Copy[key] = obj2[key];
}
}
return obj1;
});
return obj1Copy;
}

var GiftedListView = React.createClass({
Expand Down Expand Up @@ -243,7 +239,7 @@ var GiftedListView = React.createClass({
this._setPage(this._getPage() + 1);
var mergedRows = null;
if (this.props.withSections === true) {
mergedRows = MergeRecursive(this._getRows(), rows);
mergedRows = MergeRowsWithHeaders(this._getRows(), rows);
} else {
mergedRows = this._getRows().concat(rows);
}
Expand Down

0 comments on commit 50667da

Please sign in to comment.