DataLoader, first draft. popcorn-port
authorhamidouk
Tue, 11 Oct 2011 17:13:08 +0200
branchpopcorn-port
changeset 61 dc7b5ed7b02b
parent 60 ffc038fdb8f1
child 62 aa30f4339117
DataLoader, first draft.
src/js/data.js
--- a/src/js/data.js	Tue Oct 11 17:12:51 2011 +0200
+++ b/src/js/data.js	Tue Oct 11 17:13:08 2011 +0200
@@ -1,5 +1,28 @@
 /* data.js - this file deals with how the players gets and sends data */
 
+IriSP.DataLoader = function() {
+  this._cache = {};
+};
+
+IriSP.DataLoader.prototype.get = function(url, callback) {  
+  if (this._cache.hasOwnProperty(url)) {
+    callback(this._cache[url]);
+  } else {
+    /* we need a closure because this gets lost when it's called back */
+    IriSP.jQuery.get(url, (function(obj) {      
+                               return function(data) {
+                                  obj._cache[url] = data;      
+                                  callback(obj._cache[url]);
+                                }; 
+                              })(this));
+       
+  }
+}
+
+IriSP.Serializer = function(DataLoader) {
+  this.DataLoader = DataLoader;
+};
+
 IriSP.getMetadata = function() {
 	
 	IriSP.jQuery.ajax({