Closed V-ed closed 4 years ago
I tried multiple ways of switching to async functions (the sendRequest method should in theory already be async for every single request, since it is done in a promise... weird), but I couldn't fix this issue (yet).
The issue is definitely happening when doing the request though, like if the UI thread was being locked, which I find weird. I'll investigate again sooner or later.
I don't think I'll fix this issue properly since the request will always take up some time and lag the input field a bit.
Therefore, I'll see about changing the way I wait for the minimum delay and doing a hack instead. I added todos to the issue body.
These tweaks will make the inputs feel more natural, as currently, this is what is happening : the javascript engine is busy trying to do the request while the UI received a new command, which the thread can't execute since it is busy and the input event is therefore added to the event queue instead of executed immediately.
Further readings about Promise asynchronous behaviors :
Changing the while loop to a calculated timeout actually fixes this issue right away, which is interesting.
I will still implement the input delayer for sending a request, as I don't want to spam send requests when typing quickly in any input field.
I decided that the delay between inputs were to be 250ms
, and the minimumDelay for showing a spinner for (both index's AND setup page) is now 150ms
.
I think those values gives the best perceived performance while still not putting too much stress on my server.
Currently, when you input candidates, you see a small delay between typing, making it feels like the application is lagging, while it is only doing an asynchronous request in the background, blocking the app from actually adding the inputs to the fields.
~To make the app more seamless, I should switch to an async method to prevent lockups.~
~The issue I see doing this is that the request should be canceled or some sort if the inputs' verify state gets changed (goes from invalid to valid or vice versa).~
TODOs
while
waiting loop to asetTimeout
function which the timeout is calculated from the time before the send and after the send.MinimalDelayer
could be created for generalizing the minimum delay logic and remove that logic from the sendRequest methods(parseInt(val) > 0 && parseInt(val)) || 0
: could be used to parse any object given as parameterexecute
function, accept callback to trigger once the minimum delay has passed. Funnily enough, this could return a Promise to be able to chain data when the minimum delay was achieved... I'll see how I can make that fancy :)100ms