Created
October 19, 2012 18:06
-
-
Save kpdecker/3919679 to your computer and use it in GitHub Desktop.
Possible bindToRoute programatic navigation fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/js/lib/backbone.historytracker.js b/js/lib/backbone.historytracker.js | |
index 9dbedd6..f9f4dc5 100644 | |
--- a/js/lib/backbone.historytracker.js | |
+++ b/js/lib/backbone.historytracker.js | |
@@ -100,6 +100,10 @@ | |
} | |
} | |
_navigate.call(this, fragment, options); | |
+ | |
+ if (!options || !options.trigger) { | |
+ Backbone.history.trigger('route:ignored', route); | |
+ } | |
}, | |
_updateHash: function(location, frag, replace) { | |
@@ -132,6 +136,7 @@ | |
this._ignoreChange = false; | |
this._directionIndex = Backbone.history.loadIndex(); | |
this._pendingNavigate && setTimeout(Backbone.history._pendingNavigate, 0); | |
+ Backbone.history.trigger('route:ignored', route); | |
} else { | |
try { | |
callback && callback.apply(this, arguments); | |
diff --git a/js/lib/thorax.js b/js/lib/thorax.js | |
index 97d16dc..b8dd622 100644 | |
--- a/js/lib/thorax.js | |
+++ b/js/lib/thorax.js | |
@@ -1188,7 +1188,7 @@ | |
}); | |
function bindToRoute(callback, failback) { | |
- var fragment = Backbone.history.getFragment(), | |
+ var fragment, | |
completed; | |
function finalizer(isCanceled) { | |
@@ -1207,6 +1207,7 @@ | |
completed = true; | |
Backbone.history.unbind('route', resetLoader); | |
+ Backbone.history.unbind('route:ignored', updateFragment); | |
var args = Array.prototype.slice.call(arguments, 1); | |
if (!isCanceled && same) { | |
@@ -1215,10 +1216,19 @@ | |
failback && failback.apply(this, args); | |
} | |
} | |
+ function updateFragment() { | |
+ fragment = Backbone.history.getFragment(); | |
+ } | |
+ | |
+ updateFragment(); | |
var resetLoader = _.bind(finalizer, this, true); | |
Backbone.history.bind('route', resetLoader); | |
+ // If we are navigating due to an ignored event we don't want to fail. | |
+ // This is primariy | |
+ Backbone.history.bind('route:ignored', updateFragment); | |
+ | |
return _.bind(finalizer, this, false); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment