Skip to content

Commit bbe56a6

Browse files
authored
Merge pull request #16 from Squarespace/avyazovoy/MOBILE-1955-CollectionDifference-migration
MOBILE-1955: Switch from `Dwifft` to `CollectionDifference`
2 parents daa1b25 + 98d8f9e commit bbe56a6

4 files changed

Lines changed: 16 additions & 48 deletions

File tree

.github/fixed_podspecs/Dwifft.podspec

Lines changed: 0 additions & 20 deletions
This file was deleted.

Examples/Podfile.lock

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
PODS:
2-
- Dwifft (0.9)
32
- Nimble (12.3.0)
43
- Quick (7.3.0)
5-
- SimpleSource (3.0.0):
6-
- Dwifft (~> 0.9.0)
4+
- SimpleSource (3.0.0)
75
- SimpleSource/Tests (3.0.0):
8-
- Dwifft (~> 0.9.0)
96
- Nimble (~> 12.0)
107
- Quick (~> 7.0)
118
- SwiftyJSON (5.0.1)
@@ -17,7 +14,6 @@ DEPENDENCIES:
1714

1815
SPEC REPOS:
1916
trunk:
20-
- Dwifft
2117
- Nimble
2218
- Quick
2319
- SwiftyJSON
@@ -27,10 +23,9 @@ EXTERNAL SOURCES:
2723
:path: ".."
2824

2925
SPEC CHECKSUMS:
30-
Dwifft: 42912068ed2a8146077d1a1404df18625bd086e1
3126
Nimble: f8a8219d16f176429b951e8f7e72df5c23ceddc0
3227
Quick: d32871931c05547cb4e0bc9009d66a18b50d8558
33-
SimpleSource: 14b1bd2028a07d7b2a71433bed85f03ca33deb37
28+
SimpleSource: 611bfe53fe55132415a3c72a9a0126f9aa846d8b
3429
SwiftyJSON: 2f33a42c6fbc52764d96f13368585094bfd8aa5e
3530

3631
PODFILE CHECKSUM: a5deddba5204624da3222bdb26450e64fabfabc5

SimpleSource.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Pod::Spec.new do |s|
99
s.swift_version = '5.7'
1010
s.source = { :git => 'https://github.com/Squarespace/simple-source.git', :tag => s.version }
1111
s.source_files = 'Sources/**/*.{h,m,swift}'
12-
s.dependency 'Dwifft', '~> 0.9.0'
1312

1413
s.test_spec 'Tests' do |test_spec|
1514
test_spec.resource = 'Tests/Model/*.xcdatamodeld'

Sources/Utils/Diff.swift

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import Dwifft
32

43
private struct WrappedIdentifiableSection<T: SectionType> {
54
private let value: T
@@ -38,15 +37,13 @@ struct Diff {
3837

3938
let oldSectionIdentifiers = oldData.map { $0.sectionIdentifier }
4039
let newSectionIdentifiers = newData.map { $0.sectionIdentifier }
41-
42-
let sectionsDiff = Dwifft.diff(oldSectionIdentifiers, newSectionIdentifiers)
4340

44-
sectionsDiff.forEach { step in
45-
switch step {
46-
case .insert:
47-
insertedSections.insert(step.idx)
48-
case .delete:
49-
deletedSections.insert(step.idx)
41+
newSectionIdentifiers.difference(from: oldSectionIdentifiers).forEach { change in
42+
switch change {
43+
case let .remove(offset, _, _):
44+
deletedSections.insert(offset)
45+
case let .insert(offset, _, _):
46+
insertedSections.insert(offset)
5047
}
5148
}
5249

@@ -76,20 +73,17 @@ struct Diff {
7673
.map { IndexPath(item: $0.offset, section: sectionIndex) }
7774
} else {
7875
// Calculate a diff to transform the old section items into the new section items. No in-place updates will be emitted.
79-
Dwifft.diff(oldSection.items, newSection.items)
80-
.forEach { step in
81-
switch step {
82-
case .insert:
83-
let indexPath = IndexPath(item: step.idx, section: sectionIndex)
84-
insertedRows.append(indexPath)
85-
case .delete:
86-
let indexPath = IndexPath(item: step.idx, section: oldSectionIndex)
87-
deletedRows.append(indexPath)
88-
}
76+
newSection.items.difference(from: oldSection.items).forEach { change in
77+
switch change {
78+
case let .remove(offset, _, _):
79+
deletedRows.append(.init(item: offset, section: oldSectionIndex))
80+
case let .insert(offset, _, _):
81+
insertedRows.append(.init(item: offset, section: sectionIndex))
8982
}
83+
}
9084
}
9185
}
92-
86+
9387
return .delta(
9488
insertedSections: insertedSections,
9589
updatedSections: IndexSet(),

0 commit comments

Comments
 (0)