Skip to content

Commit

Permalink
comments in reactive examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian committed Sep 30, 2020
1 parent 4d9acca commit be08f64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ class RepositoryListViewController: UITableViewController {
- populate the table.
*/
repositories
// In this project we have an extension to tell Siesta's status overlay to be
// interested in the latest Resource output by a Resource publisher. The following
// line gives us a progress spinner, error display and retry functionality.
.watchedBy(statusOverlay: statusOverlay)

// Transform the sequence of Resources into a sequence of their content: [Repository].
.flatMapLatest { resource -> AnyPublisher<[Repository], Never> in
resource?.contentPublisher() ?? Just([]).eraseToAnyPublisher()
}

// This is everything we need to populate the table with the list of repos,
// courtesy of CombineDataSources.
.bind(subscriber: tableView.rowsSubscriber(cellIdentifier: "repo", cellType: RepositoryTableViewCell.self, cellConfig: { cell, indexPath, repo in
cell.repository = repo
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,31 @@ class RepositoryListViewController: UITableViewController {
Whether it's better to pass in a resource or an observable here is much the same argument as whether to define
APIs in terms of resources or observables. See UserViewController for a discussion about that.
*/
func configure(repositories: Observable<Resource? /* [Repository] */>) {
/*
Oh hey, in the next small handful of lines, let's:
- make an api call if necessary to fetch the latest repo list we're to show
- display progress and errors while doing that, and
- populate the table.
*/
repositories
.watchedBy(statusOverlay: statusOverlay)
.flatMapLatest { resource -> Observable<[Repository]> in
resource?.rx.content() ?? .just([])
}
.bind(to: tableView.rx.items(cellIdentifier: "repo", cellType: RepositoryTableViewCell.self)) {
(row, repo, cell) in
cell.repository = repo
}
.disposed(by: disposeBag)
}
func configure(repositories: Observable<Resource? /* [Repository] */>) {
/*
Oh hey, in the next small handful of lines, let's:
- make an api call if necessary to fetch the latest repo list we're to show
- display progress and errors while doing that, and
- populate the table.
*/
repositories
// In this project we have an extension to tell Siesta's status overlay to be
// interested in the latest Resource output by a Resource sequence. The following
// line gives us a progress spinner, error display and retry functionality.
.watchedBy(statusOverlay: statusOverlay)

// Transform the sequence of Resources into a sequence of their content: [Repository].
.flatMapLatest { resource -> Observable<[Repository]> in
resource?.rx.content() ?? .just([])
}

// This is everything we need to populate the table with the list of repos.
.bind(to: tableView.rx.items(cellIdentifier: "repo", cellType: RepositoryTableViewCell.self)) {
(row, repo, cell) in
cell.repository = repo
}
.disposed(by: disposeBag)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "repoDetail" {
Expand Down

0 comments on commit be08f64

Please sign in to comment.