I've already come up with a number of different methods to solve this issue in my code, but I'd like to hear how other people do it.
So far here's what I've done:
- Use lodash.throttle on a method which does an ajax call so that multiple clicks in quick succession don't create multiple calls.
- Use lodash.debounce on a method so that ajax is only called once a user hasn't done any activity for a bit. This is how I'm doing semi-realtime updates of text fields on change.
- Dispatch an "is updating" message to stores when the action is first called and then dispatch a "done" message when the ajax call returns. Do stuff like disabling input on the initial message and then re-enable on the second.
The third method seems to be the best in terms of functionality since it allows you to make the user interface reflect exactly what's going on, but it's also SO INCREDIBLY VERBOSE. Like.. holy application constants batman! Plus it clutters absolutely everything up with tons of extra state, handler methods, etc...
So how do you keep your application in sync with ajax calls?
Aucun commentaire:
Enregistrer un commentaire