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

Avoid events in flatMapLatest #830

Merged
merged 3 commits into from
Dec 22, 2023
Merged

Avoid events in flatMapLatest #830

merged 3 commits into from
Dec 22, 2023

Conversation

metin-kale
Copy link
Collaborator

@metin-kale metin-kale commented Dec 20, 2023

The current code contains lots of statements like

state.flatMapLatest { value ->
    clicks.map { ... }
} handledBy ...

The problem here is, that

  1. the listener is attached after a minimal delay
  2. event-calls might get lost, because the outer flow changes

For flows, which represent a state, it should be no problem to use flatMapLatest, but because events are one-shot operations, they should not be used within another flow transformation. While it seems to work for normal usage, it causes lots of problems for automated ui-tests e.g. using playwright. Actions might get lost or are not ready yet, what causes failing/flaky tests.

With this PR i replaced all event-Flows within Flow-Transformations i could found. The replacement always a followed similiar pattern. The above example code would be

clicks.map {
     val value = state.first()
     ...
} handledBy ...

Or if state is the flow of a store, i used Store.current rather than first()

Lysander
Lysander previously approved these changes Dec 21, 2023
@metin-kale metin-kale marked this pull request as ready for review December 21, 2023 14:31
@Lysander Lysander self-requested a review December 21, 2023 18:12
@metin-kale metin-kale merged commit d7c3d02 into master Dec 22, 2023
2 checks passed
@Lysander Lysander added this to the 1.0-RC13 milestone Jan 2, 2024
@Lysander Lysander added the headless All about headless components and foundations label Jan 2, 2024
@Lysander Lysander assigned Lysander and metin-kale and unassigned Lysander Jan 2, 2024
@Lysander Lysander changed the title avoid events in flatMapLatest Avoid events in flatMapLatest Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
headless All about headless components and foundations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants