New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration with unidirectional/mvi architecture #157
Comments
Could you give an example of what you mean by an unidirectional/mvi architecture? I'm unfamiliar with it. |
Thanks @nhaarman. A bunch of Android presentation layer frameworks that support unidirectional/mvi architecture have sprung up over the last couple of years. I think this may be the post that kicked it all off. They're all based on some interpretation of Flux/Redux from web-land. It conceives of state as immutable and models the app (or parts of it) as a state-machine. In functional programming terms, I think it's an interpretation and elaboration of the State monad. Some Android implementations are Mobius from Spotify and MvRx from AirBnB. |
@lgtout I used MvRx before switching from fragments to Acorn. That library can't be adapted to Acorn components because it's strictly coupled to fragments and viewmodels. Anyway you can do something similar // You can easily pass a mock container for testing purpose
interface MyContainer : Container {
val events: Flow<UIEvent>
fun render(state: State)
}
// scene can acts like a viewmodel, it persists across configuration changes and can saves its state
class MyScene : Scene<MyContainer> {
fun onStart() {
// I created some utilities around coroutines flow.
// Try to see RxScene within acorn extension artifacts
whenViewAvailable { it.events }
.combineWithLatestView()
.onEach { (event, view) -> view.render(**new state based on ui events**) }
.launchIn(sceneScope)
}
}
|
@manueldidonna Thank you! |
@lgtout your welcome! I'm glad to help you |
@nhaarman Do you have ideas about how one might use Acorn together with unidirectional/mvi architecture in the same app? Thanks in advance.
The text was updated successfully, but these errors were encountered: