Created
February 9, 2020 19:16
-
-
Save soxjke/71e374302f4737f88250a38424a75b13 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
| private(set) var searchTermThrottle = Throttler<String>(1.5) | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| searchField.addTarget(self, action: #selector(textDidChange(_:)), for: .editingChanged) | |
| searchTermThrottle.on { (searchTerm) in | |
| GithubAPI.search(term: searchTerm) { [weak self] result in | |
| switch (result) { | |
| case .success(let models): self?.onSuccess(models) | |
| case .failure(let error): self?.onError(error) | |
| } | |
| } | |
| } | |
| } | |
| @objc func textDidChange(_ sender: UITextField) { | |
| searchTermThrottle.receive(sender.text ?? "") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment