Comments (2)
This is happening because of the general behavior of StateFlow
. Since StateFlow
has its own initial value that will get emitted immediately to Turbine. So the awaitItem
is handled and dispatch is called. The issue is that that doesn't mean that stateIn
has started collecting the upstream state
yet and because StateFlow has a builtIn distinctUntilChanged
there is also no way to wait for the actual first emission of FlowReduxStateMachine
. There are a few solutions for this:
- use
state
instead ofstateFlow
in tests, that way the first emission for awaitItem comes from FlowReduxStateMachine and theon
/dispatch
is guaranteed to work - replace
StateFlow
withSharedFlow
by usingshareIn(..., replay = 1)
, similar to the above but lets you use the shared flow for tests so that the test is closer to a real consumer - have a different initial state for the StateFlow and the StateMachine, probably not a nice solution
I would also generally recommend one of the first 2 in tests. StateFlow
has some things like conflation of values that can easily make tests flaky since you might not get in between emissions sometimes.
from flowredux.
Thank you so much!
We chose the second solution. In the example code the change is just from
val stateFlow: StateFlow<MachineState> = state.stateIn(
scope = CoroutineScope(Dispatchers.Default),
started = SharingStarted.Eagerly,
initialValue = initialState
)
to
val stateFlow: SharedFlow<MachineState> = state.shareIn(
scope = CoroutineScope(Dispatchers.Default),
started = SharingStarted.Eagerly,
replay = 1
)
from flowredux.
Related Issues (20)
- Make Compose artifact Compose Multiplatform HOT 1
- Cannot dispatch action because state Flow of this FlowReduxStateMachine is not collected yet HOT 2
- ChangedState reduce() type mismatch HOT 3
- [Question] Detail page implementation help HOT 6
- DSL: Add a way to work with"Identity" of states HOT 3
- 2.0 todo list
- Action Required: Fix Renovate Configuration
- FlowRedux and Flow from usecases HOT 1
- Support null values for identity? HOT 1
- Improve hierarchical state machines
- [Question] Search Implementation HOT 3
- [Idea] Generate a state transition graph in compile time HOT 2
- [Question] How to dispatch actions in one coroutine? HOT 1
- [Question] Dead lock in dispatching multiple actions to ORDERED OnAction statement HOT 4
- Cannot dispatch action because state Flow of this FlowReduxStateMachine is not collected yet HOT 7
- 1.2.0 seems to be broken regarding iOS HOT 2
- Unify state (snapshot) access and parameters in DSL
- [Question] State Collection On Multiple Screens HOT 1
- Cannot dispatch action because state Flow of this FlowReduxStateMachine is not collected yet HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flowredux.