I am attempting to send sequential requests to the ngrx-store in order to save two different entities in randomly chosen MongoDB collections. The challenge lies in needing a response from the first ngrx-store effect in order to utilize the data in another one when creating an entity that references the first one.
Here is what I have:
Reducer
...Action
...Effect
...Selector
...And service
...All of this setup functions properly when I create only one entity from the component.
...Other logic for creating different entities follows similar patterns as described above. However, calling an action within an action within the component can break the application state if not handled correctly. For instance, when trying to make additional actions after such nested calls, like editing or deleting contacts, the application state becomes unstable and errors occur.
On the other hand, dividing the logic into two independent calls results in issues because the application might not know the createdUser _id or userState.user._id at the time the createContact method is called, leading to errors.
I believe there needs to be a more intricate implementation of logic to handle these scenarios correctly. If you have any suggestions on the proper way to accomplish this, please advise me accordingly.
Thank you in advance.