mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 13:28:22 -05:00
Merge pull request #862 from braddunbar/implicit-callback
Router: Use implicit callback if none provided
This commit is contained in:
@@ -709,6 +709,7 @@
|
||||
route : function(route, name, callback) {
|
||||
Backbone.history || (Backbone.history = new Backbone.History);
|
||||
if (!_.isRegExp(route)) route = this._routeToRegExp(route);
|
||||
if (!callback) callback = this[name];
|
||||
Backbone.history.route(route, _.bind(function(fragment) {
|
||||
var args = this._extractParameters(route, fragment);
|
||||
callback && callback.apply(this, args);
|
||||
|
||||
@@ -19,12 +19,17 @@ $(document).ready(function() {
|
||||
|
||||
initialize : function(options) {
|
||||
this.testing = options.testing;
|
||||
this.route('implicit', 'implicit');
|
||||
},
|
||||
|
||||
counter: function() {
|
||||
this.count++;
|
||||
},
|
||||
|
||||
implicit: function() {
|
||||
this.count++;
|
||||
},
|
||||
|
||||
search : function(query, page) {
|
||||
this.query = query;
|
||||
this.page = page;
|
||||
@@ -114,6 +119,12 @@ $(document).ready(function() {
|
||||
equals(router.count, 2);
|
||||
});
|
||||
|
||||
test("Router: use implicit callback if none provided", function() {
|
||||
router.count = 0;
|
||||
router.navigate('implicit', {trigger: true})
|
||||
equals(router.count, 1);
|
||||
});
|
||||
|
||||
asyncTest("Router: routes via navigate with {replace: true}", function() {
|
||||
var historyLength = window.history.length;
|
||||
router.navigate('search/manhattan/start_here');
|
||||
|
||||
Reference in New Issue
Block a user