Skip to content
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

Open
lgtout opened this issue Dec 25, 2019 · 5 comments
Open

Integration with unidirectional/mvi architecture #157

lgtout opened this issue Dec 25, 2019 · 5 comments
Labels
type:question A question about Acorn

Comments

@lgtout
Copy link

lgtout commented Dec 25, 2019

@nhaarman Do you have ideas about how one might use Acorn together with unidirectional/mvi architecture in the same app? Thanks in advance.

@nhaarman
Copy link
Owner

nhaarman commented Feb 2, 2020

Could you give an example of what you mean by an unidirectional/mvi architecture? I'm unfamiliar with it.

@nhaarman nhaarman added the type:question A question about Acorn label Feb 2, 2020
@lgtout
Copy link
Author

lgtout commented Feb 2, 2020

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.

@manueldidonna
Copy link

manueldidonna commented Feb 2, 2020

@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) 
    }
}

@lgtout
Copy link
Author

lgtout commented Feb 2, 2020

@manueldidonna Thank you!

@manueldidonna
Copy link

@lgtout your welcome! I'm glad to help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question A question about Acorn
Projects
None yet
Development

No branches or pull requests

3 participants