mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 05:48:10 -05:00
added a test and code to allow a router to define a route with no callback method for the route name
This commit is contained in:
@@ -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));
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user