Skip to content

Instantly share code, notes, and snippets.

@myeonginwoo
Last active November 4, 2018 17:24
Show Gist options
  • Save myeonginwoo/117164504632ad7a031218ca194b7e18 to your computer and use it in GitHub Desktop.
Save myeonginwoo/117164504632ad7a031218ca194b7e18 to your computer and use it in GitHub Desktop.
// before
class MainViewModel(val view: MainView) {
private var currentItem: Item by Delegates.observable(Item.ITEM_A,
{ _: KProperty<*>, oldItem: Item, newItem: Item ->
view.onUpdatedItem(oldItem, newItem)
})
fun onClicked(item: Item) {
currentItem = item
}
}
// after
class MainViewModel(val view: MainView, val dataStore: DataStore) {
private var currentItem: Item by Delegates.observable(Item("kotlin", "#FF0000"),
{ _: KProperty<*>, oldItem: Item, newItem: Item ->
view.onUpdatedItem(oldItem, newItem)
})
fun requestItemInfo(itemType: ItemType) {
view.showProgress()
try {
currentItem = dataStore.getItemInfo(itemType)
} catch (error: Throwable?) {
view.onError(error)
} finally {
view.hideProgress()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment