Remove type erasure from AnyBaseTableRow

Rename AnyBaseTableRow to SeparatorRowBox
This commit is contained in:
Anton Popkov 2017-10-12 15:14:43 +03:00
parent 763efd8968
commit 5102f4adf1
5 changed files with 18 additions and 42 deletions

View File

@ -402,10 +402,10 @@
A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A71F8A654600C6308D /* EmptyCellRow.swift */; };
A6E0DDDF1F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; };
A6E0DDE01F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; };
A6E0DDE11F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */; };
A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; };
A6E0DDE31F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; };
A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; };
A6E0DDE51F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */; };
A6E0DDE51F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; };
A6E0DDEF1F8A6C57002CA74E /* CellSeparatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */; };
A6E0DDF11F8A6C80002CA74E /* SeparatorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */; };
A6F32C081F6EBDAA00AC08EE /* String+LocalizedComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F32C071F6EBDAA00AC08EE /* String+LocalizedComponent.swift */; };
@ -605,7 +605,7 @@
A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCellViewModel.swift; sourceTree = "<group>"; };
A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = "<group>"; };
A66428A71F8A654600C6308D /* EmptyCellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellRow.swift; sourceTree = "<group>"; };
A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBaseTableRow.swift; sourceTree = "<group>"; };
A66428A81F8A655600C6308D /* SeparatorRowBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorRowBox.swift; sourceTree = "<group>"; };
A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellViewModel.swift; sourceTree = "<group>"; };
A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCell.swift; sourceTree = "<group>"; };
A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Extensions.swift"; sourceTree = "<group>"; };
@ -753,7 +753,7 @@
671461D41EB3396E00EAB194 /* Views */ = {
isa = PBXGroup;
children = (
A6AF3B381F8B957400CDB971 /* AnyBaseTableRow */,
A6AF3B381F8B957400CDB971 /* SeparatorRowBox */,
A66428A41F8A651700C6308D /* SeparatorCell */,
A6C9A4F71F8BBC0F009311CC /* EmptyCell */,
A6C9A4F81F8BBC27009311CC /* SpinnerView */,
@ -1273,12 +1273,12 @@
path = SeparatorCell;
sourceTree = "<group>";
};
A6AF3B381F8B957400CDB971 /* AnyBaseTableRow */ = {
A6AF3B381F8B957400CDB971 /* SeparatorRowBox */ = {
isa = PBXGroup;
children = (
A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */,
A66428A81F8A655600C6308D /* SeparatorRowBox.swift */,
);
path = AnyBaseTableRow;
path = SeparatorRowBox;
sourceTree = "<group>";
};
A6C9A4F71F8BBC0F009311CC /* EmptyCell */ = {
@ -2148,7 +2148,7 @@
671462581EB3396E00EAB194 /* Log.swift in Sources */,
671462B41EB3396E00EAB194 /* PaginationTableViewWrapperDelegate+DefaultImplementation.swift in Sources */,
671462781EB3396E00EAB194 /* ResizeContentMode.swift in Sources */,
A6E0DDE11F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */,
A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */,
A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */,
A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */,
671463041EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */,
@ -2228,7 +2228,7 @@
A6E0DDE31F8A696F002CA74E /* SeparatorCell.swift in Sources */,
A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */,
671463C41EB34B1E00EAB194 /* Post.swift in Sources */,
A6E0DDE51F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */,
A6E0DDE51F8A696F002CA74E /* SeparatorRowBox.swift in Sources */,
A6C9A5041F8BC78F009311CC /* CellSeparatorType.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@ -50,9 +50,9 @@ public final class EmptyCellRow: TableRow<EmptyCell> {
return item.height
}
/// EmptyCellRow typed as AnyBaseTableRow
public var anyRow: AnyBaseTableRow {
return AnyBaseTableRow(tableRow: self)
/// EmptyCellRow typed as SeparatorRowBox
public var separatorRowBox: SeparatorRowBox {
return SeparatorRowBox(tableRow: self)
}
}

View File

@ -22,43 +22,19 @@
import TableKit
/// Class used as general placeholder for type-erasured in TableRow<T>
private class AnyBaseTableRowHolder {
let row: Row
init(tableRow: Row) {
row = tableRow
}
}
/// Class used to hold resolved TableRow
private final class AnyBaseTableRowBox<T: ConfigurableCell>: AnyBaseTableRowHolder
where T: SeparatorCell, T.T: SeparatorCellViewModel {
init(tableRow: TableRow<T>) {
super.init(tableRow: tableRow)
}
}
/// Class that used to configure separators when multiply cells presented in one section
/// Holds TableRow<T> with any model inherited from BaseCellViewModel
public final class AnyBaseTableRow {
private let anyTableRow: AnyBaseTableRowHolder
public final class SeparatorRowBox {
/// Row `item`, that typed as BaseCellViewModel
public let viewModel: SeparatorCellViewModel
/// TableRow that typed to generic Row
public var row: Row {
return anyTableRow.row
}
public let row: Row
/// Initialize AnyBaseTableRow with tableRow
/// - parameter tableRow: TableRow which `item` conforms to BaseCellViewModel
public init<T>(tableRow: TableRow<T>) where T: SeparatorCell, T.T: SeparatorCellViewModel {
anyTableRow = AnyBaseTableRowBox(tableRow: tableRow)
row = tableRow
viewModel = tableRow.item
}

View File

@ -22,9 +22,9 @@
import TableKit
public extension Array where Element == AnyBaseTableRow {
public extension Array where Element == SeparatorRowBox {
/// Create rows from anyBaseTableRow array
/// Create rows from SeparatorRowBox array
var rows: [Row] {
return map { $0.row }
}

View File

@ -121,7 +121,7 @@ public extension TableDirector {
/// - parameter rows: Rows for configuration
/// - parameter extreme: Configuration that will be used for extreme values, for first or last row
/// - parameter middle: Configuration for intermediate rows
func configure(rows: [AnyBaseTableRow],
func configure(rows: [SeparatorRowBox],
extreme extremeSeparatorConfiguration: SeparatorConfiguration,
middle middleSeparatorConfiguration: SeparatorConfiguration) {