Updates data sources.

This commit is contained in:
Krunoslav Zaher 2016-03-22 11:20:10 +01:00
parent 9e8bb711ab
commit 834cd872f5
11 changed files with 52 additions and 34 deletions

View File

@ -23,10 +23,12 @@ extension UITableView {
O.E == [Section]
>
(dataSource: DataSource)
(source: O)
-> (source: O)
-> Disposable {
let differences = source.differentiateForSectionedView()
return self.rx_itemsWithDataSource(dataSource)(source: differences)
return { source in
let differences = source.differentiateForSectionedView()
return self.rx_itemsWithDataSource(dataSource)(source: differences)
}
}
}
@ -40,9 +42,11 @@ extension UICollectionView {
O.E == [Section]
>
(dataSource: DataSource)
(source: O)
-> (source: O)
-> Disposable {
let differences = source.differentiateForSectionedView()
return self.rx_itemsWithDataSource(dataSource)(source: differences)
return { source in
let differences = source.differentiateForSectionedView()
return self.rx_itemsWithDataSource(dataSource)(source: differences)
}
}
}

View File

@ -12,7 +12,7 @@ public struct AnimatableSectionModel<Section: Hashable, ItemType: Hashable>
: Hashable
, AnimatableSectionModelType
, CustomStringConvertible {
public typealias Item = IdentitifiableValue<ItemType>
public typealias Item = IdentifiableValue<ItemType>
public typealias Identity = Section
public var model: Section
@ -25,7 +25,7 @@ public struct AnimatableSectionModel<Section: Hashable, ItemType: Hashable>
public init(model: Section, items: [ItemType]) {
self.model = model
self.items = items.map(IdentitifiableValue.init)
self.items = items.map(IdentifiableValue.init)
}
public init(original: AnimatableSectionModel, items: [Item]) {

View File

@ -11,7 +11,7 @@ import Foundation
public protocol AnimatableSectionModelType
: SectionModelType
, IdentifiableType {
typealias Item : IdentifiableType, Equatable
associatedtype Item : IdentifiableType, Equatable
init(original: Self, items: [Item])
}

View File

@ -8,9 +8,7 @@
import Foundation
import UIKit
#if !RX_NO_MODULE
import RxCocoa
#endif
import RxCocoa
public class _CollectionViewSectionedDataSource
: NSObject
@ -144,13 +142,18 @@ public class CollectionViewSectionedDataSource<S: SectionModelType>
}
override func _collectionView(collectionView: UICollectionView, canMoveItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return canMoveItemAtIndexPath?(self, indexPath: indexPath) ??
super._collectionView(collectionView, canMoveItemAtIndexPath: indexPath)
guard let canMoveItem = canMoveItemAtIndexPath?(self, indexPath: indexPath) else {
return super._collectionView(collectionView, canMoveItemAtIndexPath: indexPath)
}
return canMoveItem
}
override func _collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
return moveItem?(self, sourceIndexPath:sourceIndexPath, destinationIndexPath: destinationIndexPath) ??
guard let _ = moveItem?(self, sourceIndexPath:sourceIndexPath, destinationIndexPath: destinationIndexPath) else {
super._collectionView(collectionView, moveItemAtIndexPath: sourceIndexPath, toIndexPath: destinationIndexPath)
return
}
}
}

View File

@ -9,7 +9,7 @@
import Foundation
public protocol IdentifiableType {
typealias Identity: Hashable
associatedtype Identity: Hashable
var identity : Identity { get }
}

View File

