@@ -30,23 +30,36 @@ struct IntItem {
3030 let date : Date
3131}
3232
33- extension NumberSection : SectionModelType {
33+ extension NumberSection : AnimatableSectionModelType {
3434 typealias Item = IntItem
35+ typealias Identity = String
3536
3637 var items : [ IntItem ] {
3738 return numbers
3839 }
40+ var identity : String { return header }
3941
4042 init ( original: NumberSection , items: [ Item ] ) {
4143 self = original
4244 self . numbers = items
4345 }
4446}
4547
48+ extension IntItem : IdentifiableType , Equatable {
49+ typealias Identity = Int
50+ var identity : Int {
51+ return number. hashValue
52+ }
53+ }
54+
55+ func == ( lhs: IntItem , rhs: IntItem ) -> Bool {
56+ return lhs. date == rhs. date && lhs. number == rhs. number
57+ }
58+
4659class ViewController : UIViewController {
4760
4861 let tableNode = ASTableNode ( )
49- private let dataSource = RxASTableReloadDataSource < NumberSection > ( )
62+ private let dataSource = RxASTableAnimatedDataSource < NumberSection > ( )
5063
5164 private let disposeBag = DisposeBag ( )
5265 override func viewDidLoad( ) {
@@ -55,18 +68,35 @@ class ViewController: UIViewController {
5568
5669 dataSource. configureCell = { ( _, tv, ip, i) in
5770 let cell = ASTextCellNode ( )
58- cell. text = " \( i) "
71+ cell. text = " \( i. number ) "
5972 return cell
6073 }
6174
6275 dataSource. titleForHeaderInSection = { ( dataSource, section) -> String ? in
6376 return dataSource [ section] . header
6477 }
6578
66- Observable . just ( _initialValue)
67- . asObservable ( )
79+ Observable < Int >
80+ . interval ( 2.0 , scheduler: MainScheduler . instance)
81+ . map { _ in
82+ var sectionIndex = Set < Int > ( )
83+ var section = [ NumberSection] ( )
84+
85+ let numberSections = Int ( arc4random_uniform ( 5 ) ) + 2
86+
87+ while sectionIndex. count < numberSections {
88+ let random = Int ( arc4random_uniform ( 9 ) )
89+ guard !sectionIndex. contains ( random) else { continue }
90+
91+ section. append ( _initialValue [ random] )
92+ sectionIndex. insert ( random)
93+ }
94+
95+ return section
96+ }
6897 . bind ( to: tableNode. rx. items ( dataSource: dataSource) )
6998 . disposed ( by: disposeBag)
99+
70100 }
71101
72102 override func viewWillLayoutSubviews( ) {
0 commit comments