Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TableSectionViewModel.collapsed, close #120 #121

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ The changelog for `ReactiveLists`. Also see the [releases](https://github.com/pl

------

0.1.2
0.1.2 (NEXT RELEASE)
-----

### Breaking

- Removed `TableSectionViewModel.collapsed` ([#120](https://github.com/plangrid/ReactiveLists/pull/120), [@jessesquires](https://github.com/jessesquires))

### Changed

- Section and cell view models are now diffable by default. ([#119](https://github.com/plangrid/ReactiveLists/pull/119), [@jessesquires](https://github.com/jessesquires))
Expand Down
2 changes: 1 addition & 1 deletion Sources/TableViewDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extension TableViewDriver: UITableViewDataSource {

/// :nodoc:
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let sectionModel = self.tableViewModel?[section], !sectionModel.collapsed else { return 0 }
guard let sectionModel = self.tableViewModel?[section] else { return 0 }
return sectionModel.cellViewModels.count
}

Expand Down
6 changes: 0 additions & 6 deletions Sources/TableViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ public struct TableSectionViewModel: DiffableViewModel {
/// View model for the footer of this section.
public let footerViewModel: TableSectionHeaderFooterViewModel?

/// Indicates whether or not this section is collapsed.
public var collapsed: Bool = false

/// The key used by the diffing algorithm to uniquely identify this section.
/// If you are using automatic diffing on the `TableViewDriver` (which is enabled by default)
/// you are required to provide a key that uniquely identifies this section.
Expand All @@ -149,18 +146,15 @@ public struct TableSectionViewModel: DiffableViewModel {
/// - cellViewModels: The cell view models contained in this section.
/// - headerViewModel: A header view model for this section (defaults to `nil`).
/// - footerViewModel: A footer view model for this section (defaults to `nil`).
/// - collapsed: Whether or not this section is collapsed (defaults to `false`).
/// - diffingKey: A diffing key.
public init(
cellViewModels: [TableCellViewModel],
headerViewModel: TableSectionHeaderFooterViewModel? = nil,
footerViewModel: TableSectionHeaderFooterViewModel? = nil,
collapsed: Bool = false,
diffingKey: String = UUID().uuidString) {
self.cellViewModels = cellViewModels
self.headerViewModel = headerViewModel
self.footerViewModel = footerViewModel
self.collapsed = collapsed
self.diffingKey = diffingKey
}

Expand Down
15 changes: 5 additions & 10 deletions Tests/TableView/TableViewDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,24 @@ final class TableViewDriverTests: XCTestCase {
TableSectionViewModel(
cellViewModels: [],
headerViewModel: TestHeaderFooterViewModel(height: 10, viewKind: .header, label: "A"),
footerViewModel: TestHeaderFooterViewModel(height: 11, viewKind: .footer, label: "A"),
collapsed: false),
footerViewModel: TestHeaderFooterViewModel(height: 11, viewKind: .footer, label: "A")),
TableSectionViewModel(
cellViewModels: ["A", "B", "C"].map { _generateTestCellViewModel($0) },
headerViewModel: nil,
footerViewModel: TestHeaderFooterViewModel(title: "footer_2", height: 21),
collapsed: false),
footerViewModel: TestHeaderFooterViewModel(title: "footer_2", height: 21)),
TableSectionViewModel(
cellViewModels: ["D", "E", "F"].map { _generateTestCellViewModel($0) },
headerViewModel: TestHeaderFooterViewModel(title: "header_3", height: 30),
footerViewModel: nil,
collapsed: true),
footerViewModel: nil),
], sectionIndexTitles: ["A", "Z", "Z"])
self._tableViewDataSource = TableViewDriver(
tableView: tableView,
automaticDiffingEnabled: false
)
automaticDiffingEnabled: false)
self._tableViewDataSource.tableViewModel = self._tableViewModel
}

/// Table view sections described in the table view model are converted into views correctly.
func testTableViewSections() {

XCTAssertEqual(self._tableViewDataSource.sectionIndexTitles(for: self._tableView)!, ["A", "Z", "Z"])

XCTAssertEqual(self._tableViewDataSource.numberOfSections(in: self._tableView), 3)
Expand All @@ -81,7 +76,7 @@ final class TableViewDriverTests: XCTestCase {
XCTAssertEqual(self._tableViewDataSource.tableView(self._tableView, titleForFooterInSection: $0), $1)
}

parameterize(cases: (0, 0), (1, 3), (2, 0), (9, 0)) {
parameterize(cases: (0, 0), (1, 3), (2, 3), (9, 0)) {
XCTAssertEqual(self._tableViewDataSource.tableView(self._tableView, numberOfRowsInSection: $0), $1)
}
}
Expand Down
7 changes: 1 addition & 6 deletions Tests/TableView/TableViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ final class TableViewModelTests: XCTestCase {
XCTAssertEqual(sectionModel.cellViewModels.count, 1)
XCTAssertEqual(sectionModel.headerViewModel?.height, 42)
XCTAssertEqual(sectionModel.footerViewModel?.height, 43)
XCTAssertFalse(sectionModel.collapsed)
XCTAssertEqual(sectionModel.headerViewModel?.title, "foo")
XCTAssertEqual(sectionModel.footerViewModel?.title, "bar")
XCTAssertNil(sectionModel.headerViewModel?.viewInfo)
Expand All @@ -93,9 +92,7 @@ final class TableViewModelTests: XCTestCase {
let sectionModel = TableSectionViewModel(
cellViewModels: [generateTestCellViewModel()],
headerViewModel: TestHeaderFooterViewModel(height: 42, viewKind: .header, label: "A"),
footerViewModel: TestHeaderFooterViewModel(height: 43, viewKind: .footer, label: "A"),
collapsed: true
)
footerViewModel: TestHeaderFooterViewModel(height: 43, viewKind: .footer, label: "A"))

XCTAssertEqual(sectionModel.cellViewModels.count, 1)
XCTAssertEqual(sectionModel.headerViewModel?.height, 42)
Expand All @@ -106,7 +103,6 @@ final class TableViewModelTests: XCTestCase {
let headerInfo = sectionModel.headerViewModel?.viewInfo
let footerInfo = sectionModel.footerViewModel?.viewInfo

XCTAssertTrue(sectionModel.collapsed)
XCTAssertTrue(headerInfo?.registrationInfo.registrationMethod == .fromClass(HeaderView.self))
XCTAssertTrue(footerInfo?.registrationInfo.registrationMethod == .fromClass(FooterView.self))
XCTAssertEqual(headerInfo?.registrationInfo.reuseIdentifier, "HeaderView")
Expand All @@ -120,5 +116,4 @@ final class TableViewModelTests: XCTestCase {
"access_footer+44"
)
}

}