Skip to content

Instantly share code, notes, and snippets.

@ElonPark
Created July 29, 2021 03:13
Show Gist options
  • Save ElonPark/5826d75b225749cc16b1a50f7e3e6f80 to your computer and use it in GitHub Desktop.
Save ElonPark/5826d75b225749cc16b1a50f7e3e6f80 to your computer and use it in GitHub Desktop.
bind Listener
// MARK: - Binding
private extension UserListViewController {
func bind(listener: UserListPresentableListener?) {
guard let listener = listener else { return }
bindActions(to: listener)
bindState(from: listener)
}
}
// MARK: - Binding Action
private extension UserListViewController {
func bindActions(to listener: UserListPresentableListener) {
bindItemSelectedAction(to: listener)
/* ... */
}
func bindItemSelectedAction(to listener: UserListPresentableListener) {
tableView.rx.itemSelected
.map { .itemSelected($0) }
.bind(to: listener.action)
.disposed(by: disposeBag)
}
/* ... */
}
// MARK: - Binding State
private extension UserListViewController {
func bindState(from listener: UserListPresentableListener) {
bindUserListSectionsState(from: listener)
/* ... */
}
func bindUserListSectionsState(from listener: UserListPresentableListener) {
listener.state.map(\.userListSections)
.distinctUntilChanged()
.asDriver(onErrorJustReturn: [])
.drive(tableView.rx.items(dataSource: dataSource()))
.disposed(by: disposeBag)
}
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment