Last active
February 6, 2018 19:09
-
-
Save Ben-G/e30eb095e73c3c6d0ada3325c334480c to your computer and use it in GitHub Desktop.
Reactive List Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Pure function mapping new state to a new `TableViewModel`. This is invoked each time the state updates | |
/// in order for ReactiveLists to update the UI. | |
static func viewModel(forState groups: [ToolGroup]) -> TableViewModel { | |
// Create a section for every tool group | |
let sections: [TableSectionViewModel] = groups.map { group in | |
// Create a single cell for every tool | |
let cellViewModels = group.tools.map { ToolTableCellModel(tool: $0) } | |
return TableSectionViewModel( | |
headerTitle: group.name, | |
headerHeight: 44, | |
cellViewModels: cellViewModels, | |
diffingKey: group.name | |
) | |
} | |
return TableViewModel(sectionModels: sections) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment