Last active
July 4, 2018 05:11
-
-
Save alfian0/ad5f98b3d66db9ef533f6755dbdb8854 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
final class ViewController: UITableViewController { | |
var viewModel: ViewModel! | |
let disposeBag = DisposeBag() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let input = viewModel.Input() | |
let output = viewModel.transform(input: input) | |
output.bind(to: tableView.rx.items(cellIdentifier: “Cell")) { row, item, cell in | |
cell.textLabel!?text = "\(item) @ row \(row)" | |
} | |
.disposed(by: disposeBag) | |
} | |
} |
This file contains hidden or 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
final class ViewModel: ViewModelType { | |
struct Input { | |
let text: Driver<String> | |
} | |
struct Output { | |
let items: Driver<[String]> | |
} | |
func transform(input: Input) -> Output { | |
let items = input | |
.orEmpty | |
.throttle(0.3, scheduler: Mainscheduler.instance) | |
.distinctUntilChanged() | |
.map{ ["1", "2", "3"] } | |
return Output(items: items) | |
} | |
} |
This file contains hidden or 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
protocol ViewModelType { | |
associatedtype Input | |
associatedtype Output | |
func transform(input: Input) -> Output | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment