Skip to content

Instantly share code, notes, and snippets.

@CesarValiente
Last active March 24, 2018 18:48
Show Gist options
  • Save CesarValiente/ef856e3c801fdb0a648c1889c71ccb45 to your computer and use it in GitHub Desktop.
Save CesarValiente/ef856e3c801fdb0a648c1889c71ccb45 to your computer and use it in GitHub Desktop.
class ItemsControllerView(
val itemsViewCallback: WeakReference<ItemsViewCallback>,
store: Store,
mainThread: ThreadExecutor? = null)
: ControllerView(store, mainThread) {
fun fetchItems() =
store.dispatch(FetchItemsAction())
fun toEditItemScreen(item: Item) =
store.dispatch(EditItemScreenAction(item))
fun deleteItem(item: Item) =
store.dispatch(DeleteItemAction(item.localId))
override fun handleState(state: State) {
when (state.navigation) {
Navigation.ITEMS_LIST -> itemsViewCallback.get()?.updateItems(state.itemsListScreen.items)
Navigation.EDIT_ITEM -> itemsViewCallback.get()?.goToEditItem()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment