mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-05 06:27:29 +03:00
Replaces model(_:)
with model(at:)
.
This commit is contained in:
parent
a7b8c11b40
commit
02c63a4f56
@ -20,20 +20,5 @@ public protocol SectionedViewDataSourceType {
|
||||
- parameter indexPath: Model index path
|
||||
- returns: Model at index path.
|
||||
*/
|
||||
func model(_ indexPath: IndexPath) throws -> Any
|
||||
}
|
||||
|
||||
extension SectionedViewDataSourceType {
|
||||
/**
|
||||
Returns model at index path.
|
||||
|
||||
In case data source doesn't contain any sections when this method is being called, `RxCocoaError.ItemsNotYetBound(object: self)` is thrown.
|
||||
|
||||
- parameter indexPath: Model index path
|
||||
- returns: Model at index path.
|
||||
*/
|
||||
@available(*, deprecated, renamed: "model(_:)")
|
||||
func modelAtIndexPath(_ indexPath: IndexPath) throws -> Any {
|
||||
return try self.model(indexPath)
|
||||
}
|
||||
func model(at indexPath: IndexPath) throws -> Any
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class RxCollectionViewReactiveArrayDataSource<Element>
|
||||
return itemModels?[index]
|
||||
}
|
||||
|
||||
func model(_ indexPath: IndexPath) throws -> Any {
|
||||
func model(at indexPath: IndexPath) throws -> Any {
|
||||
precondition(indexPath.section == 0)
|
||||
guard let item = itemModels?[indexPath.item] else {
|
||||
throw RxCocoaError.itemsNotYetBound(object: self)
|
||||
|
@ -70,7 +70,7 @@ class RxTableViewReactiveArrayDataSource<Element>
|
||||
return itemModels?[index]
|
||||
}
|
||||
|
||||
func model(_ indexPath: IndexPath) throws -> Any {
|
||||
func model(at indexPath: IndexPath) throws -> Any {
|
||||
precondition(indexPath.section == 0)
|
||||
guard let item = itemModels?[indexPath.item] else {
|
||||
throw RxCocoaError.itemsNotYetBound(object: self)
|
||||
|
@ -249,7 +249,7 @@ extension Reactive where Base: UICollectionView {
|
||||
return Observable.empty()
|
||||
}
|
||||
|
||||
return Observable.just(try view.rx.model(indexPath))
|
||||
return Observable.just(try view.rx.model(at: indexPath))
|
||||
}
|
||||
|
||||
return ControlEvent(events: source)
|
||||
@ -272,7 +272,7 @@ extension Reactive where Base: UICollectionView {
|
||||
return Observable.empty()
|
||||
}
|
||||
|
||||
return Observable.just(try view.rx.model(indexPath))
|
||||
return Observable.just(try view.rx.model(at: indexPath))
|
||||
}
|
||||
|
||||
return ControlEvent(events: source)
|
||||
@ -281,10 +281,10 @@ extension Reactive where Base: UICollectionView {
|
||||
/**
|
||||
Syncronous helper method for retrieving a model at indexPath through a reactive data source
|
||||
*/
|
||||
public func model<T>(_ indexPath: IndexPath) throws -> T {
|
||||
public func model<T>(at indexPath: IndexPath) throws -> T {
|
||||
let dataSource: SectionedViewDataSourceType = castOrFatalError(self.dataSource.forwardToDelegate(), message: "This method only works in case one of the `rx.itemsWith*` methods was used.")
|
||||
|
||||
let element = try dataSource.model(indexPath)
|
||||
let element = try dataSource.model(at: indexPath)
|
||||
|
||||
return element as! T
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ extension Reactive where Base: UITableView {
|
||||
return Observable.empty()
|
||||
}
|
||||
|
||||
return Observable.just(try view.rx.model(indexPath))
|
||||
return Observable.just(try view.rx.model(at: indexPath))
|
||||
}
|
||||
|
||||
return ControlEvent(events: source)
|
||||
@ -356,7 +356,7 @@ extension Reactive where Base: UITableView {
|
||||
return Observable.empty()
|
||||
}
|
||||
|
||||
return Observable.just(try view.rx.model(indexPath))
|
||||
return Observable.just(try view.rx.model(at: indexPath))
|
||||
}
|
||||
|
||||
return ControlEvent(events: source)
|
||||
@ -365,10 +365,10 @@ extension Reactive where Base: UITableView {
|
||||
/**
|
||||
Synchronous helper method for retrieving a model at indexPath through a reactive data source.
|
||||
*/
|
||||
public func model<T>(_ indexPath: IndexPath) throws -> T {
|
||||
public func model<T>(at indexPath: IndexPath) throws -> T {
|
||||
let dataSource: SectionedViewDataSourceType = castOrFatalError(self.dataSource.forwardToDelegate(), message: "This method only works in case one of the `rx.items*` methods was used.")
|
||||
|
||||
let element = try dataSource.model(indexPath)
|
||||
let element = try dataSource.model(at: indexPath)
|
||||
|
||||
return castOrFatalError(element)
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
|
||||
}
|
||||
}
|
||||
|
||||
public func model(_ indexPath: IndexPath) throws -> Any {
|
||||
public func model(at indexPath: IndexPath) throws -> Any {
|
||||
return self[indexPath]
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
|
||||
}
|
||||
}
|
||||
|
||||
public func model(_ indexPath: IndexPath) throws -> Any {
|
||||
public func model(at indexPath: IndexPath) throws -> Any {
|
||||
return self[indexPath]
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import UIKit
|
||||
super.init()
|
||||
}
|
||||
|
||||
func model(_ indexPath: IndexPath) throws -> Any {
|
||||
func model(at indexPath: IndexPath) throws -> Any {
|
||||
return items![indexPath.item]
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ class UICollectionViewTests : RxTest {
|
||||
}
|
||||
let (collectionView, dataSourceSubscription) = createView()
|
||||
|
||||
let model: Int = try! collectionView.rx.model(IndexPath(item: 1, section: 0))
|
||||
let model: Int = try! collectionView.rx.model(at: IndexPath(item: 1, section: 0))
|
||||
|
||||
XCTAssertEqual(model, 2)
|
||||
|
||||
|
@ -352,7 +352,7 @@ class UITableViewTests : RxTest {
|
||||
|
||||
let (tableView, dataSourceSubscription) = createView()
|
||||
|
||||
let model: Int = try! tableView.rx.model(IndexPath(item: 1, section: 0))
|
||||
let model: Int = try! tableView.rx.model(at: IndexPath(item: 1, section: 0))
|
||||
|
||||
XCTAssertEqual(model, 2)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user