Improves UITableView and UICollection view bindings behavior.
This commit is contained in:
parent
4b602fd88e
commit
bdbcb5bc87
|
|
@ -142,7 +142,14 @@ extension UICollectionView {
|
||||||
-> (source: O)
|
-> (source: O)
|
||||||
-> Disposable {
|
-> Disposable {
|
||||||
return { source in
|
return { source in
|
||||||
|
// This is called for sideeffects only, and to make sure delegate proxy is in place when
|
||||||
|
// data source is being bound.
|
||||||
|
// This is needed because theoretically the data source subscription itself might
|
||||||
|
// call `self.rx_delegate`. If that happens, it might cause weird side effects since
|
||||||
|
// setting data source will set delegate, and UITableView might get into a weird state.
|
||||||
|
// Therefore it's better to set delegate proxy first, just to be sure.
|
||||||
|
_ = self.rx_delegate
|
||||||
|
// Strong reference is needed because data source is in use until result subscription is disposed
|
||||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxCollectionViewDataSourceProxy, event) -> Void in
|
||||||
guard let collectionView = self else {
|
guard let collectionView = self else {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,14 @@ extension UITableView {
|
||||||
-> (source: O)
|
-> (source: O)
|
||||||
-> Disposable {
|
-> Disposable {
|
||||||
return { source in
|
return { source in
|
||||||
// There needs to be a strong retaining here because
|
// This is called for sideeffects only, and to make sure delegate proxy is in place when
|
||||||
|
// data source is being bound.
|
||||||
|
// This is needed because theoretically the data source subscription itself might
|
||||||
|
// call `self.rx_delegate`. If that happens, it might cause weird side effects since
|
||||||
|
// setting data source will set delegate, and UITableView might get into a weird state.
|
||||||
|
// Therefore it's better to set delegate proxy first, just to be sure.
|
||||||
|
_ = self.rx_delegate
|
||||||
|
// Strong reference is needed because data source is in use until result subscription is disposed
|
||||||
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
return source.subscribeProxyDataSourceForObject(self, dataSource: dataSource, retainDataSource: true) { [weak self] (_: RxTableViewDataSourceProxy, event) -> Void in
|
||||||
guard let tableView = self else {
|
guard let tableView = self else {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue