Skip to content

Instantly share code, notes, and snippets.

@tsuharesu
Created January 5, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuharesu/1693b23b66fb632a07b1e1773ac50d1f to your computer and use it in GitHub Desktop.
Save tsuharesu/1693b23b66fb632a07b1e1773ac50d1f to your computer and use it in GitHub Desktop.
override fun start() {
program.accept(LoadLabelsMsg)
program.accept(LoadAccountsMsg)
}
override fun resume() {
}
override fun destroy() {
programDisposable.dispose()
}
override fun update(msg: Msg, state: State): Pair<State, Cmd> {
state as CreateTransactionState
return when (msg) {
is Init -> Pair(
state.copy(loadingAccounts = true, loadingCategories = true, loadingLabels = true),
BatchCmd(listOf(GetAccountsCmd, GetCategoriesCmd, GetLabelsCmd))
)
is LoadAccountsMsg ->
Pair(state.copy(loadingAccounts = true), GetAccountsCmd)
is AccountsLoadedMsg ->
Pair(state.copy(loadingAccounts = false, accounts = msg.accounts), None)
is LoadCategoriesMsg ->
Pair(state.copy(loadingCategories = true), GetCategoriesCmd)
is CategoriesLoadedMsg ->
Pair(state.copy(loadingCategories = false, categories = msg.categories), None)
is LoadLabelsMsg ->
Pair(state.copy(loadingLabels = true), GetLabelsCmd)
is LabelsLoadedMsg ->
Pair(state.copy(loadingLabels = false, labels = msg.labels), None)
else -> Pair(state, None)
}
}
override fun call(cmd: Cmd): Single<Msg> {
return when (cmd) {
is GetAccountsCmd -> getAccounts.execute().map { AccountsLoadedMsg(it) }
is GetCategoriesCmd -> getCategories.execute().map { CategoriesLoadedMsg(it) }
is GetLabelsCmd -> getLabels.execute().map { LabelsLoadedMsg(it) }
else -> Single.just(Idle)
}
}
override fun render(state: State) {
view.render(state as CreateTransactionState)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment