|
1 | 1 | import Foundation |
2 | | -import Dwifft |
3 | 2 |
|
4 | 3 | private struct WrappedIdentifiableSection<T: SectionType> { |
5 | 4 | private let value: T |
@@ -38,15 +37,13 @@ struct Diff { |
38 | 37 |
|
39 | 38 | let oldSectionIdentifiers = oldData.map { $0.sectionIdentifier } |
40 | 39 | let newSectionIdentifiers = newData.map { $0.sectionIdentifier } |
41 | | - |
42 | | - let sectionsDiff = Dwifft.diff(oldSectionIdentifiers, newSectionIdentifiers) |
43 | 40 |
|
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) |
50 | 47 | } |
51 | 48 | } |
52 | 49 |
|
@@ -76,20 +73,17 @@ struct Diff { |
76 | 73 | .map { IndexPath(item: $0.offset, section: sectionIndex) } |
77 | 74 | } else { |
78 | 75 | // 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)) |
89 | 82 | } |
| 83 | + } |
90 | 84 | } |
91 | 85 | } |
92 | | - |
| 86 | + |
93 | 87 | return .delta( |
94 | 88 | insertedSections: insertedSections, |
95 | 89 | updatedSections: IndexSet(), |
|
0 commit comments