diff --git a/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerCombine.swift b/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerCombine.swift index 28e7a996..7b4dc69c 100644 --- a/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerCombine.swift +++ b/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerCombine.swift @@ -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 })) diff --git a/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerRx.swift b/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerRx.swift index d5dd632e..1fa3930f 100644 --- a/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerRx.swift +++ b/Examples/GithubBrowser/Source/UI/RepositoryListViewControllerRx.swift @@ -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) { - /* - 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) { + /* + 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" {