Skip to content

Commit

Permalink
Renames X -> More verbose.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaher committed Apr 27, 2019
1 parent 1fba558 commit 48b8d51
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 110 deletions.
2 changes: 1 addition & 1 deletion RxCocoa/Traits/ControlProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct ControlProperty<PropertyType> : ControlPropertyType {
/// - parameter valueSink: Observer that enables binding values to control property.
/// - returns: Control property created with a observable sequence of values and an observer that enables binding values
/// to property.
public init<V: ObservableType, S: ObserverType>(values: V, valueSink: S) where Element == V.Element, Element == S.Element {
public init<Values: ObservableType, Sink: ObserverType>(values: Values, valueSink: Sink) where Element == Values.Element, Element == Sink.Element {
self._values = values.subscribeOn(ConcurrentMainScheduler.instance)
self._valueSink = valueSink.asObserver()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ extension SharedSequenceConvertibleType {
- parameter keySelector: A function to compute the comparison key for each element.
- returns: An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.
*/
public func distinctUntilChanged<K: Equatable>(_ keySelector: @escaping (Element) -> K) -> SharedSequence<SharingStrategy, Element> {
public func distinctUntilChanged<Key: Equatable>(_ keySelector: @escaping (Element) -> Key) -> SharedSequence<SharingStrategy, Element> {
let source = self.asObservable()
.distinctUntilChanged(keySelector, comparer: { $0 == $1 })
return SharedSequence(source)
Expand Down
4 changes: 2 additions & 2 deletions RxCocoa/Traits/SharedSequence/SharedSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public struct SharedSequence<SharingStrategy: SharingStrategyProtocol, Element>
By defining `EXPANDABLE_SHARED_SEQUENCE` one agrees that it's up to him to ensure shared sequence
properties are preserved after extension.
*/
public static func createUnsafe<O: ObservableType>(source: O) -> SharedSequence<Sequence, O.Element> {
return SharedSequence<Sequence, O.Element>(raw: source.asObservable())
public static func createUnsafe<Source: ObservableType>(source: Source) -> SharedSequence<Sequence, Source.Element> {
return SharedSequence<Sequence, Source.Element>(raw: source.asObservable())
}
#endif

Expand Down
12 changes: 6 additions & 6 deletions RxCocoa/iOS/UICollectionView+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ extension Reactive where Base: UICollectionView {
}
.disposed(by: disposeBag)
*/
public func items<Sequence: Swift.Sequence, O: ObservableType>
(_ source: O)
public func items<Sequence: Swift.Sequence, Source: ObservableType>
(_ source: Source)
-> (_ cellFactory: @escaping (UICollectionView, Int, Sequence.Element) -> UICollectionViewCell)
-> Disposable where O.Element == Sequence {
-> Disposable where Source.Element == Sequence {
return { cellFactory in
let dataSource = RxCollectionViewReactiveArrayDataSourceSequenceWrapper<Sequence>(cellFactory: cellFactory)
return self.items(dataSource: dataSource)(source)
Expand Down Expand Up @@ -73,11 +73,11 @@ extension Reactive where Base: UICollectionView {
}
.disposed(by: disposeBag)
*/
public func items<Sequence: Swift.Sequence, Cell: UICollectionViewCell, O: ObservableType>
public func items<Sequence: Swift.Sequence, Cell: UICollectionViewCell, Source: ObservableType>
(cellIdentifier: String, cellType: Cell.Type = Cell.self)
-> (_ source: O)
-> (_ source: Source)
-> (_ configureCell: @escaping (Int, Sequence.Element, Cell) -> Void)
-> Disposable where O.Element == Sequence {
-> Disposable where Source.Element == Sequence {
return { source in
return { configureCell in
let dataSource = RxCollectionViewReactiveArrayDataSourceSequenceWrapper<Sequence> { cv, i, item in
Expand Down
24 changes: 12 additions & 12 deletions RxCocoa/iOS/UIPickerView+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
*/

public func itemTitles<Sequence: Swift.Sequence, O: ObservableType>
(_ source: O)
public func itemTitles<Sequence: Swift.Sequence, Source: ObservableType>
(_ source: Source)
-> (_ titleForRow: @escaping (Int, Sequence.Element) -> String?)
-> Disposable where O.Element == Sequence {
-> Disposable where Source.Element == Sequence {
return { titleForRow in
let adapter = RxStringPickerViewAdapter<Sequence>(titleForRow: titleForRow)
return self.items(adapter: adapter)(source)
Expand Down Expand Up @@ -137,10 +137,10 @@
*/

public func itemAttributedTitles<Sequence: Swift.Sequence, O: ObservableType>
(_ source: O)
public func itemAttributedTitles<Sequence: Swift.Sequence, Source: ObservableType>
(_ source: Source)
-> (_ attributedTitleForRow: @escaping (Int, Sequence.Element) -> NSAttributedString?)
-> Disposable where O.Element == Sequence {
-> Disposable where Source.Element == Sequence {
return { attributedTitleForRow in
let adapter = RxAttributedStringPickerViewAdapter<Sequence>(attributedTitleForRow: attributedTitleForRow)
return self.items(adapter: adapter)(source)
Expand Down Expand Up @@ -176,10 +176,10 @@
*/

public func items<Sequence: Swift.Sequence, O: ObservableType>
(_ source: O)
public func items<Sequence: Swift.Sequence, Source: ObservableType>
(_ source: Source)
-> (_ viewForRow: @escaping (Int, Sequence.Element, UIView?) -> UIView)
-> Disposable where O.Element == Sequence {
-> Disposable where Source.Element == Sequence {
return { viewForRow in
let adapter = RxPickerViewAdapter<Sequence>(viewForRow: viewForRow)
return self.items(adapter: adapter)(source)
Expand All @@ -197,10 +197,10 @@
- parameter source: Observable sequence of items.
- returns: Disposable object that can be used to unbind.
*/
public func items<O: ObservableType,
public func items<Source: ObservableType,
Adapter: RxPickerViewDataSourceType & UIPickerViewDataSource & UIPickerViewDelegate>(adapter: Adapter)
-> (_ source: O)
-> Disposable where O.Element == Adapter.Element {
-> (_ source: Source)
-> Disposable where Source.Element == Adapter.Element {
return { source in
let delegateSubscription = self.setDelegate(adapter)
let dataSourceSubscription = source.subscribeProxyDataSource(ofObject: self.base, dataSource: adapter, retainDataSource: true, binding: { [weak pickerView = self.base] (_: RxPickerViewDataSourceProxy, event) in
Expand Down
6 changes: 3 additions & 3 deletions RxCocoa/iOS/UITableView+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extension Reactive where Base: UITableView {
.disposed(by: disposeBag)
*/
public func items<Sequence: Swift.Sequence, O: ObservableType>
(_ source: O)
public func items<Sequence: Swift.Sequence, Source: ObservableType>
(_ source: Source)
-> (_ cellFactory: @escaping (UITableView, Int, Sequence.Element) -> UITableViewCell)
-> Disposable
where O.Element == Sequence {
where Source.Element == Sequence {
return { cellFactory in
let dataSource = RxTableViewReactiveArrayDataSourceSequenceWrapper<Sequence>(cellFactory: cellFactory)
return self.items(dataSource: dataSource)(source)
Expand Down
16 changes: 8 additions & 8 deletions RxExample/RxDataSources/Differentiator/Changeset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import Foundation

public struct Changeset<S: SectionModelType> {
public typealias I = S.Item
public struct Changeset<Section: SectionModelType> {
public typealias Item = Section.Item

public let reloadData: Bool

public let originalSections: [S]
public let finalSections: [S]
public let originalSections: [Section]
public let finalSections: [Section]

public let insertedSections: [Int]
public let deletedSections: [Int]
Expand All @@ -27,8 +27,8 @@ public struct Changeset<S: SectionModelType> {
public let updatedItems: [ItemPath]

init(reloadData: Bool = false,
originalSections: [S] = [],
finalSections: [S] = [],
originalSections: [Section] = [],
finalSections: [Section] = [],
insertedSections: [Int] = [],
deletedSections: [Int] = [],
movedSections: [(from: Int, to: Int)] = [],
Expand All @@ -55,8 +55,8 @@ public struct Changeset<S: SectionModelType> {
self.updatedItems = updatedItems
}

public static func initialValue(_ sections: [S]) -> Changeset<S> {
return Changeset<S>(
public static func initialValue(_ sections: [Section]) -> Changeset<Section> {
return Changeset<Section>(
reloadData: true,
finalSections: sections,
insertedSections: Array(0 ..< sections.count) as [Int]
Expand Down
59 changes: 25 additions & 34 deletions RxExample/RxDataSources/Differentiator/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ public enum Diff {
//
// There maybe exists a better division, but time will tell.
//
public static func differencesForSectionedView<S: AnimatableSectionModelType>(
initialSections: [S],
finalSections: [S])
throws -> [Changeset<S>] {
typealias I = S.Item
public static func differencesForSectionedView<Section: AnimatableSectionModelType>(
initialSections: [Section],
finalSections: [Section])
throws -> [Changeset<Section>] {
typealias Item = Section.Item

var result: [Changeset<S>] = []
var result: [Changeset<Section>] = []

var sectionCommands = try CommandGenerator<S>.generatorForInitialSections(initialSections, finalSections: finalSections)
var sectionCommands = try CommandGenerator<Section>.generatorForInitialSections(initialSections, finalSections: finalSections)

result.append(contentsOf: try sectionCommands.generateDeleteSectionsDeletedItemsAndUpdatedItems())
result.append(contentsOf: try sectionCommands.generateInsertAndMoveSections())
Expand All @@ -370,20 +370,11 @@ public enum Diff {
return result
}

private struct CommandGenerator<Section: AnimatableSectionModelType> {
typealias Item = Section.Item

@available(*, deprecated, renamed: "differencesForSectionedView(initialSections:finalSections:)")
public static func differencesForSectionedView<S: AnimatableSectionModelType>(
_ initialSections: [S],
finalSections: [S])
throws -> [Changeset<S>] {
return try differencesForSectionedView(initialSections: initialSections, finalSections: finalSections)
}

private struct CommandGenerator<S: AnimatableSectionModelType> {
typealias Item = S.Item

let initialSections: [S]
let finalSections: [S]
let initialSections: [Section]
let finalSections: [Section]

let initialSectionData: ContiguousArray<SectionAssociatedData>
let finalSectionData: ContiguousArray<SectionAssociatedData>
Expand All @@ -395,9 +386,9 @@ public enum Diff {
let finalItemCache: ContiguousArray<ContiguousArray<Item>>

static func generatorForInitialSections(
_ initialSections: [S],
finalSections: [S]
) throws -> CommandGenerator<S> {
_ initialSections: [Section],
finalSections: [Section]
) throws -> CommandGenerator<Section> {

let (initialSectionData, finalSectionData) = try calculateSectionMovements(initialSections: initialSections, finalSections: finalSections)

Expand All @@ -416,7 +407,7 @@ public enum Diff {
finalSectionData: finalSectionData
)

return CommandGenerator<S>(
return CommandGenerator<Section>(
initialSections: initialSections,
finalSections: finalSections,

Expand Down Expand Up @@ -525,7 +516,7 @@ public enum Diff {
return (initialItemData, finalItemData)
}

static func calculateSectionMovements(initialSections: [S], finalSections: [S]) throws
static func calculateSectionMovements(initialSections: [Section], finalSections: [Section]) throws
-> (ContiguousArray<SectionAssociatedData>, ContiguousArray<SectionAssociatedData>) {

let initialSectionIndexes = try Diff.indexSections(initialSections)
Expand Down Expand Up @@ -608,13 +599,13 @@ public enum Diff {
return (initialSectionData, finalSectionData)
}

mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset<S>] {
mutating func generateDeleteSectionsDeletedItemsAndUpdatedItems() throws -> [Changeset<Section>] {
var deletedSections = [Int]()

var deletedItems = [ItemPath]()
var updatedItems = [ItemPath]()

var afterDeleteState = [S]()
var afterDeleteState = [Section]()

// mark deleted items {
// 1rst stage again (I know, I know ...)
Expand All @@ -629,7 +620,7 @@ public enum Diff {
continue
}

var afterDeleteItems: [S.Item] = []
var afterDeleteItems: [Section.Item] = []
for j in 0 ..< initialItems.count {
let event = initialItemData[i][j].event
switch event {
Expand All @@ -647,7 +638,7 @@ public enum Diff {
}
}

afterDeleteState.append(try S.init(safeOriginal: initialSections[i], safeItems: afterDeleteItems))
afterDeleteState.append(try Section.init(safeOriginal: initialSections[i], safeItems: afterDeleteItems))
}
// }

Expand All @@ -663,7 +654,7 @@ public enum Diff {
)]
}

func generateInsertAndMoveSections() throws -> [Changeset<S>] {
func generateInsertAndMoveSections() throws -> [Changeset<Section>] {

var movedSections = [(from: Int, to: Int)]()
var insertedSections = [Int]()
Expand Down Expand Up @@ -695,7 +686,7 @@ public enum Diff {
}

// sections should be in place, but items should be original without deleted ones
let sectionsAfterChange: [S] = try self.finalSections.enumerated().map { i, s -> S in
let sectionsAfterChange: [Section] = try self.finalSections.enumerated().map { i, s -> Section in
let event = self.finalSectionData[i].event

if event == .inserted {
Expand All @@ -706,7 +697,7 @@ public enum Diff {
let originalSectionIndex = try finalSectionData[i].moveIndex.unwrap()
let originalSection = initialSections[originalSectionIndex]

var items: [S.Item] = []
var items: [Section.Item] = []
items.reserveCapacity(originalSection.items.count)
let itemAssociatedData = self.initialItemData[originalSectionIndex]
for j in 0 ..< originalSection.items.count {
Expand All @@ -724,7 +715,7 @@ public enum Diff {
items.append(finalItemCache[finalIndex.sectionIndex][finalIndex.itemIndex])
}

let modifiedSection = try S.init(safeOriginal: s, safeItems: items)
let modifiedSection = try Section.init(safeOriginal: s, safeItems: items)

return modifiedSection
}
Expand All @@ -741,7 +732,7 @@ public enum Diff {
)]
}

mutating func generateInsertAndMovedItems() throws -> [Changeset<S>] {
mutating func generateInsertAndMovedItems() throws -> [Changeset<Section>] {
var insertedItems = [ItemPath]()
var movedItems = [(from: ItemPath, to: ItemPath)]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ import Foundation
import UIKit
import RxCocoa

open class TableViewSectionedDataSource<S: SectionModelType>
open class TableViewSectionedDataSource<Section: SectionModelType>
: NSObject
, UITableViewDataSource
, SectionedViewDataSourceType {

public typealias I = S.Item
public typealias Section = S
public typealias Item = Section.Item

public typealias ConfigureCell = (TableViewSectionedDataSource<S>, UITableView, IndexPath, I) -> UITableViewCell
public typealias TitleForHeaderInSection = (TableViewSectionedDataSource<S>, Int) -> String?
public typealias TitleForFooterInSection = (TableViewSectionedDataSource<S>, Int) -> String?
public typealias CanEditRowAtIndexPath = (TableViewSectionedDataSource<S>, IndexPath) -> Bool
public typealias CanMoveRowAtIndexPath = (TableViewSectionedDataSource<S>, IndexPath) -> Bool
public typealias ConfigureCell = (TableViewSectionedDataSource<Section>, UITableView, IndexPath, Item) -> UITableViewCell
public typealias TitleForHeaderInSection = (TableViewSectionedDataSource<Section>, Int) -> String?
public typealias TitleForFooterInSection = (TableViewSectionedDataSource<Section>, Int) -> String?
public typealias CanEditRowAtIndexPath = (TableViewSectionedDataSource<Section>, IndexPath) -> Bool
public typealias CanMoveRowAtIndexPath = (TableViewSectionedDataSource<Section>, IndexPath) -> Bool

#if os(iOS)
public typealias SectionIndexTitles = (TableViewSectionedDataSource<S>) -> [String]?
public typealias SectionForSectionIndexTitle = (TableViewSectionedDataSource<S>, _ title: String, _ index: Int) -> Int
public typealias SectionIndexTitles = (TableViewSectionedDataSource<Section>) -> [String]?
public typealias SectionForSectionIndexTitle = (TableViewSectionedDataSource<Section>, _ title: String, _ index: Int) -> Int
#endif

#if os(iOS)
Expand Down Expand Up @@ -83,20 +82,20 @@ open class TableViewSectionedDataSource<S: SectionModelType>
// and their relationship with section.
// If particular item is mutable, that is irrelevant for this logic to function
// properly.
public typealias SectionModelSnapshot = SectionModel<S, I>
public typealias SectionModelSnapshot = SectionModel<Section, Item>

private var _sectionModels: [SectionModelSnapshot] = []

open var sectionModels: [S] {
open var sectionModels: [Section] {
return _sectionModels.map { Section(original: $0.model, items: $0.items) }
}

open subscript(section: Int) -> S {
open subscript(section: Int) -> Section {
let sectionModel = self._sectionModels[section]
return S(original: sectionModel.model, items: sectionModel.items)
return Section(original: sectionModel.model, items: sectionModel.items)
}

open subscript(indexPath: IndexPath) -> I {
open subscript(indexPath: IndexPath) -> Item {
get {
return self._sectionModels[indexPath.section].items[indexPath.item]
}
Expand All @@ -111,7 +110,7 @@ open class TableViewSectionedDataSource<S: SectionModelType>
return self[indexPath]
}

open func setSections(_ sections: [S]) {
open func setSections(_ sections: [Section]) {
self._sectionModels = sections.map { SectionModelSnapshot(model: $0, items: $0.items) }
}

Expand Down
Loading

0 comments on commit 48b8d51

Please sign in to comment.