Created
December 7, 2017 18:41
-
-
Save joshuawright11/2e22217a3c7643bae61997f9bcbd371b 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
class TransactionStore { | |
var shared: TransactionStore = TransactionStore() | |
var transactions: Variable<[Transaction]> | |
} | |
// ViewModel | |
class Presenter { | |
var monthsOfDataBeforeToday: Variable<Int> = ... | |
var transactions: Observable<[Transaction]> { | |
return Observable.combineLatest(TransactionStore.shared.transactions.asObservable(), monthsOfDataBeforeToday.asObservable()){ (transactions, months) | |
return transactions.filter(months) // write a real filter function with `months` variable | |
} | |
} | |
} | |
class ViewController: UIViewController { | |
var presenter = Presenter() | |
func viewDidLoad() { | |
... | |
presenter.transactions.subscribe(onNext: { transactions in | |
// reloadview | |
}) | |
} | |
func segmentedControlSelected(index: Int) { | |
presenter.monthsOfDataBeforeToday.value = [4, 6, 12][index] | |
// now view will auto reload cause setting this will trigger presenter.transactions onnext | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment