walmartlabs / thorax

Strengthening your Backbone
http://thoraxjs.org/
Other
1.32k stars 129 forks source link

Success handler of fetch is not called when response is synchronous (and fetchQueue is empty) #378

Open MichaReiser opened 10 years ago

MichaReiser commented 10 years ago

In the fetchQueue method a new queue is created when no one exists. Additionally the success and error callbacks are overridden to point to flushQueue. When super ($super.call) is called, the fetch queue is still empty. When the super.call now resolves the success handler synchronous (no defer or anything), then at the moment where flushQueue is called, the queue is still empty, and the success or error handler are not called (because the queue is empty)

A simple solution could be, that super will be invoked using _.defer. Otherwise the registration in the flushQueue must take place before invoking super...

MichaReiser commented 9 years ago

I have added a unit test that shows the issue. Either I still don't know how a fix can be implemented. The only possibility I see (but I don't know if this would be conform with the api) is to pass the original success function to flushQueue. If the fetchQueue is empty in flushQueue, then call the original success function. Otherwise use the existing logic. Any ideas?

liorcode commented 9 years ago

I'm facing the same issue, any progress on that?

CLAassistant commented 4 years ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.