@ -8,7 +8,7 @@
import Foundation
public struct IdentitifiableValue<Value: Hashable>
public struct IdentifiableValue<Value: Hashable>
: IdentifiableType
, Equatable
, CustomStringConvertible
@ -30,6 +30,6 @@ public struct IdentitifiableValue<Value: Hashable>
}
}
public func == <V: Hashable>(lhs: IdentitifiableValue<V>, rhs: IdentitifiableValue<V>) -> Bool {
public func == <V: Hashable>(lhs: IdentifiableValue<V>, rhs: IdentifiableValue<V>) -> Bool {
return lhs.value == rhs.value
}

View File

@ -8,9 +8,7 @@
import Foundation
import UIKit
#if !RX_NO_MODULE
import RxCocoa
#endif
import RxCocoa
// objc monkey business
public class _TableViewSectionedDataSource
@ -179,22 +177,35 @@ public class RxTableViewSectionedDataSource<S: SectionModelType>
}
override func _tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return canEditRowAtIndexPath?(self, indexPath: indexPath) ??
super._tableView(tableView, canMoveRowAtIndexPath: indexPath)
guard let canEditRow = canEditRowAtIndexPath?(self, indexPath: indexPath) else {
return super._tableView(tableView, canMoveRowAtIndexPath: indexPath)
}
return canEditRow
}
override func _tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return canMoveRowAtIndexPath?(self, indexPath: indexPath) ??
super._tableView(tableView, canMoveRowAtIndexPath: indexPath)
guard let canMoveRow = canMoveRowAtIndexPath?(self, indexPath: indexPath) else {
return super._tableView(tableView, canMoveRowAtIndexPath: indexPath)
}
return canMoveRow
}
override func _sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return sectionIndexTitles?(self) ?? super._sectionIndexTitlesForTableView(tableView)
guard let titles = sectionIndexTitles?(self) else {
return super._sectionIndexTitlesForTableView(tableView)
}
return titles
}
override func _tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return sectionForSectionIndexTitle?(self, title: title, index: index) ??
super._tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
guard let section = sectionForSectionIndexTitle?(self, title: title, index: index) else {
return super._tableView(tableView, sectionForSectionIndexTitle: title, atIndex: index)
}
return section
}
}

View File

@ -19,7 +19,7 @@ import Foundation
let MB = 1024 * 1024
func exampleError(error: String, location: String = "\(__FILE__):\(__LINE__)") -> NSError {
func exampleError(error: String, location: String = "\(#file):\(#line)") -> NSError {
return NSError(domain: "ExampleError", code: -1, userInfo: [NSLocalizedDescriptionKey: "\(location): \(error)"])
}

View File

@ -202,7 +202,7 @@ extension GitHubSearchRepositoriesAPI {
let range = m.rangeAtIndex(rangeIndex)
let startIndex = links.startIndex.advancedBy(range.location)
let endIndex = startIndex.advancedBy(range.length)
let stringRange = Range(start: startIndex, end: endIndex)
let stringRange = startIndex ..< endIndex
return links.substringWithRange(stringRange)
}

View File

@ -74,7 +74,7 @@ class Randomizer {
if rng.get_random() % 2 == 0 {
let itemIndex = rng.get_random() % (itemCount + 1)
if insertItems {
sections[sectionIndex].items.insert(IdentitifiableValue(value: unusedValue), atIndex: itemIndex)
sections[sectionIndex].items.insert(IdentifiableValue(value: unusedValue), atIndex: itemIndex)
}
else {
nextUnusedItems.append(unusedValue)
@ -83,14 +83,14 @@ class Randomizer {
// update
else {
if itemCount == 0 {
sections[sectionIndex].items.insert(IdentitifiableValue(value: unusedValue), atIndex: 0)
sections[sectionIndex].items.insert(IdentifiableValue(value: unusedValue), atIndex: 0)
continue
}
let itemIndex = rng.get_random() % itemCount
if reloadItems {
nextUnusedItems.append(sections[sectionIndex].items.removeAtIndex(itemIndex).value)
sections[sectionIndex].items.insert(IdentitifiableValue(value: unusedValue), atIndex: itemIndex)
sections[sectionIndex].items.insert(IdentifiableValue(value: unusedValue), atIndex: itemIndex)
}
else {

View File

@ -21,7 +21,7 @@ extension ObservableType {
- returns: An observable sequence whose events are printed to standard output.
*/
@warn_unused_result(message="http://git.io/rxs.uo")
public func debug(identifier: String? = nil, file: String = __FILE__, line: UInt = __LINE__, function: String = __FUNCTION__)
public func debug(identifier: String? = nil, file: String = #file, line: UInt = #line, function: String = #function)
-> Observable<E> {
return Debug(source: self.asObservable(), identifier: identifier, file: file, line: line, function: function)
}