Skip to content

Commit

Permalink
fix(paramTypes.hash): Update hash for each transition
Browse files Browse the repository at this point in the history
The hash parameter (`#`) is now a `dynamic: true` param, and equals are compared with coersion, such that "" == undefined == null.
Closes #2742
  • Loading branch information
christopherthielen committed May 12, 2016
1 parent f9c3e3c commit 79d4fd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/params/paramTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ParamTypes {
decode: valFromString,
is: is(String),
pattern: /.*/,
equals: val(true)
equals: (a, b) => a == b // allow coersion for null/undefined/""
},
"string": {
encode: valToString,
Expand Down
2 changes: 1 addition & 1 deletion src/state/stateRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class StateRegistry {
url: '^',
views: null,
params: {
'#': { value: null, type: 'hash' }
'#': { value: null, type: 'hash', dynamic: true }
},
abstract: true
};
Expand Down
15 changes: 15 additions & 0 deletions test/ng1/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,21 @@ describe('state', function () {
expect($location.hash()).toBe('frag');
}));

it('runs a transition when the location #fragment is updated', inject(function ($state, $q, $location, $transitions) {
var transitionCount = 0;
$transitions.onSuccess({}, function() { transitionCount++; });

$state.transitionTo('home.item', {id: 'world', '#': 'frag'});
$q.flush();
expect($location.hash()).toBe('frag');
expect(transitionCount).toBe(1);

$state.transitionTo('home.item', {id: 'world', '#': 'blarg'});
$q.flush();
expect($location.hash()).toBe('blarg');
expect(transitionCount).toBe(2);
}));

it('injects $transition$ into resolves', inject(function ($state, $q) {
$state.transitionTo('home'); $q.flush();
$state.transitionTo('about'); $q.flush();
Expand Down

0 comments on commit 79d4fd7

Please sign in to comment.