add deferred request to models or collections for race condutions #1567
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
About this request
This solves some problems when user interacts backbone rapidly(user click all buttons faster than servers response). This is related to #1325 and #1468. This has some problems.Look at the commits and comments.This pull request is first commit that improving backbone's asynchronous UI feature.
What are you offering Incoming requests?
Backbone offer asynchronous user interfaces but it is not clean when it
comes to rapid model syncing and id generation.Spine offers approximately
similar features, but Spine focus asynchronous interfaces more than backbone.
I do not want to switch to Spine because I was delving deeper to the backbone by
reading annotated source code.After all, I decided to strength asynchronous
UI feature of backbone by whether pulling some requests or writing tiny plug-in
Implementing asynchronous user interfaces
if you create a model then you call Backbone.sync
indirectly, (calling model.fetch,save,destroy collection.fetch,create)
you want to sync with server.Unfortunately there is some problems.
your server is completely unaware this deletion when dealing with your
update or create methods.
Thus, client is under the impression that s/he deleted the model,
but server don't and won't delete.
SOLUTION: give an id into Backbone.sync on create method.
probably give cid or guid as a pseudo-id.
this causes second problem
some race conditions may happen.
For example, your delete method with pseudo-id is received by server
before your create method that will turn to the client with real id.
second example is sending read method with filter A
then sending read method with filter B. if second read method
returns to the server first, client see filter A when want to see filter B
SOLUTION: send all methods one at a time but do this efficiently.
send one request then defer requests until response. if user send another
request when there is a deferred request, override previously deferred one
because user only wants the last change on the model or collection.
Finally response comes, only change pseudo-id of deferred to the real id
then send deferred request
NOTE: Look at commit notes for pseudo-codes for solutions