vivid-money / elmslie

Kotlin TEA/ELM implementation with first class android support
https://github.com/vivid-money/elmslie
Apache License 2.0
116 stars 13 forks source link

[Bug] Effects which are emitted in background can be missed in Compose #162

Open rcmkt opened 2 years ago

rcmkt commented 2 years ago

Preconditions: There are two ElmFragments which are only container for Composable functions. Subscribe to Flow(Effect) with effects extension inside Composable fun.

Steps to reproduce:

  1. Open Fragment1 and navigate to Fragment2. Fragment1 subscribes via Actor to some data-holder.
  2. Trigger an event in Fragment2 which perform some work and update the data-holder from previous step.
  3. Reducer1 received event from Actor and produce effect, while Fragment1 is paused.
  4. Fragment2 is closed and Fragment1 didn't get effect.

IMPORTANT NOTE It's related only for Flow. Due to research, I found that ElmScreen always subscribes to effects when Fragment is resumed. Since we manually subscribes to effects, this behavior broke the logic. CoroutineScope inside Composable starts later than Fragment is get resume state, so ElmScreen consume effects but it shouldn't.

diklimchuk commented 2 years ago

Hello. Do you have a working sample that reproduces this issue?