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

Action,Result是否应该是一类对应一类呢 #11

Open
CoderLengary opened this issue Sep 6, 2019 · 1 comment
Open

Action,Result是否应该是一类对应一类呢 #11

CoderLengary opened this issue Sep 6, 2019 · 1 comment

Comments

@CoderLengary
Copy link

这里面有段代码让我有点困惑,在HomeActionProcessorHolder这个类中,InitIntent 会触发 Paging 这个库的方法,比如从零加载和向下分页,

private val initialActionTransformer =
        ObservableTransformer<HomeAction.InitialAction, HomeResult.InitialResult> { action ->
            action.flatMap<HomeResult.InitialResult> {
                repository.getReceivedPagedList(
                    boundaryCallback = object : PagedList.BoundaryCallback<ReceivedEvent>() {
                        override fun onZeroItemsLoaded() {
                            [email protected]()
                        }

                        override fun onItemAtEndLoaded(itemAtEnd: ReceivedEvent) {
                            [email protected](itemAtEnd)
                        }
                    }
                ).map(HomeResult::InitialResult).toObservable()
            }
        }

我注意到这两个方法会发出一个 PublishSubject<HomeResult.LoadingPageResult>,它会将:加载中、加载成功、加载失败 传递出去。如果这次请求成功的话,还会有一个 InitialResult 包括了请求成功返回的列表。
所以总结一下,InitialAction 会带来两种 Result,一个是 InitialAction 对应的 InitialResult,一个是 另外生成的 LoadingPageResult。我困惑的地方就在于,一种 Action 不应该只对应一种 Result 么。如果 一种 Action 可以对应多种 Result,感觉就没有一个单链条传递的关系了。

@CoderLengary
Copy link
Author

MVI 感觉是一个优秀的模式,虽然它的代码量多,但是它的条理十分清晰,什么 Intent 就会变成什么样的 Action,返回什么样的 result ,最后统一成不同 ViewState。怎么说,就像是多个单链条,在终点时汇聚。这就是我对 MVI 的一部分理解。针对上述代码来说,打破了我对这个模式的认识,所以很不解。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant