[Pkg-javascript-commits] [backbone] 32/281: added a test and code to allow a router to define a route with no callback method for the route name

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:01:53 UTC 2014


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

js pushed a commit to tag 0.9.0
in repository backbone.

commit 6799c8e8be220f085ba63d44f8e626f9b5bfef0c
Author: Derick Bailey <derickbailey at gmail.com>
Date:   Thu Oct 6 19:09:53 2011 -0500

    added a test and code to allow a router to define a route with no callback method for the route name
---
 backbone.js    |  4 +++-
 test/router.js | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/backbone.js b/backbone.js
index ebb0497..d0f49e1 100644
--- a/backbone.js
+++ b/backbone.js
@@ -686,7 +686,9 @@
       if (!_.isRegExp(route)) route = this._routeToRegExp(route);
       Backbone.history.route(route, _.bind(function(fragment) {
         var args = this._extractParameters(route, fragment);
-        callback.apply(this, args);
+        if (callback){
+          callback.apply(this, args);
+        }
         this.trigger.apply(this, ['route:' + name].concat(args));
       }, this));
     },
diff --git a/test/router.js b/test/router.js
index 2562b0c..4e84023 100644
--- a/test/router.js
+++ b/test/router.js
@@ -5,6 +5,7 @@ $(document).ready(function() {
   var Router = Backbone.Router.extend({
 
     routes: {
+      "noCallback":                 "noCallback",
       "search/:query":              "search",
       "search/:query/p:page":       "search",
       "splat/*args/end":            "splat",
@@ -41,6 +42,8 @@ $(document).ready(function() {
       this.anything = whatever;
     }
 
+    // do not provide a callback method for the noCallback route
+
   });
 
   Backbone.history = null;
@@ -113,4 +116,20 @@ $(document).ready(function() {
     }, 10);
   });
 
+  asyncTest("Router: fires event when router doesn't have callback on it", 1, function() {
+    try{
+      var callbackFired = false;
+      var myCallback = function(){ callbackFired = true; }
+      router.bind("route:noCallback", myCallback);
+      window.location.hash = "noCallback";
+      setTimeout(function(){
+        equals(callbackFired, true);
+        start();
+        window.location.hash = '';
+      }, 10);
+    } catch (err) {
+      ok(false, "an exception was thrown trying to fire the router event with no router handler callback");
+    }
+  });
+
 });

-- 
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