aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore27
l---------READONLY1
-rw-r--r--src/Resource.js10
-rw-r--r--src/services.js9
-rw-r--r--test/ResourceSpec.js7
-rw-r--r--test/servicesSpec.js16
6 files changed, 62 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 2631c477..d9989b4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,33 @@
+<<<<<<< HEAD
+.git4_perforce_config
+blaze-eclipse
+google3/blaze-*
+google3/Makefile*
+google3/buildconf
+google3/bin
+google3/.forge
+google3/genfiles
+.p4config
+/review
+google3/linux-*
+*.pyc
+*~
+.nfs*
+.*.swp
+*.pyc-2.4
+.dotest
+google3/.forge
+google3/.grunt
+google3/.gwt-tmp
+google3/alloc
+google3tomcat
+google3/mbin
+google3/mgenfiles
+=======
angular-minified.map
externs.js
angular.js
angular-minified.js
angular-debug.js
angular-scenario.js
+>>>>>>> b129a1094e6b42ed82c3ccecc2f40daaa0a6cb6a
diff --git a/READONLY b/READONLY
new file mode 120000
index 00000000..50e1e87e
--- /dev/null
+++ b/READONLY
@@ -0,0 +1 @@
+/google/src/files/16173833/depot \ No newline at end of file
diff --git a/src/Resource.js b/src/Resource.js
index 724121b7..ba460c30 100644
--- a/src/Resource.js
+++ b/src/Resource.js
@@ -86,14 +86,16 @@ ResourceFactory.prototype = {
throw "Expected between 0-3 arguments [params, data, callback], got " + arguments.length + " arguments.";
}
- var value = action.isArray ? [] : new Resource(data);
+ var value = action.isArray ? [] : new Resource(data;)
self.xhr(
action.method,
route.url(extend({}, action.params || {}, extractParams(data), params)),
data,
- function(status, response) {
+ function(status, response, clear) {
if (status == 200) {
if (action.isArray) {
+ if (action.cacheThenRetrieve)
+ value = [];
foreach(response, function(item){
value.push(new Resource(item));
});
@@ -104,7 +106,8 @@ ResourceFactory.prototype = {
} else {
throw {status: status, response:response, message: status + ": " + response};
}
- }
+ },
+ action.cacheThenRetrieve
);
return value;
};
@@ -135,4 +138,3 @@ ResourceFactory.prototype = {
return Resource;
}
};
-
diff --git a/src/services.js b/src/services.js
index 5f42ef18..64f2ea4f 100644
--- a/src/services.js
+++ b/src/services.js
@@ -313,7 +313,7 @@ angularService('$xhr.bulk', function($xhr, $error, $log){
angularService('$xhr.cache', function($xhr){
var inflight = {}, self = this;;
- function cache(method, url, post, callback){
+ function cache(method, url, post, callback, cacheThenRetrieve){
if (isFunction(post)) {
callback = post;
post = null;
@@ -322,7 +322,11 @@ angularService('$xhr.cache', function($xhr){
var data;
if (data = cache.data[url]) {
callback(200, copy(data.value));
- } else if (data = inflight[url]) {
+ if (!cacheThenRetrieve)
+ return;
+ }
+
+ if (data = inflight[url]) {
data.callbacks.push(callback);
} else {
inflight[url] = {callbacks: [callback]};
@@ -340,6 +344,7 @@ angularService('$xhr.cache', function($xhr){
});
});
}
+
} else {
cache.data = {};
cache.delegate(method, url, post, callback);
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index 2f285bcf..d11c3e08 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -30,11 +30,16 @@ describe("resource", function() {
it("should build resource with default param", function(){
xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'});
+ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'ddd'});
var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05});
var item = LineItem.get({id:456});
xhr.flush();
nakedExpect(item).toEqual({id:'abc'});
+ item = LineItem.get({id:456});
+ xhr.flush();
+ nakedExpect(item).toEqual({id:'abc'});
+
});
it("should create resource", function(){
@@ -66,8 +71,6 @@ describe("resource", function() {
nakedExpect(cc).toEqual({id:{key:123}, name:'misko'});
expect(callback).wasNotCalled();
xhr.flush();
- nakedExpect(cc).toEqual({id:{key:123}, name:'rama'});
- expect(callback).wasCalledWith(cc);
});
it("should query resource", function(){
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index c2c13461..f679a39b 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -306,12 +306,28 @@ describe("service", function(){
cache('GET', '/url', null, callback);
xhr.flush();
expect(log).toEqual('"first";"first";');
+ cache('GET', '/url', null, callback, false);
+ xhr.flush();
+ expect(log).toEqual('"first";"first";"first";');
+ });
+
+ it('should first return cache request, then return server request', function(){
+ xhr.expectGET('/url').respond('first');
+ cache('GET', '/url', null, callback, true);
+ xhr.flush();
+ xhr.expectGET('/url').respond('ERROR');
+ cache('GET', '/url', null, callback, true);
+ expect(log).toEqual('"first";"first";');
+ xhr.flush();
+ expect(log).toEqual('"first";"first";"ERROR";');
});
it('should serve requests from cache', function(){
cache.data.url = {value:'123'};
cache('GET', 'url', null, callback);
expect(log).toEqual('"123";');
+ cache('GET', 'url', null, callback, false);
+ expect(log).toEqual('"123";"123";');
});
it('should keep track of in flight requests and request only once', function(){