From b581a3e2661bf5f6ef10ad5d324f28f6a316fc51 Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:06:12 +0900
Subject: [PATCH 1/7] Add completion block to apply function
---
.../AppKit/CocoaCollectionViewDiffableDataSource.swift | 6 +++++-
Sources/Internal/DiffableDataSourceCore.swift | 10 +++++++---
Sources/UIKit/CollectionViewDiffableDataSource.swift | 8 ++++++--
Sources/UIKit/TableViewDiffableDataSource.swift | 8 ++++++--
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
index bd6ed6b..aa5eb7e 100644
--- a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
+++ b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
@@ -33,6 +33,8 @@ open class CocoaCollectionViewDiffableDataSource, animatingDifferences: Bool = true) {
core.apply(
snapshot,
@@ -40,7 +42,9 @@ open class CocoaCollectionViewDiffableDataSource,
view: View?,
animatingDifferences: Bool,
- performUpdates: @escaping (View, StagedChangeset<[Section]>, @escaping ([Section]) -> Void) -> Void
+ performUpdates: @escaping (View, StagedChangeset<[Section]>, @escaping ([Section]) -> Void) -> Void,
+ completion: (() -> Void)?
) {
dispatcher.dispatch { [weak self] in
guard let self = self else {
@@ -35,15 +36,18 @@ final class DiffableDataSourceCore, animatingDifferences: Bool = true) {
+ /// - completion: An optional completion block which is called when the complete
+ /// performing updates.
+ public func apply(_ snapshot: DiffableDataSourceSnapshot, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
core.apply(
snapshot,
view: collectionView,
animatingDifferences: animatingDifferences,
performUpdates: { collectionView, changeset, setSections in
collectionView.reload(using: changeset, setData: setSections)
- })
+ },
+ completion: completion
+ )
}
/// Returns a new snapshot object of current state.
diff --git a/Sources/UIKit/TableViewDiffableDataSource.swift b/Sources/UIKit/TableViewDiffableDataSource.swift
index 67ce2d7..fcc7a1f 100644
--- a/Sources/UIKit/TableViewDiffableDataSource.swift
+++ b/Sources/UIKit/TableViewDiffableDataSource.swift
@@ -36,14 +36,18 @@ open class TableViewDiffableDataSource, animatingDifferences: Bool = true) {
+ /// - completion: An optional completion block which is called when the complete
+ /// performing updates.
+ public func apply(_ snapshot: DiffableDataSourceSnapshot, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
core.apply(
snapshot,
view: tableView,
animatingDifferences: animatingDifferences,
performUpdates: { tableView, changeset, setSections in
tableView.reload(using: changeset, with: self.defaultRowAnimation, setData: setSections)
- })
+ },
+ completion: completion
+ )
}
/// Returns a new snapshot object of current state.
From 8db42c2188e0ff2172226fc82e8bb08ae6d93461 Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:26:30 +0900
Subject: [PATCH 2/7] Add tests
---
.../CocoaCollectionViewDiffableDataSource.swift | 2 +-
...oaCollectionViewDiffableDataSourceTests.swift | 16 ++++++++++++----
.../CollectionViewDiffableDataSourceTests.swift | 16 ++++++++++++----
Tests/TableViewDiffableDataSourceTests.swift | 16 ++++++++++++----
4 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
index aa5eb7e..2d837d5 100644
--- a/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
+++ b/Sources/AppKit/CocoaCollectionViewDiffableDataSource.swift
@@ -35,7 +35,7 @@ open class CocoaCollectionViewDiffableDataSource, animatingDifferences: Bool = true) {
+ public func apply(_ snapshot: DiffableDataSourceSnapshot, animatingDifferences: Bool = true, completion: (() -> Void)? = nil) {
core.apply(
snapshot,
view: collectionView,
diff --git a/Tests/CocoaCollectionViewDiffableDataSourceTests.swift b/Tests/CocoaCollectionViewDiffableDataSourceTests.swift
index ca54824..c500e01 100644
--- a/Tests/CocoaCollectionViewDiffableDataSourceTests.swift
+++ b/Tests/CocoaCollectionViewDiffableDataSourceTests.swift
@@ -22,21 +22,29 @@ final class CocoaCollectionViewDiffableDataSourceTests: XCTestCase {
var snapshot = DiffableDataSourceSnapshot()
- dataSource.apply(snapshot)
+ let e1 = expectation(description: "testApply() e1")
+ dataSource.apply(snapshot, completion: e1.fulfill)
+ wait(for: [e1], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)
snapshot.appendSections([0])
snapshot.appendItems([0])
- dataSource.apply(snapshot)
+ let e2 = expectation(description: "testApply() e2")
+ dataSource.apply(snapshot, completion: e2.fulfill)
+ wait(for: [e2], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
- dataSource.apply(snapshot)
+ let e3 = expectation(description: "testApply() e3")
+ dataSource.apply(snapshot, completion: e3.fulfill)
+ wait(for: [e3], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
snapshot.appendItems([1])
- dataSource.apply(snapshot)
+ let e4 = expectation(description: "testApply() e4")
+ dataSource.apply(snapshot, completion: e4.fulfill)
+ wait(for: [e4], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
}
diff --git a/Tests/CollectionViewDiffableDataSourceTests.swift b/Tests/CollectionViewDiffableDataSourceTests.swift
index e419a54..872683a 100644
--- a/Tests/CollectionViewDiffableDataSourceTests.swift
+++ b/Tests/CollectionViewDiffableDataSourceTests.swift
@@ -22,21 +22,29 @@ final class CollectionViewDiffableDataSourceTests: XCTestCase {
var snapshot = DiffableDataSourceSnapshot()
- dataSource.apply(snapshot)
+ let e1 = expectation(description: "testApply() e1")
+ dataSource.apply(snapshot, completion: e1.fulfill)
+ wait(for: [e1], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 0)
snapshot.appendSections([0])
snapshot.appendItems([0])
- dataSource.apply(snapshot)
+ let e2 = expectation(description: "testApply() e2")
+ dataSource.apply(snapshot, completion: e2.fulfill)
+ wait(for: [e2], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
- dataSource.apply(snapshot)
+ let e3 = expectation(description: "testApply() e3")
+ dataSource.apply(snapshot, completion: e3.fulfill)
+ wait(for: [e3], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 1)
snapshot.appendItems([1])
- dataSource.apply(snapshot)
+ let e4 = expectation(description: "testApply() e4")
+ dataSource.apply(snapshot, completion: e4.fulfill)
+ wait(for: [e4], timeout: 1)
XCTAssertEqual(collectionView.isPerformBatchUpdatesCalledCount, 2)
}
diff --git a/Tests/TableViewDiffableDataSourceTests.swift b/Tests/TableViewDiffableDataSourceTests.swift
index c29cd3f..ce3e1cb 100644
--- a/Tests/TableViewDiffableDataSourceTests.swift
+++ b/Tests/TableViewDiffableDataSourceTests.swift
@@ -22,21 +22,29 @@ final class TableViewDiffableDataSourceTests: XCTestCase {
var snapshot = DiffableDataSourceSnapshot()
- dataSource.apply(snapshot)
+ let e1 = expectation(description: "testApply() e1")
+ dataSource.apply(snapshot, completion: e1.fulfill)
+ wait(for: [e1], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 0)
snapshot.appendSections([0])
snapshot.appendItems([0])
- dataSource.apply(snapshot)
+ let e2 = expectation(description: "testApply() e2")
+ dataSource.apply(snapshot, completion: e2.fulfill)
+ wait(for: [e2], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)
- dataSource.apply(snapshot)
+ let e3 = expectation(description: "testApply() e3")
+ dataSource.apply(snapshot, completion: e3.fulfill)
+ wait(for: [e3], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 1)
snapshot.appendItems([1])
- dataSource.apply(snapshot)
+ let e4 = expectation(description: "testApply() e4")
+ dataSource.apply(snapshot, completion: e4.fulfill)
+ wait(for: [e4], timeout: 1)
XCTAssertEqual(tableView.isPerformBatchUpdatesCalledCount, 2)
}
From 8df43ab0b438c85236f2d8ef36463ab133933711 Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:31:49 +0900
Subject: [PATCH 3/7] Update gems
---
Gemfile | 4 ++--
Gemfile.lock | 61 ++++++++++++++++++++++++++--------------------------
2 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/Gemfile b/Gemfile
index 605a9fe..ea199be 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,4 @@
source "https://rubygems.org"
-gem 'cocoapods', '1.7.5'
-gem 'jazzy', '0.9.4'
+gem 'cocoapods', '1.8.4'
+gem 'jazzy', '0.11.2'
diff --git a/Gemfile.lock b/Gemfile.lock
index 0f6f1b7..321f0be 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,24 +1,27 @@
GEM
remote: https://rubygems.org/
specs:
- CFPropertyList (3.0.1)
+ CFPropertyList (3.0.2)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
+ algoliasearch (1.27.1)
+ httpclient (~> 2.8, >= 2.8.3)
+ json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
- cocoapods (1.7.5)
+ cocoapods (1.8.4)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
- cocoapods-core (= 1.7.5)
+ cocoapods-core (= 1.8.4)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
- cocoapods-trunk (>= 1.3.1, < 2.0)
+ cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
@@ -27,65 +30,63 @@ GEM
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.4)
- xcodeproj (>= 1.10.0, < 2.0)
- cocoapods-core (1.7.5)
+ xcodeproj (>= 1.11.1, < 2.0)
+ cocoapods-core (1.8.4)
activesupport (>= 4.0.2, < 6)
+ algoliasearch (~> 1.0)
+ concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.4)
- cocoapods-downloader (1.2.2)
+ cocoapods-downloader (1.3.0)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
- cocoapods-trunk (1.4.0)
+ cocoapods-trunk (1.4.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.5)
escape (0.0.4)
- ffi (1.11.1)
+ ffi (1.11.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
+ httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
- jazzy (0.9.4)
- cocoapods (~> 1.0)
- mustache (~> 0.99)
+ jazzy (0.11.2)
+ cocoapods (~> 1.5)
+ mustache (~> 1.1)
open4
- redcarpet (~> 3.2)
+ redcarpet (~> 3.4)
rouge (>= 2.0.6, < 4.0)
- sass (~> 3.4)
+ sassc (~> 2.1)
sqlite3 (~> 1.3)
xcinvoke (~> 0.3.0)
+ json (2.2.0)
liferaft (0.0.6)
- minitest (5.11.3)
+ minitest (5.13.0)
molinillo (0.6.6)
- mustache (0.99.8)
+ mustache (1.1.1)
nanaimo (0.2.6)
nap (1.1.0)
netrc (0.11.0)
open4 (1.3.4)
- rb-fsevent (0.10.3)
- rb-inotify (0.10.0)
- ffi (~> 1.0)
- redcarpet (3.4.0)
- rouge (3.4.1)
+ redcarpet (3.5.0)
+ rouge (3.13.0)
ruby-macho (1.4.0)
- sass (3.7.4)
- sass-listen (~> 4.0.0)
- sass-listen (4.0.0)
- rb-fsevent (~> 0.9, >= 0.9.4)
- rb-inotify (~> 0.9, >= 0.9.7)
+ sassc (2.2.1)
+ ffi (~> 1.9)
sqlite3 (1.4.1)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcinvoke (0.3.0)
liferaft (~> 0.0.6)
- xcodeproj (1.12.0)
+ xcodeproj (1.13.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
@@ -96,8 +97,8 @@ PLATFORMS
ruby
DEPENDENCIES
- cocoapods (= 1.7.5)
- jazzy (= 0.9.4)
+ cocoapods (= 1.8.4)
+ jazzy (= 0.11.2)
BUNDLED WITH
- 2.0.1
+ 2.0.2
From 3505c43a46e497932f99f514ff2306009e685e41 Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:32:56 +0900
Subject: [PATCH 4/7] Update README
---
README.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 4693651..5d8872b 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,9 @@ let snapshot = DiffableDataSourceSnapshot()
snapshot.appendSections([.main])
snapshot.appendItems(users)
-dataSource.apply(snapshot)
+dataSource.apply(snapshot) {
+ // completion
+}
```
Check the documentation for more detailed API.
From b87be70ffcd0374c7e5edc3b42646540be77b64f Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:37:05 +0900
Subject: [PATCH 5/7] Update podspec
---
DiffableDataSources.podspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/DiffableDataSources.podspec b/DiffableDataSources.podspec
index 07dbfde..7f62850 100644
--- a/DiffableDataSources.podspec
+++ b/DiffableDataSources.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'DiffableDataSources'
- spec.version = '0.2.0'
+ spec.version = '0.3.0'
spec.author = { 'ra1028' => 'r.fe51028.r@gmail.com' }
spec.homepage = 'https://github.com/ra1028/DiffableDataSources'
spec.documentation_url = 'https://ra1028.github.io/DiffableDataSources'
From 240e52b5000e9fc42be0b182776f9b3d5b1cfac6 Mon Sep 17 00:00:00 2001
From: Ryo Aoyama
Date: Tue, 10 Dec 2019 15:39:46 +0900
Subject: [PATCH 6/7] Update docs
---
.../CollectionViewDiffableDataSource.html | 25 +-
docs/Classes/TableViewDiffableDataSource.html | 149 +++++++++++-
docs/DataSources.html | 4 +-
docs/Snapshot.html | 4 +-
docs/Structs/DiffableDataSourceSnapshot.html | 4 +-
docs/css/jazzy.css | 16 +-
docs/index.html | 8 +-
docs/js/jazzy.js | 52 ++--
docs/js/jazzy.search.js | 26 +-
docs/js/jquery.min.js | 6 +-
docs/js/lunr.min.js | 7 +-
docs/js/typeahead.jquery.js | 228 ++++++++++++++----
docs/search.json | 2 +-
13 files changed, 423 insertions(+), 108 deletions(-)
mode change 100755 => 100644 docs/js/jquery.min.js
mode change 100755 => 100644 docs/js/lunr.min.js
diff --git a/docs/Classes/CollectionViewDiffableDataSource.html b/docs/Classes/CollectionViewDiffableDataSource.html
index ed97757..ba23473 100644
--- a/docs/Classes/CollectionViewDiffableDataSource.html
+++ b/docs/Classes/CollectionViewDiffableDataSource.html
@@ -235,9 +235,9 @@ changes with automatic diffing.
@@ -252,7 +252,7 @@ changes with automatic diffing.
Declaration
Swift
-
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true)
+
public func apply(_ snapshot: DiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil)
@@ -285,6 +285,19 @@ changes with automatic diffing.
+
+
+
+ completion
+
+ |
+
+
+ An optional completion block which is called when the complete
+ performing updates.
+
+ |
+
@@ -678,8 +691,8 @@ changes with automatic diffing.