Closed Badlazzor closed 1 month ago
Hi @Badlazzor, the behavior you are witnessing is unfortunately expected, though not necessary ideal. I believe this behavior is documented, but I couldn't find it and so I will have to look into that.
But currently the TestStore
eagerly executes effect actions when they are received, which means the logic that mutates shared state is happening before one even does store.receive
. Before releasing the shared state tools we looked into making TestStore
delay executing an effect action until one actually does store.receive
, but unfortunately we found that would be a breaking change. There are tests out there that assert on dependencies in a specific way that would be broken by delaying the execution of the effect action.
So, we do plan on fixing this issue, but it will have to wait for 2.0. Since we do not consider this an issue with the library today I am going to convert it to a discussion. Please feel free to continue the conversation over there.
Description
Consider having a Reducer that has 4 actions:
It also shares the As and Bs in a
@Shared [A: IdentifiedArray<B>]
State.The Reducer should do the following:
fetchA
.run
, sendingresultForA
when donefetchB
, but before that updates the@Shared
state with the As adding empty arrays for each entry (for display reasons).run
, sendingresultForB
when done@Shared
state's BsThe problem I see is when testing and sending
fetchA
to the TestStore the actions are received as expected, but the state changes are accumulated into the first actions changes in the@Shared
state.Checklist
main
branch of this package.Expected behavior
Sending
fetchA
to the TestStore would result in the following:Actual behavior
Sending
fetchA
to the TestStore would result in the following:Steps to reproduce
No response
The Composable Architecture version information
1.13.1
Destination operating system
iOS 17.5
Xcode version information
Version 15.4 (15F31d)
Swift Compiler version information