You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/04/29 16:46:57 UTC
git commit: updated refs/heads/route-events to 098776a
Updated Branches:
refs/heads/route-events 6ec350527 -> 098776a8f
add callback chain when a route is called
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/098776a8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/098776a8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/098776a8
Branch: refs/heads/route-events
Commit: 098776a8f5bd4b225a30a3c5b23f07423371c15a
Parents: 6ec3505
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Apr 29 16:46:40 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Apr 29 16:46:40 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/api.js | 18 +++++++++++++++
src/fauxton/app/modules/documents/routes.js | 4 +++
src/fauxton/app/router.js | 25 +++++++++++++++++++++-
3 files changed, 46 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/098776a8/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index a7496f4..de0844c 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -96,6 +96,24 @@ function(app, Fauxton) {
}
});
+ FauxtonAPI.routeCallChain = {
+ callChain: {},
+
+ registerBeforeRoute: function (name, fn) {
+ this.callChain[name] = fn;
+ },
+
+ unregisterBeforeRoute: function (name) {
+ delete callChain[name];
+ },
+
+ run: function () {
+ var callChainDeferreds = _.map(this.callChain, function (cb) { return cb(); });
+ return $.when(null, callChainDeferreds );
+ }
+ };
+
+
FauxtonAPI.RouteObject = function(options) {
this._options = options;
http://git-wip-us.apache.org/repos/asf/couchdb/blob/098776a8/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index 519ad7f..78af28e 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -182,6 +182,10 @@ function(app, FauxtonAPI, Documents, Databases) {
var DocumentsRouteObject = FauxtonAPI.RouteObject.extend({
layout: "with_tabs_sidebar",
+ initialize: function () {
+
+ },
+
events: {
"route:all_docs": "allDocs",
"route:all_design_docs": "allDesignDocs"
http://git-wip-us.apache.org/repos/asf/couchdb/blob/098776a8/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index dc04be3..2bcd071 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -97,6 +97,21 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents
};
};
+ FauxtonAPI.routeCallChain.registerBeforeRoute('no_deferred', function () {
+ console.log('This is a before route callback with no deferred.');
+ });
+
+ FauxtonAPI.routeCallChain.registerBeforeRoute('deferred', function () {
+ var deferred = $.Deferred();
+
+ setTimeout(function () {
+ console.log('hi this is a delayed called before each route.');
+ deferred.resolve();
+ }, 10);
+
+ return deferred;
+ });
+
var Router = app.router = Backbone.Router.extend({
routes: {},
@@ -110,14 +125,22 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases, Documents
addModuleRouteObject: function(routeObject) {
var self = this;
var masterLayout = this.masterLayout;
+
_.each(routeObject.get('routes'), function(route) {
this.route(route, route.toString(), function() {
+ var args = arguments;
+
if (self.activeRouteObject && routeObject !== self.activeRouteObject) {
self.activeRouteObject.renderedState = false;
self.activeRouteObject.clearViews();
}
- routeObject.render(route, masterLayout, Array.prototype.slice.call(arguments));
+ FauxtonAPI.routeCallChain.run().then(function () {
+ routeObject.initialize();
+ routeObject.render(route, masterLayout, Array.prototype.slice.call(args));
+ });
+
+ self.activeRouteObject = routeObject;
});
}, this);