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
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