Waiting for submit response #195
-
Hi! I have a submission like the following <fx-action event="submit">
<fx-message>Searching...</fx-message>
<fx-action while="counter < 10" delay="1000">
<fx-setvalue ref="counter" value=".+1"></fx-setvalue>
<fx-update></fx-update>
<fx-refresh></fx-refresh>
<fx-message>You waited {'{counter}'} second</fx-message>
</fx-action>
</fx-action>
<fx-message
event="submit-done">Done!</fx-message>
<fx-message
event="submit-error">ERROR ! </fx-message>
<fx-message
event="submit-error"
value="event('error')"></fx-message>
</fx-submission> Because it can take some seconds to return results, I added the counter to show a message while the users wait. I am sure there are better ways to report that the search is still ongoing, it just did not return yet? This works but keeps counting after I get the "Done!" message. I guess I would need to limit that with an if statement to fire only until submit-done event? I tried if="event('submit-done')" on action and message, but I am clearly missing something important. Thanks a lot for any hint! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hm, this appears to be a bug. In this place: https://github.com/Jinntec/Fore/blob/dev/src/actions/abstract-action.js#L232 we fire the 'done' event when we are done with the first iteration of the while. So in your case, after a second. In other cases, when we have an infinite while loop, we actually want to release the event loop (to allow new 'done' events to come through). Problem here is that we cannot distinguish those loops... You could choose to do something like this to make this work though:
And then dispatch an event from the search action that tells all is done. @JoernT what do you think on the while immediately causing the 'done' event? Maybe we should add a 'blockContinuation' attribute on the action? |
Beta Was this translation helpful? Give feedback.
-
@DrRataplan maybe we can distinguish...? Can't we say that an endless loop is always just using |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! Here is how I updated my fx-instance and fx-submission, and it works as you explained, even if I did not actually understand how to "dispatch an event from the search action that tells all is done". <fx-instance id="searchcounter">
<data>
<counter>0</counter>
<search-state/>
</data>
</fx-instance> <fx-submission
id="search"
replace="target"
target="#results"
method="post"
url="">
<fx-action
event="submit">
<fx-setvalue ref="instance('searchcounter')/search-state">running</fx-setvalue>
<fx-message>Searching...</fx-message>
<fx-action while="instance('searchcounter')/search-state = 'running'" delay="1000">
<fx-update></fx-update>
<fx-refresh></fx-refresh>
<fx-setvalue ref="instance('searchcounter')/counter" value=".+1"></fx-setvalue>
<fx-message>You waited {'{instance("searchcounter")/counter}'} second, I am still working, please, wait</fx-message>
</fx-action>
</fx-action>
<fx-action event="submit-done">
<fx-setvalue ref="instance('searchcounter')/search-state"></fx-setvalue>
<fx-setvalue ref="instance('searchcounter')/counter">0</fx-setvalue>
<fx-message>Done, thanks for your patience.</fx-message>
</fx-action>
<fx-message
event="submit-error">ERROR ! </fx-message>
<fx-message
event="submit-error"
value="event('error')"></fx-message>
</fx-submission> |
Beta Was this translation helpful? Give feedback.
Hm, this appears to be a bug. In this place: https://github.com/Jinntec/Fore/blob/dev/src/actions/abstract-action.js#L232 we fire the 'done' event when we are done with the first iteration of the while. So in your case, after a second.
In other cases, when we have an infinite while loop, we actually want to release the event loop (to allow new 'done' events to come through). Problem here is that we cannot distinguish those loops...
You could choose to do something like this to make this work though:
<search-state running="true"/>
fx-setvalue
to set the running to 'false'<fx-action whi…