File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // Created by Jesse Squires
3
+ // https://www.jessesquires.com
4
+ //
5
+ // Documentation
6
+ // https://jessesquires.github.io/ReactiveCollectionsKit
7
+ //
8
+ // GitHub
9
+ // https://github.com/jessesquires/ReactiveCollectionsKit
10
+ //
11
+ // Copyright © 2019-present Jesse Squires
12
+ //
13
+
14
+ import Foundation
15
+ import UIKit
16
+
17
+ typealias DiffableSectionSnapshot = NSDiffableDataSourceSectionSnapshot < AnyHashable >
18
+
19
+ extension DiffableSectionSnapshot {
20
+ init ( viewModel: SectionViewModel ) {
21
+ self . init ( )
22
+
23
+ let allCellIdentifiers = viewModel. cells. map ( \. id)
24
+ self . append ( allCellIdentifiers)
25
+
26
+ viewModel. cells. forEach { cell in
27
+ appendAllChildren ( from: cell, to: cell. id)
28
+ }
29
+ }
30
+
31
+ private mutating func appendAllChildren( from cell: AnyCellViewModel , to parentId: AnyHashable ) {
32
+ let childIdentifiers = cell. children. map ( \. id)
33
+
34
+ guard childIdentifiers. isNotEmpty else { return }
35
+
36
+ self . append ( childIdentifiers, to: parentId)
37
+
38
+ for child in cell. children {
39
+ appendAllChildren ( from: child, to: child. id)
40
+ }
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments