Wait For another action within a store.
Hi everyone,
I just came across this problematic and wondered how I could resolve it.
I have a accountService with a login method, giving a user and a password. This method hash the password and start a first action "TempAction" to keep for a time in the accountStore the non-encrypted password and user. It then makes an ajax request to give the hash and username to our server. At the end, as a callback, it triggers another action "RetrieveAccountInfo" located in the same Store which will use both server-given information and temporary info.
My issue is the following : the waitFor is perfect for this, but not when the action we are waiting for is in the same store. As this behavior will happen frequently in our project, the use of another "temporaryStore" might become another issue, as in the end, the "RetrieveAccountInfo" might wait for different from TempAction action to end in the temporaryStore.
Before you ask, it is wished to give a hashed password to our lovely server. ;)
And damn it is really hard to explain, so I hope I was clear enough. If not, feel free to ask for more information.
Accurate naming seems like an issue here, and I think the lack of accurate naming is causing you to get tripped up. "TempAction" is very vague. "RetrieveAccountInfo" sounds very imperative. Remember actions do not say what to do. Instead, they describe what happened.
I'm assuming we are talking about basic, standard Flux of the variety that this repo is about. I'm also assuming that all code here is on the client.
Please correct me if I'm wrong:
The first action I'll name LOGIN_SUBMITTED.
The LoginStore responds to this action by storing the non-encrypted username and password (why do you need to do this? seems like a security risk).
Additionally, the LOGIN_SUBMITTED action creator calls the WebAPIUtils to make a request to the server. Upon success, the LOGIN_VALIDATED action is dispatched.
The AccountStore responds to LOGIN_VALIDATED by retrieving the temporary information from the LoginStore and combining that with the account information from the server, contained in the action. I don't think there is any need for waitFor() in the retrieval of the temporary info, since the LoginStore is not updating in response to LOGIN_VALIDATED.
Sounds like this issue was answered :)