Erik
09/07/2020, 12:34 PMarnaud.giuliani
09/11/2020, 8:25 AMarnaud.giuliani
09/11/2020, 8:26 AMarnaud.giuliani
09/11/2020, 8:26 AMarnaud.giuliani
09/11/2020, 1:23 PM0.11.4
is online 🎉 - https://github.com/uniflow-kt/uniflow-kt/blob/master/Changelog.mdOrfeo Ciano
09/14/2020, 1:50 PMOrfeo Ciano
09/14/2020, 1:50 PMOrfeo Ciano
09/14/2020, 2:01 PMclass Activity: Activity{
onCreate() { viewModel.onCreate() }
onStart() { viewModel.onStart() }
onResume() { viewModel.onResume() }
...
}
This is the viewmodel's implementation
class MyViewModel: AndroidDataFlow(){
fun onCreate() = actionOn<UIState.Empty>{ setState { MyState.Created } }
fun onStart() = actionOn<MyState.Created>{ setState { MyState.Started } }
fun onResume() = actionOn<MyState.Started>{ setState { MyState.Resumed } }
...
}
Since the system calls onCreate
,onStart
,onResume
too quickly, the internal state goes out of sync, causing a BadOrWrongState
(similar to the concurrency issue mentioned earlier).
This is because the library needs to check the state when running the action and not before enqueuing it.
I have already prepared a fix for that, but I can't push it right now.Orfeo Ciano
09/14/2020, 2:28 PMarnaud.giuliani
09/14/2020, 5:17 PMarnaud.giuliani
09/14/2020, 5:21 PMOrfeo Ciano
09/14/2020, 5:41 PMarnaud.giuliani
09/14/2020, 6:31 PMOrfeo Ciano
09/15/2020, 9:36 AMarnaud.giuliani
09/15/2020, 9:37 AMarnaud.giuliani
12/04/2020, 10:19 AMarnaud.giuliani
12/04/2020, 10:39 AMErik
02/18/2021, 7:39 PMaction {}
return ActionFlow
instead of Unit
, is there a use case to have that object somewhere outside of the Uniflow internals?Erik
03/01/2021, 2:11 PMCoroutineScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) { action() }
(not literally, but that's what it comes down to). If you create a lot of action {}
actions quickly, or if your system is slow, then these launched coroutines aren't necessarily run in order. Remember: launching is fire-and-forget. You don't know when the coroutine is actually run!
So, is my code just an example of bad practice? Or is my code an example of a UniFlow running actions in an unordered fashion, and is that a bug?arnaud.giuliani
03/18/2021, 5:09 PMDavide C
04/12/2021, 1:52 PMDavide C
05/13/2021, 7:00 PMpitpit
05/25/2021, 10:30 AMStephan Schuster
08/10/2021, 10:19 PMJustin Ramos
10/18/2021, 7:39 PM0.11.6
to 1.0.10
and ran into an issue and wanted to reach out to the community to see what you all recommend. Below is how we’ve been testing the default state of our viewmodels and we’ve never had issues.
class FeatureFlagViewModel(
private val featureFlagStorage: FeatureFlagStorage
) : AndroidDataFlow(defaultState = FeatureFlagScreenState(isButtonVisible = featureFlagStorage.getFeatureFlagState()!!)) {...}
class FeatureFlagViewModelTest : BaseCovaltoUnitTest() {
private val mockFeatureFlagStorage: FeatureFlagStorage = mockk(relaxed = true)
private lateinit var viewModel: FeatureFlagViewModel
private lateinit var view: TestViewObserver
@Before
fun setup() {
coEvery {
mockFeatureFlagStorage.getFeatureFlagState()
} returns true
viewModel = FeatureFlagViewModel(mockFeatureFlagStorage)
view = viewModel.createTestObserver()
}
@Test
fun `Should set feature flag states properly by default`() {
assertThat(view.lastStateOrNull)
.isEqualTo(
FeatureFlagScreenState(isCreateAccountButtonVisible = true)
)
}
When I run the tests after upgrading to the stable version it fails with the error in the photo below. The issue seems to be that the viewmodel is initialized before it can be observed so we never see the default state set. In other tests when we call viewModel.doStuff()
the viewmodel state is properly updated. An easy fix is to create the default state in the init method of the viewModel like this:
class FeatureFlagViewModel(
private val featureFlagStorage: FeatureFlagStorage
) : AndroidDataFlow() {
init {
action {
setState(FeatureFlagScreenState(isCreateAccountButtonVisible = featureFlagStorage.getFeatureFlagState()!!))
}
}
However, this feels a bit cumbersome to do in every viewmodel we have. It would be great to keep instantiating state the way we’re currently doing it. What do you guys recommend we do though?Erik
10/29/2021, 9:49 AMErik
11/09/2021, 3:11 PMarnaud.giuliani
11/16/2021, 9:41 AM