-
Notifications
You must be signed in to change notification settings - Fork 68
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
base: main
Are you sure you want to change the base?
Conversation
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.
Not sure we should have a |
* ``` | ||
*/ | ||
public suspend inline fun <reified SubState, UiState> CircuitReceiveTurbine<UiState>.consumeState( | ||
dropUnmatchedIntermediates: Boolean = true |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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 👍
This is an alternative to the distinctUntilChanged approach we added, where this exposes a new
CircuitReceiveTurbine
with extraawaitState
andnextState
(naming suggestions welcome) helper functions.