Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run UI updates on main thread #96

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Next Next commit
Updated TableViewDiffCalculator to run processChanges on main thread
saltzmanjoelh authored Jul 17, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cdbd6fd818e3d95f94d6042ccbab4f88ce671443
26 changes: 18 additions & 8 deletions Dwifft/Dwifft+AppKit.swift
Original file line number Diff line number Diff line change
@@ -51,16 +51,26 @@ public final class TableViewDiffCalculator<Value: Equatable>: AbstractDiffCalcul

override internal func processChanges(newState: SectionedValues<Int, Value>, diff: [SectionedDiffStep<Int, Value>]) {
guard let tableView = self.tableView else { return }
tableView.beginUpdates()
self._sectionedValues = newState
for result in diff {
switch result {
case let .delete(_, row, _): tableView.removeRows(at: [row], withAnimation: self.deletionAnimation)
case let .insert(_, row, _): tableView.insertRows(at: [row], withAnimation: self.insertionAnimation)
default: fatalError("NSTableViews do not have sections")
let updateAction = {
tableView.beginUpdates()
self._sectionedValues = newState
for result in diff {
switch result {
case let .delete(_, row, _): tableView.removeRows(at: [row], withAnimation: self.deletionAnimation)
case let .insert(_, row, _): tableView.insertRows(at: [row], withAnimation: self.insertionAnimation)
default: fatalError("NSTableViews do not have sections")
}
}
tableView.endUpdates()
}
if Thread.current.isMainThread {
updateAction()
} else {
DispatchQueue.main.sync {
updateAction()
}
}
tableView.endUpdates()

}

}