[Pkg-javascript-commits] [backbone] 56/74: commentng out Backbone.Controller

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.0
in repository backbone.

commit 3fc9ef1e6b2835945a3f6a63ccbd97473dad33a0
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Mon Nov 8 14:22:22 2010 -0500

    commentng out Backbone.Controller
---
 backbone.js | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/backbone.js b/backbone.js
index 82550f6..b1d8e97 100644
--- a/backbone.js
+++ b/backbone.js
@@ -565,7 +565,8 @@
   // Backbone.Controller
   // -------------------
 
-  // Creating a Backbone.Controller sets its `urls` hash, if not set statically.
+  // Controllers map faux-URLs to actions, and fire events when routes are
+  // matched. Creating a new one sets its `routes` hash, if not set statically.
   Backbone.Controller = function(options) {
     options || (options = {});
     if (options.routes) this.routes = options.routes;
@@ -573,12 +574,15 @@
     if (this.initialize) this.initialize(options);
   };
 
+  // Cached regular expressions for matching named param parts and splatted
+  // parts of route strings.
   var namedParam = /:([\w\d]+)/g;
   var splatParam = /\*([\w\d]+)/g;
 
   // Set up all inheritable **Backbone.Controller** properties and methods.
   _.extend(Backbone.Controller.prototype, Backbone.Events, {
 
+    // Bind all defined routes to `Backbone.history`.
     bindRoutes : function() {
       if (!this.routes) return;
       for (var route in this.routes) {
@@ -587,27 +591,37 @@
       }
     },
 
+    // Manually bind a single named route to a callback. For example:
+    //
+    //     this.route('search/:query/p:page', 'search', function(query, page) {
+    //       ...
+    //     });
+    //
     route : function(route, name, callback) {
       Backbone.history || (Backbone.history = new Backbone.History);
       if (!_.isRegExp(route)) route = this._routeToRegExp(route);
       Backbone.history.route(route, _.bind(function(fragment) {
-        var args = this._extractArguments(route, fragment);
+        var args = this._extractParameters(route, fragment);
         callback.apply(this, args);
-        var cargs = ['route:' + (name || callback)].concat(args);
-        this.trigger.apply(this, args);
+        this.trigger.apply(this, ['route:' + name].concat(args));
       }, this));
     },
 
+    // Simply proxy to `Backbone.history` to save a fragment into the history.
     save : function(fragment) {
       Backbone.history.save(fragment);
     },
 
+    // Convert a route string into a regular expression, suitable for matching
+    // against `window.location.hash`.
     _routeToRegExp : function(route) {
       route = route.replace(namedParam, "([^\/]*)").replace(splatParam, "(.*?)");
       return new RegExp('^#' + route + '$');
     },
 
-    _extractArguments : function(route, fragment) {
+    // Given a route, and a URL fragment that it matches, return the array of
+    // extracted parameters.
+    _extractParameters : function(route, fragment) {
       return route.exec(fragment).slice(1);
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list