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

MOBILE-1955: Switch from Dwifft to CollectionDifference #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/fixed_podspecs/Dwifft.podspec

This file was deleted.

9 changes: 2 additions & 7 deletions Examples/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
PODS:
- Dwifft (0.9)
- Nimble (12.3.0)
- Quick (7.3.0)
- SimpleSource (3.0.0):
- Dwifft (~> 0.9.0)
- SimpleSource (3.0.0)
- SimpleSource/Tests (3.0.0):
- Dwifft (~> 0.9.0)
- Nimble (~> 12.0)
- Quick (~> 7.0)
- SwiftyJSON (5.0.1)
Expand All @@ -17,7 +14,6 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- Dwifft
- Nimble
- Quick
- SwiftyJSON
Expand All @@ -27,10 +23,9 @@ EXTERNAL SOURCES:
:path: ".."

SPEC CHECKSUMS:
Dwifft: 42912068ed2a8146077d1a1404df18625bd086e1
Nimble: f8a8219d16f176429b951e8f7e72df5c23ceddc0
Quick: d32871931c05547cb4e0bc9009d66a18b50d8558
SimpleSource: 14b1bd2028a07d7b2a71433bed85f03ca33deb37
SimpleSource: 611bfe53fe55132415a3c72a9a0126f9aa846d8b
SwiftyJSON: 2f33a42c6fbc52764d96f13368585094bfd8aa5e

PODFILE CHECKSUM: a5deddba5204624da3222bdb26450e64fabfabc5
Expand Down
1 change: 0 additions & 1 deletion SimpleSource.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Pod::Spec.new do |s|
s.swift_version = '5.7'
s.source = { :git => 'https://github.com/Squarespace/simple-source.git', :tag => s.version }
s.source_files = 'Sources/**/*.{h,m,swift}'
s.dependency 'Dwifft', '~> 0.9.0'

s.test_spec 'Tests' do |test_spec|
test_spec.resource = 'Tests/Model/*.xcdatamodeld'
Expand Down
34 changes: 14 additions & 20 deletions Sources/Utils/Diff.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Dwifft

private struct WrappedIdentifiableSection<T: SectionType> {
private let value: T
Expand Down Expand Up @@ -38,15 +37,13 @@ struct Diff {

let oldSectionIdentifiers = oldData.map { $0.sectionIdentifier }
let newSectionIdentifiers = newData.map { $0.sectionIdentifier }

let sectionsDiff = Dwifft.diff(oldSectionIdentifiers, newSectionIdentifiers)

sectionsDiff.forEach { step in
switch step {
case .insert:
insertedSections.insert(step.idx)
case .delete:
deletedSections.insert(step.idx)
newSectionIdentifiers.difference(from: oldSectionIdentifiers).forEach { change in
switch change {
case let .remove(offset, _, _):
deletedSections.insert(offset)
case let .insert(offset, _, _):
insertedSections.insert(offset)
}
}

Expand Down Expand Up @@ -76,20 +73,17 @@ struct Diff {
.map { IndexPath(item: $0.offset, section: sectionIndex) }
} else {
// Calculate a diff to transform the old section items into the new section items. No in-place updates will be emitted.
Dwifft.diff(oldSection.items, newSection.items)
.forEach { step in
switch step {
case .insert:
let indexPath = IndexPath(item: step.idx, section: sectionIndex)
insertedRows.append(indexPath)
case .delete:
let indexPath = IndexPath(item: step.idx, section: oldSectionIndex)
deletedRows.append(indexPath)
}
newSection.items.difference(from: oldSection.items).forEach { change in
switch change {
case let .remove(offset, _, _):
deletedRows.append(.init(item: offset, section: oldSectionIndex))
case let .insert(offset, _, _):
insertedRows.append(.init(item: offset, section: sectionIndex))
}
}
}
}

return .delta(
insertedSections: insertedSections,
updatedSections: IndexSet(),
Expand Down