Skip to content

Commit acbf74b

Browse files
committed
Changed modelAtIndexPath to return actual model, not wrapped model by IdentifiableValue if using AnimatedDataSource,
so that we can use `UITableView`'s `rx_modelSelected` with actual ModelType, not `IdentitifiableValue<ModelType>` as a parameter.
1 parent 890a5d7 commit acbf74b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Sources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import RxSwift
1313
import RxCocoa
1414
#endif
1515

16-
public class RxCollectionViewSectionedAnimatedDataSource<S: SectionModelType>
16+
public class RxCollectionViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
1717
: CollectionViewSectionedDataSource<S>
1818
, RxCollectionViewDataSourceType {
1919
public typealias Element = [Changeset<S>]
20+
public typealias ItemType = S.Item.Identity
21+
2022
public var animationConfiguration: AnimationConfiguration? = nil
2123

2224
// For some inexplicable reason, when doing animated updates first time
@@ -42,4 +44,13 @@ public class RxCollectionViewSectionedAnimatedDataSource<S: SectionModelType>
4244

4345
}.on(observedEvent)
4446
}
47+
48+
override public func modelAtIndexPath(indexPath: NSIndexPath) throws -> Any {
49+
let model = itemAtIndexPath(indexPath)
50+
if let m = model as? IdentitifiableValue<ItemType> {
51+
return m.value
52+
} else {
53+
return model
54+
}
55+
}
4556
}

Sources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import RxSwift
1313
import RxCocoa
1414
#endif
1515

16-
public class RxTableViewSectionedAnimatedDataSource<S: SectionModelType>
16+
public class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
1717
: RxTableViewSectionedDataSource<S>
1818
, RxTableViewDataSourceType {
1919

2020
public typealias Element = [Changeset<S>]
21+
public typealias ItemType = S.Item.Identity
22+
2123
public var animationConfiguration: AnimationConfiguration? = nil
2224

2325
public override init() {
@@ -37,4 +39,13 @@ public class RxTableViewSectionedAnimatedDataSource<S: SectionModelType>
3739
}
3840
}.on(observedEvent)
3941
}
42+
43+
override public func modelAtIndexPath(indexPath: NSIndexPath) throws -> Any {
44+
let model = itemAtIndexPath(indexPath)
45+
if let m = model as? IdentitifiableValue<ItemType> {
46+
return m.value
47+
} else {
48+
return model
49+
}
50+
}
4051
}

0 commit comments

Comments
 (0)