FaridSafi / react-native-gifted-listview

✌️ ListView with pull-to-refresh and infinite scrolling for Android and iOS React-Native apps
MIT License
1.62k stars 290 forks source link

Incorrect merge behavior for data with existing sections #98

Open Oxyaction opened 7 years ago

Oxyaction commented 7 years ago

Current implementation of MergeRecursive function works incorrectly when loading a new page with header that already exists, new data completely overwrites old. Consider the following example:

const a = { monday: ['a', 'b', 'c'] };
const b = { monday: ['d', 'e'], tuesday: ['f'] };
MergeRecursive(a, b);

gives

{ monday: [ 'd', 'e' ], tuesday: [ 'f' ] }

instead of expected

{ monday: ['a', 'b', 'c', 'd', 'e' ], tuesday: [ 'f' ] }

so to get this feature work correctly we need either prefetch all pages before current too, which is totally inefficient of course or to merge new data with old before passing it to the callback which is not so convenient.