Last active
November 4, 2018 17:24
-
-
Save myeonginwoo/117164504632ad7a031218ca194b7e18 to your computer and use it in GitHub Desktop.
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
// 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