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

首页列表点击收藏一个item,去到(我的)页面点我的收藏后,在回到首页会自动触发收藏和取消收藏操作。 #38

Open
chakfaigo opened this issue Jan 4, 2023 · 1 comment

Comments

@chakfaigo
Copy link

master分支。

看堆栈是ProfileFragment.refreshData ->Play.isLogin ,但是不知道为什么触发到ArticleAdapter 的Play.isLogin().collectLatest,

@ruirui1128
Copy link
Contributor

应该是Flow的问题.刷新登录状态的时候,之前的生产消费关系依然存在,导致了重复收藏,取消的问题,每点击一次,关系就会再次重新生成一次。可以尝试限制流的消费。

fun isLogin(): Flow<Boolean> {
    return if (::dataStore.isInitialized) {
        dataStore.readBooleanFlow(IS_LOGIN).take(1)
    } else {
        flow {
            emit(false)
        }.take(1)

    }
}

虽然这样解决重复消费的问题,但是会有些瑕疵。可以在刷新的方法中,重新获取数据,而不是只改变登录状态。

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

2 participants