From 086b56fab0caf1aff537fb07d70ffe798a76268e Mon Sep 17 00:00:00 2001 From: 8secz-johndpope <50567111+8secz-johndpope@users.noreply.github.com> Date: Wed, 8 Apr 2020 14:33:05 +1000 Subject: [PATCH] Suggestion to simply implementation We should encourage users to hook into the willSet parameter as the tableview / collection view are finicky and will crash when the underlying data is not atomically set. --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index e464acd..a54fe35 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,44 @@ collectionView.reload(changes: changes, section: 2, updateData: { }) ``` +## API Pagination + +```swift + + var itemsList: [Video] = [] + var deepDiffRefreshVideoList: [Video] = [] { + willSet { + + let oldVideos = deepDiffRefreshVideoList + let changes = diff(old: oldVideos, new: newValue) + + let exception = tryBlock { + self.collectionView.reload(changes: changes, section: 0, updateData: { + self.itemsList = newValue + }, completion: nil) + } + if let exception = exception { + print(exception as Any) + } + + } + } + + + // in your pagination api callback / simply set the above list + + func fetchMainFeedTrending() { + Video.getMostLikeFeed(currentPage).subscribe( + onNext: { [weak self] videos in + + self?.itemsList.append(contentsOf: videos) + if let arr = self?.itemsList { + self?.deepDiffRefreshVideoList = arr + } + } + } +``` + Take a look at [Demo](https://github.com/onmyway133/DeepDiff/tree/master/Example/DeepDiffDemo) where changes are made via random number of items, and the items are shuffled. ## How does it work