couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [30/50] [abbrv] fauxton commit: updated refs/heads/import-master to b32c617
Date Tue, 01 Apr 2014 09:14:46 GMT
Fauxton: remove caching


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/af19be10
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/af19be10
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/af19be10

Branch: refs/heads/import-master
Commit: af19be104dfda7fc0a8078f9e755e9e701412907
Parents: d88bae7
Author: Garren Smith <garren.smith@gmail.com>
Authored: Fri Mar 14 15:54:27 2014 -0400
Committer: suelockwood <deathbear@apache.org>
Committed: Mon Mar 17 08:23:56 2014 -0400

----------------------------------------------------------------------
 Gruntfile.js                              |   2 +-
 app/config.js                             |   3 +-
 app/core/base.js                          |  45 ++--
 app/core/couchdbSession.js                |   1 -
 assets/js/plugins/backbone.fetch-cache.js | 311 -------------------------
 tasks/couchserver.js                      |   4 +-
 6 files changed, 18 insertions(+), 348 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index 348fa45..49c082e 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -170,7 +170,7 @@ module.exports = function(grunt) {
     // override inside main.js needs to test for them so as to not accidentally
     // route. Settings expr true so we can do `migtBeNullObject && mightBeNullObject.coolFunction()`
     jshint: {
-      all: ['app/**/*.js', 'Gruntfile.js', "test/core/*.js"],
+      all: ['app/**/*.js', 'Gruntfile.js', "!app/**/assets/js/*.js"],
       options: {
         scripturl: true,
         evil: true,

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/app/config.js
----------------------------------------------------------------------
diff --git a/app/config.js b/app/config.js
index a5d764f..98be9c6 100644
--- a/app/config.js
+++ b/app/config.js
@@ -30,8 +30,7 @@ require.config({
     spin: "../assets/js/libs/spin.min",
     d3: "../assets/js/libs/d3",
     "nv.d3": "../assets/js/libs/nv.d3",
-    "ace":"../assets/js/libs/ace",
-    "backbone.fetch-cache": "../assets/js/plugins/backbone.fetch-cache"
+    "ace":"../assets/js/libs/ace"
   },
 
   baseUrl: '/',

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/app/core/base.js
----------------------------------------------------------------------
diff --git a/app/core/base.js b/app/core/base.js
index 7cacf39..15499b3 100644
--- a/app/core/base.js
+++ b/app/core/base.js
@@ -12,11 +12,10 @@
 
 define([
   "backbone",
-  "plugins/backbone.layoutmanager",
-  "backbone.fetch-cache"
+  "plugins/backbone.layoutmanager"
 ],
 
-function(Backbone, LayoutManager, BackboneCache) {
+function(Backbone, LayoutManager) {
   var FauxtonAPI = {
     //add default objects
     router: {
@@ -68,44 +67,26 @@ function(Backbone, LayoutManager, BackboneCache) {
     }
   });
 
-
-  FauxtonAPI.Model = Backbone.Model.extend({
-
-  });
-
-  FauxtonAPI.Collection = Backbone.Collection.extend({
-
-  });
-
   var caching = {
-    fetchOnce: function (opts) {
-      var options = _.defaults(opts || {}, this.cache, {cache: true});
+    fetchOnce: function (opt) {
+      var options = _.extend({}, opt);
 
-      if (opts && !opts.cache) {
-        delete options.cache;
+      if (!this._deferred || this._deferred.state() === "rejected" || options.forceFetch
) {
+        this._deferred = this.fetch();
       }
 
-      if (!options.prefill) {
-        return this.fetch(options);
-      }
-
-      //With Prefill, the Caching with resolve with whatever is in the cache for that model/collection
-      //and at the sametime it will fetch from the server the latest. 
-      var promise = FauxtonAPI.Deferred(),
-          fetchPromise = this.fetch(options);
-
-      fetchPromise.progress(promise.resolveWith); // Fires when the cache hit happens
-      fetchPromise.then(promise.resolveWith); // Fires after the AJAX call
-      promise.fail(fetchPromise.abort);
-
-      return promise;
+      return this._deferred;
     }
   };
 
-  _.each([FauxtonAPI.Collection, FauxtonAPI.Model], function (ctor) {
+  FauxtonAPI.Model = Backbone.Model.extend({ });
+
+  FauxtonAPI.Collection = Backbone.Collection.extend({ });
+
+  _.each([FauxtonAPI.Model, FauxtonAPI.Collection], function (ctor) {
     _.extend(ctor.prototype, caching);
   });
-
+  
   var extensions = _.extend({}, Backbone.Events);
   // Can look at a remove function later.
   FauxtonAPI.registerExtension = function (name, view) {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/app/core/couchdbSession.js
----------------------------------------------------------------------
diff --git a/app/core/couchdbSession.js b/app/core/couchdbSession.js
index 747ef3e..7482db9 100644
--- a/app/core/couchdbSession.js
+++ b/app/core/couchdbSession.js
@@ -35,7 +35,6 @@ function (FauxtonAPI) {
 
         if (options.forceFetch) {
           fetch = _.bind(this.fetch, this);
-          Backbone.fetchCache.clearItem(_.result(this, 'url'));
         }
 
         return fetch(opt).then(function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/assets/js/plugins/backbone.fetch-cache.js
----------------------------------------------------------------------
diff --git a/assets/js/plugins/backbone.fetch-cache.js b/assets/js/plugins/backbone.fetch-cache.js
deleted file mode 100644
index 4aa7676..0000000
--- a/assets/js/plugins/backbone.fetch-cache.js
+++ /dev/null
@@ -1,311 +0,0 @@
-/*!
-  backbone.fetch-cache v1.3.0
-  by Andy Appleton - https://github.com/mrappleton/backbone-fetch-cache.git
- */
-
-// AMD wrapper from https://github.com/umdjs/umd/blob/master/amdWebGlobal.js
-
-(function (root, factory) {
-  if (typeof define === 'function' && define.amd) {
-    // AMD. Register as an anonymous module and set browser global
-    define(['underscore', 'backbone', 'jquery'], function (_, Backbone, $) {
-      return (root.Backbone = factory(_, Backbone, $));
-    });
-  } else {
-    // Browser globals
-    root.Backbone = factory(root._, root.Backbone, root.jQuery);
-  }
-}(this, function (_, Backbone, $) {
-
-  // Setup
-  var superMethods = {
-    modelFetch: Backbone.Model.prototype.fetch,
-    modelSync: Backbone.Model.prototype.sync,
-    collectionFetch: Backbone.Collection.prototype.fetch
-  },
-  supportLocalStorage = (function() {
-    var supported = typeof window.localStorage !== 'undefined';
-    if (supported) {
-      try {
-        // impossible to write on some platforms when private browsing is on and
-        // throws an exception = local storage not supported.
-        localStorage.setItem("test_support", "test_support");
-        localStorage.removeItem("test_support");
-      } catch (e) {
-        supported = false;
-      }
-    }
-    return supported;
-  })();
-
-  Backbone.fetchCache = (Backbone.fetchCache || {});
-  Backbone.fetchCache._cache = (Backbone.fetchCache._cache || {});
-
-  Backbone.fetchCache.priorityFn = function(a, b) {
-    if (!a || !a.expires || !b || !b.expires) {
-      return a;
-    }
-
-    return a.expires - b.expires;
-  };
-
-  Backbone.fetchCache._prioritize = function() {
-    var sorted = _.values(this._cache).sort(this.priorityFn);
-    var index = _.indexOf(_.values(this._cache), sorted[0]);
-    return _.keys(this._cache)[index];
-  };
-
-  Backbone.fetchCache._deleteCacheWithPriority = function() {
-    Backbone.fetchCache._cache[this._prioritize()] = null;
-    delete Backbone.fetchCache._cache[this._prioritize()];
-    Backbone.fetchCache.setLocalStorage();
-  };
-
-  Backbone.fetchCache.getLocalStorageKey = function() {
-    return 'backboneCache';
-  };
-
-  if (typeof Backbone.fetchCache.localStorage === 'undefined') {
-    Backbone.fetchCache.localStorage = true;
-  }
-
-  // Shared methods
-  function getCacheKey(instance, opts) {
-    var url;
-
-    if(opts && opts.url) {
-      url = opts.url;
-    } else {
-      url = _.isFunction(instance.url) ? instance.url() : instance.url;
-    }
-
-    // Need url to use as cache key so return if we can't get it
-    if(!url) { return; }
-
-    if(opts && opts.data) {
-      return url + "?" + $.param(opts.data);
-    }
-    return url;
-  }
-
-  function setCache(instance, opts, attrs) {
-    opts = (opts || {});
-    var key = Backbone.fetchCache.getCacheKey(instance, opts),
-        expires = false;
-
-    // Need url to use as cache key so return if we can't get it
-    if (!key) { return; }
-
-    // Never set the cache if user has explicitly said not to
-    if (opts.cache === false) { return; }
-
-    // Don't set the cache unless cache: true or prefill: true option is passed
-    if (!(opts.cache || opts.prefill)) { return; }
-
-    if (opts.expires !== false) {
-      expires = (new Date()).getTime() + ((opts.expires || 5 * 60) * 1000);
-    }
-
-    Backbone.fetchCache._cache[key] = {
-      expires: expires,
-      value: attrs
-    };
-
-    Backbone.fetchCache.setLocalStorage();
-  }
-
-  function clearItem(key) {
-    if (_.isFunction(key)) { key = key(); }
-    delete Backbone.fetchCache._cache[key];
-    Backbone.fetchCache.setLocalStorage();
-  }
-
-  function setLocalStorage() {
-    if (!supportLocalStorage || !Backbone.fetchCache.localStorage) { return; }
-    try {
-      localStorage.setItem(Backbone.fetchCache.getLocalStorageKey(), JSON.stringify(Backbone.fetchCache._cache));
-    } catch (err) {
-      var code = err.code || err.number || err.message;
-      if (code === 22) {
-        this._deleteCacheWithPriority();
-      } else {
-        throw(err);
-      }
-    }
-  }
-
-  function getLocalStorage() {
-    if (!supportLocalStorage || !Backbone.fetchCache.localStorage) { return; }
-    var json = localStorage.getItem(Backbone.fetchCache.getLocalStorageKey()) || '{}';
-    Backbone.fetchCache._cache = JSON.parse(json);
-  }
-
-  function nextTick(fn) {
-    return window.setTimeout(fn, 0);
-  }
-
-  // Instance methods
-  Backbone.Model.prototype.fetch = function(opts) {
-    opts = _.defaults(opts || {}, { parse: true });
-    var key = Backbone.fetchCache.getCacheKey(this, opts),
-        data = Backbone.fetchCache._cache[key],
-        expired = false,
-        attributes = false,
-        deferred = new $.Deferred(),
-        self = this;
-
-    function setData() {
-      if (opts.parse) {
-        attributes = self.parse(attributes, opts);
-      }
-
-      self.set(attributes, opts);
-      if (_.isFunction(opts.prefillSuccess)) { opts.prefillSuccess(self, attributes, opts);
}
-
-      // Trigger sync events
-      self.trigger('cachesync', self, attributes, opts);
-      self.trigger('sync', self, attributes, opts);
-
-      // Notify progress if we're still waiting for an AJAX call to happen...
-      if (opts.prefill) { deferred.notify(self); }
-      // ...finish and return if we're not
-      else {
-        if (_.isFunction(opts.success)) { opts.success(self, attributes, opts); }
-        deferred.resolve(self);
-      }
-    }
-
-    if (data) {
-      expired = data.expires;
-      expired = expired && data.expires < (new Date()).getTime();
-      attributes = data.value;
-    }
-
-    if (!expired && (opts.cache || opts.prefill) && attributes) {
-      // Ensure that cache resolution adhers to async option, defaults to true.
-      if (opts.async == null) { opts.async = true; }
-
-      if (opts.async) {
-        nextTick(setData);
-      } else {
-        setData();
-      }
-
-      if (!opts.prefill) {
-        return deferred;
-      }
-    }
-
-    // Delegate to the actual fetch method and store the attributes in the cache
-    superMethods.modelFetch.apply(this, arguments)
-      // resolve the returned promise when the AJAX call completes
-      .done( _.bind(deferred.resolve, this, this) )
-      // Set the new data in the cache
-      .done( _.bind(Backbone.fetchCache.setCache, null, this, opts) )
-      // Reject the promise on fail
-      .fail( _.bind(deferred.reject, this, this) );
-
-    // return a promise which provides the same methods as a jqXHR object
-    return deferred;
-  };
-
-  // Override Model.prototype.sync and try to clear cache items if it looks
-  // like they are being updated.
-  Backbone.Model.prototype.sync = function(method, model, options) {
-    // Only empty the cache if we're doing a create, update, patch or delete.
-    if (method === 'read') {
-      return superMethods.modelSync.apply(this, arguments);
-    }
-
-    var collection = model.collection,
-        keys = [],
-        i, len;
-
-    // Build up a list of keys to delete from the cache, starting with this
-    keys.push(Backbone.fetchCache.getCacheKey(model, options));
-
-    // If this model has a collection, also try to delete the cache for that
-    if (!!collection) {
-      keys.push(Backbone.fetchCache.getCacheKey(collection));
-    }
-
-    // Empty cache for all found keys
-    for (i = 0, len = keys.length; i < len; i++) { clearItem(keys[i]); }
-
-    return superMethods.modelSync.apply(this, arguments);
-  };
-
-  Backbone.Collection.prototype.fetch = function(opts) {
-    opts = _.defaults(opts || {}, { parse: true });
-    var key = Backbone.fetchCache.getCacheKey(this, opts),
-        data = Backbone.fetchCache._cache[key],
-        expired = false,
-        attributes = false,
-        deferred = new $.Deferred(),
-        self = this;
-
-    function setData() {
-      self[opts.reset ? 'reset' : 'set'](attributes, opts);
-      if (_.isFunction(opts.prefillSuccess)) { opts.prefillSuccess(self); }
-
-      // Trigger sync events
-      self.trigger('cachesync', self, attributes, opts);
-      self.trigger('sync', self, attributes, opts);
-
-      // Notify progress if we're still waiting for an AJAX call to happen...
-      if (opts.prefill) { deferred.notify(self); }
-      // ...finish and return if we're not
-      else {
-        if (_.isFunction(opts.success)) { opts.success(self, attributes, opts); }
-        deferred.resolve(self);
-      }
-    }
-
-    if (data) {
-      expired = data.expires;
-      expired = expired && data.expires < (new Date()).getTime();
-      attributes = data.value;
-    }
-
-    if (!expired && (opts.cache || opts.prefill) && attributes) {
-      // Ensure that cache resolution adhers to async option, defaults to true.
-      if (opts.async == null) { opts.async = true; }
-
-      if (opts.async) {
-        nextTick(setData);
-      } else {
-        setData();
-      }
-
-      if (!opts.prefill) {
-        return deferred;
-      }
-    }
-
-    // Delegate to the actual fetch method and store the attributes in the cache
-    superMethods.collectionFetch.apply(this, arguments)
-      // resolve the returned promise when the AJAX call completes
-      .done( _.bind(deferred.resolve, this, this) )
-      // Set the new data in the cache
-      .done( _.bind(Backbone.fetchCache.setCache, null, this, opts) )
-      // Reject the promise on fail
-      .fail( _.bind(deferred.reject, this, this) );
-
-    // return a promise which provides the same methods as a jqXHR object
-    return deferred;
-  };
-
-  // Prime the cache from localStorage on initialization
-  getLocalStorage();
-
-  // Exports
-
-  Backbone.fetchCache._superMethods = superMethods;
-  Backbone.fetchCache.setCache = setCache;
-  Backbone.fetchCache.getCacheKey = getCacheKey;
-  Backbone.fetchCache.clearItem = clearItem;
-  Backbone.fetchCache.setLocalStorage = setLocalStorage;
-  Backbone.fetchCache.getLocalStorage = getLocalStorage;
-
-  return Backbone;
-}));

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/af19be10/tasks/couchserver.js
----------------------------------------------------------------------
diff --git a/tasks/couchserver.js b/tasks/couchserver.js
index 21c2fcb..95b05e8 100644
--- a/tasks/couchserver.js
+++ b/tasks/couchserver.js
@@ -47,7 +47,9 @@ module.exports = function (grunt) {
           accept = req.headers.accept.split(','),
           filePath;
 
-      if (!!url.match(/assets/)) {
+      if (!!url.match(/^\/addons\/.*\/assets\/js/)) {
+        filePath = path.join(app_dir, url.replace('/_utils/fauxton/',''));
+      } else if (!!url.match(/assets/)) {
         // serve any javascript or css files from here assets dir
         filePath = path.join('./',url);
       } else if (!!url.match(/mocha|\/test\/core\/|test\.config/)) {


Mime
View raw message