From c69858ca2d30f530ae8962bc67ead0e854f0cf80 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Fri, 26 Sep 2014 11:57:50 +0200 Subject: [PATCH] Ox.Request: if data is in cache, don't fail if it gets removed before timeout --- source/Ox.UI/js/Core/Request.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/Ox.UI/js/Core/Request.js b/source/Ox.UI/js/Core/Request.js index 12e2401a..fd837f1d 100644 --- a/source/Ox.UI/js/Core/Request.js +++ b/source/Ox.UI/js/Core/Request.js @@ -106,7 +106,8 @@ Ox.Request = (function() { @*/ send: function(options) { - var options = Ox.extend({ + var data, + options = Ox.extend({ age: -1, callback: null, id: Ox.uid(), @@ -122,7 +123,7 @@ Ox.Request = (function() { if (pending[options.id]) { setTimeout(function() { Ox.Request.send(options); - }, 0); + }); } else { requests[options.id] = { url: options.url, @@ -132,8 +133,9 @@ Ox.Request = (function() { options.age == -1 || options.age > +new Date() - cache[req].time )) { + data = cache[req].data; setTimeout(function() { - callback(cache[req].data, true); + callback(data, true); }); } else { pending[options.id] = true;