Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Last active February 6, 2018 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ben-G/e30eb095e73c3c6d0ada3325c334480c to your computer and use it in GitHub Desktop.
Save Ben-G/e30eb095e73c3c6d0ada3325c334480c to your computer and use it in GitHub Desktop.
Reactive List Example
/// 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