diff --git a/src/common.js b/src/common.js index 9f73bacda..7e2209cb8 100644 --- a/src/common.js +++ b/src/common.js @@ -108,23 +108,6 @@ function inheritParams(currentParams, newParams, $current, $to) { return extend({}, inherited, newParams); } -/** - * Normalizes a set of values to string or `null`, filtering them by a list of keys. - * - * @param {Array} keys The list of keys to normalize/return. - * @param {Object} values An object hash of values to normalize. - * @return {Object} Returns an object hash of normalized string values. - */ -function normalize(keys, values) { - var normalized = {}; - - forEach(keys, function (name) { - var value = values[name]; - normalized[name] = (value != null) ? String(value) : null; - }); - return normalized; -} - /** * Performs a non-strict comparison of the subset of two objects, defined by a list of keys. * diff --git a/src/state.js b/src/state.js index 905b89e8f..abf794439 100644 --- a/src/state.js +++ b/src/state.js @@ -814,8 +814,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { return $q.when($state.current); } - // Normalize/filter parameters before we pass them to event handlers etc. - toParams = normalize(to.params, toParams || {}); + // Filter parameters before we pass them to event handlers etc. + toParams = filterByKeys(to.params, toParams || {}); // Broadcast start event and cancel the transition if requested if (options.notify) { @@ -1102,7 +1102,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { if (!nav || !nav.url) { return null; } - return $urlRouter.href(nav.url, normalize(state.params, params || {}), { absolute: options.absolute }); + return $urlRouter.href(nav.url, filterByKeys(state.params, params || {}), { absolute: options.absolute }); }; /** diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index 244f0a060..68c2973d8 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -125,7 +125,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual('contacts.item.detail'); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $document, $q) { @@ -142,7 +142,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual('contacts.item.detail'); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $document, $q) { @@ -153,7 +153,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states when meta-clicked', inject(function($state, $stateParams, $document, $q) { @@ -164,7 +164,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states when shift-clicked', inject(function($state, $stateParams, $document, $q) { @@ -175,7 +175,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states when middle-clicked', inject(function($state, $stateParams, $document, $q) { @@ -186,7 +186,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states when element has target specified', inject(function($state, $stateParams, $document, $q) { @@ -198,7 +198,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should not transition states if preventDefault() is called in click handler', inject(function($state, $stateParams, $document, $q) { @@ -212,7 +212,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.current.name).toEqual(''); - expect($stateParams).toEqual({ id: "5" }); + expect($stateParams).toEqual({ id: 5 }); })); it('should allow passing params to current state', inject(function($compile, $rootScope, $state) { @@ -277,7 +277,7 @@ describe('uiStateRef', function() { $q.flush(); expect($state.$current.name).toBe("contacts.item.detail"); - expect($state.params).toEqual({ id: '5' }); + expect($state.params).toEqual({ id: 5 }); })); it('should resolve states from parent uiView', inject(function ($state, $stateParams, $q, $timeout) { diff --git a/test/stateSpec.js b/test/stateSpec.js index 7dcae9f3f..e9036f835 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -265,7 +265,7 @@ describe('state', function () { $q.flush(); expect(called).toBeTruthy(); expect($state.current.name).toEqual('DDD'); - expect($state.params).toEqual({ x: '1', y: '2', z: '3', w: '4' }); + expect($state.params).toEqual({ x: 1, y: 2, z: 3, w: 4 }); })); it('can defer a state transition in $stateNotFound', inject(function ($state, $q, $rootScope) { @@ -282,7 +282,7 @@ describe('state', function () { $q.flush(); expect(called).toBeTruthy(); expect($state.current.name).toEqual('AA'); - expect($state.params).toEqual({ a: '1' }); + expect($state.params).toEqual({ a: 1 }); })); it('can defer and supersede a state transition in $stateNotFound', inject(function ($state, $q, $rootScope) { @@ -475,7 +475,7 @@ describe('state', function () { $q.flush(); expect($state.$current.name).toBe('about.person.item'); - expect($stateParams).toEqual({ person: 'bob', id: '5' }); + expect($stateParams).toEqual({ person: 'bob', id: 5 }); $state.go('^.^.sidebar'); $q.flush(); @@ -603,7 +603,7 @@ describe('state', function () { it('contains the parameter values for the current state', inject(function ($state, $q) { initStateTo(D, { x: 'x value', z: 'invalid value' }); - expect($state.params).toEqual({ x: 'x value', y: null }); + expect($state.params).toEqual({ x: 'x value', y: undefined }); })); }); @@ -878,16 +878,16 @@ describe('state', function () { describe('substate and stateParams inheritance', function() { it('should inherit the parent param', inject(function ($state, $stateParams, $q) { - initStateTo($state.get('root'), {param1: 1}); - $state.go('root.sub1', {param2: 2}); + initStateTo($state.get('root'), { param1: 1 }); + $state.go('root.sub1', { param2: 2 }); $q.flush(); expect($state.current.name).toEqual('root.sub1'); - expect($stateParams).toEqual({param1: '1', param2: '2'}); + expect($stateParams).toEqual({ param1: 1, param2: 2 }); })); it('should not inherit siblings\' states', inject(function ($state, $stateParams, $q) { - initStateTo($state.get('root'), {param1: 1}); - $state.go('root.sub1', {param2: 2}); + initStateTo($state.get('root'), { param1: 1 }); + $state.go('root.sub1', { param2: 2 }); $q.flush(); expect($state.current.name).toEqual('root.sub1'); @@ -895,7 +895,7 @@ describe('state', function () { $q.flush(); expect($state.current.name).toEqual('root.sub2'); - expect($stateParams).toEqual({param1: '1', param2: null}); + expect($stateParams).toEqual({ param1: 1, param2: undefined }); })); });