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

Prototype CircuitReceiveTurbine #1597

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

ZacSweers
Copy link
Collaborator

This is an alternative to the distinctUntilChanged approach we added, where this exposes a new CircuitReceiveTurbine with extra awaitState and nextState (naming suggestions welcome) helper functions.

This is an alternative to the distinctUntilChanged approach we added, where this exposes a new `CircuitReceiveTurbine` with extra `awaitState` and `nextState` (naming suggestions welcome) helper functions.
@ZacSweers ZacSweers requested a review from stagg August 23, 2024 04:40
@stagg
Copy link
Collaborator

stagg commented Aug 23, 2024

Not sure we should have a dropUnmatchedIntermediates? Think in the cases we've seen we want to consume the duplicate state emissions. Some sort of consumeState<Loading>()?

* ```
*/
public suspend inline fun <reified SubState, UiState> CircuitReceiveTurbine<UiState>.consumeState(
dropUnmatchedIntermediates: Boolean = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be really wary of this in presenter tests.

We have already had a push internally to get rid of a lot of usage of ReceiveTurbine.skipItem, because it harms test readability and can make refactoring/altering these tests a pain.

A consumeState with a conditional filter has the same problems, and also makes it easier to accidentally obscure faulty behavior in the presenter: the presenter may be emitting intermediate states that should be setting off alarms.

val value = event.value
if (predicate(value)) {
return value
} else if (dropUnmatchedIntermediates) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is confusing to me - it looks like, if this is false, then exactly one unmatched intermediate can be dropped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, but I don't remember exactly why I did that now 😅

*/
public interface CircuitReceiveTurbine<UiState : CircuitUiState> : ReceiveTurbine<UiState> {
/** Awaits the _next_ [UiState] emission that is different than the [lastState]. */
public suspend fun consumeState(lastState: UiState? = tryMostRecentItem()): UiState

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting approach. Not sure it needs to be a public param? What gets unblocked with that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking that in some cases you've already held on to the previous state, but we can always close it off and open it up later

Copy link
Collaborator Author

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking with the dropUnmatchedIntermediates param was allow people to turn off the distinctUntilChanged behavior, but we can always add that later if people need. I'm good just removing for now 👍

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

Successfully merging this pull request may close these issues.

3 participants