Skip to content

Commit

Permalink
Optimization. Ignore empty delta updates. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
heiberg authored Dec 11, 2018
1 parent 4daf229 commit c1e7f11
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/UICollectionView/CollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class CollectionViewDataSource<DS, VF>: NSObject, UICollectionViewDataSourc
super.init()

self.subscription = dataSource.updateHandler.subscribe { [weak self] update in
guard let `self` = self, !self.ignoreDataSourceUpdates else { return }
guard let `self` = self, !update.isEmpty, !self.ignoreDataSourceUpdates else { return }
viewUpdate(update)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/UITableView/TableViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class TableViewDataSource<DS, VF>: NSObject, UITableViewDataSource where DS
super.init()

self.subscription = dataSource.updateHandler.subscribe { [weak self] update in
guard let `self` = self, !self.ignoreDataSourceUpdates else { return }
guard let `self` = self, !update.isEmpty, !self.ignoreDataSourceUpdates else { return }
viewUpdate(update)
}
}
Expand Down
18 changes: 18 additions & 0 deletions Sources/Updates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ public enum IndexedUpdate {
deletedRows: [IndexPath]
)
case full

/// Whether the update is considered empty.
///
/// - `true` for delta updates with no content
/// - `false` in all other cases
public var isEmpty: Bool {
switch self {
case let .delta(insertedSections, updatedSections, deletedSections, insertedRows, updatedRows, deletedRows):
return insertedSections.isEmpty &&
updatedSections.isEmpty &&
deletedSections.isEmpty &&
insertedRows.isEmpty &&
updatedRows.isEmpty &&
deletedRows.isEmpty
case .full:
return false
}
}
}

public class IndexedUpdateHandler {
Expand Down

0 comments on commit c1e7f11

Please sign in to comment.