Skip to content
This repository has been archived by the owner on Sep 20, 2020. It is now read-only.

Commit

Permalink
fix(sticky): fixed reload: true for ui-router 0.2.8
Browse files Browse the repository at this point in the history
- in 0.2.8, params and ownParams were arrays of strings.

( Additional fix for  #139 )
  • Loading branch information
christopherthielen committed Jan 31, 2015
1 parent c8eff13 commit 8278337
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
28 changes: 18 additions & 10 deletions src/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ angular.module("ct.ui.router.extras.sticky").config(
savedFromStatePath = fromState.path;

// Try to resolve options.reload to a state. If so, we'll reload only up to the given state.
var reload = options && options.reload;
var reloadStateTree = (reload === true ? savedToStatePath[0].self : $state.get(reload, rel));
var reload = options && options.reload || false;
var reloadStateTree = reload && (reload === true ? savedToStatePath[0].self : $state.get(reload, rel));
// If options.reload is a string or a state, we want to handle reload ourselves and not
// let ui-router reload the entire toPath.
if (options && reload && reload !== true)
Expand All @@ -295,17 +295,25 @@ angular.module("ct.ui.router.extras.sticky").config(
// being reloaded, and add a param value to the transition. This will cause the "has params changed
// for state" check to return false, and the states will be reloaded.
if (reloadStateTree) {
currentTransition.toParams.$$uirouterextrasreload = Math.random();
var params = reloadStateTree.$$state().params;
var ownParams = reloadStateTree.$$state().ownParams;

var tempParam = new $urlMatcherFactoryProvider.Param('$$uirouterextrasreload');
params.$$uirouterextrasreload = ownParams.$$uirouterextrasreload = tempParam;
currentTransition.toParams.$$uirouterextrasreload = Math.random();

restore.restoreFunctions.push(function() {
delete params.$$uirouterextrasreload;
delete ownParams.$$uirouterextrasreload;
});
if (versionHeuristics.hasParamSet) {
var tempParam = new $urlMatcherFactoryProvider.Param('$$uirouterextrasreload');
params.$$uirouterextrasreload = ownParams.$$uirouterextrasreload = tempParam;
restore.restoreFunctions.push(function() {
delete params.$$uirouterextrasreload;
delete ownParams.$$uirouterextrasreload;
});
} else {
params.push('$$uirouterextrasreload');
ownParams.push('$$uirouterextrasreload');
restore.restoreFunctions.push(function() {
params.length = params.length -1;
ownParams.length = ownParams.length -1;
});
}
}

// $StickyStateProvider.processTransition analyzes the states involved in the pending transition. It
Expand Down
2 changes: 1 addition & 1 deletion src/stickyProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function $StickyStateProvider($stateProvider) {

// Duplicates logic in $state.transitionTo, primarily to find the pivot state (i.e., the "keep" value)
function equalForKeys(a, b, keys) {
if (angular.isObject(keys)) {
if (!angular.isArray(keys) && angular.isObject(keys)) {
keys = protoKeys(keys, ["$$keys", "$$values", "$$equals", "$$validates", "$$new", "$$parent"]);
}
if (!keys) {
Expand Down
4 changes: 2 additions & 2 deletions test/stickySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('stickyState', function () {
return {
'main': {},
'main.other': { sticky: true, views: { 'other@main': {} } },
'main.product': { sticky: true, views: { 'product@main': {} }, params: { 'product_id': 15 } },
'main.product': { sticky: true, views: { 'product@main': {} }, url: '/:product_id' },
'main.product.something': {}
};
}
Expand Down Expand Up @@ -404,7 +404,7 @@ describe('stickyState', function () {
testGo('A._1', { entered: ['A', 'A._1' ] });
testGo('A._2', { inactivated: [ 'A._1' ], entered: 'A._2' });
testGo('A._1', { reactivated: 'A._1', inactivated: 'A._2' });
resetTransitionLog();
// resetTransitionLog();
testGo('A._2', { exited: [ 'A._1', 'A._2', 'A' ], entered: [ 'A', 'A._2' ] }, { reload: true });
});
});
Expand Down

0 comments on commit 8278337

Please sign in to comment.