Created
July 29, 2021 03:13
-
-
Save ElonPark/5826d75b225749cc16b1a50f7e3e6f80 to your computer and use it in GitHub Desktop.
bind Listener
This file contains 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
// 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