From 987b07e5d9a51e4f2a95e53a43b8847fa6474726 Mon Sep 17 00:00:00 2001 From: Edward Hutchins Date: Thu, 12 Sep 2013 14:25:39 -0700 Subject: [PATCH 1/3] Added $state.getAll to return the entire state table. --- src/state.js | 6 ++++++ test/stateSpec.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/state.js b/src/state.js index 8020876a6..9445c270b 100644 --- a/src/state.js +++ b/src/state.js @@ -348,6 +348,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $ return (state && state.self) ? state.self : null; }; + $state.getAll = function () { + var list = []; + forEach(states, function(state) { list.push(state.self); }); + return list; + }; + function resolveState(state, params, paramsAreFiltered, inherited, dst) { // Make a restricted $stateParams with only the parameters that apply to this state if // necessary. In addition to being available to the controller and onEnter/onExit callbacks, diff --git a/test/stateSpec.js b/test/stateSpec.js index 02b180a96..87743a7d7 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -393,6 +393,32 @@ describe('state', function () { expect($state.get('A')).toBe(A); expect($state.get('Z')).toBeNull(); })); + + it("should return all of the state's config", inject(function ($state) { + var list = $state.getAll(); + var names = [ + '', // implicit root state + 'A', + 'B', + 'C', + 'D', + 'DD', + 'E', + 'H', + 'HH', + 'HHH', + 'home', + 'home.item', + 'about', + 'about.person', + 'about.person.item', + 'about.sidebar', + 'about.sidebar.item', + 'first', + 'second' + ]; + expect(list.map(function(state) { return state.name; })).toEqual(names); + })); }); describe('url handling', function () { From 4ac2edb199a0e751a7f12d2c0cb91245c77266ef Mon Sep 17 00:00:00 2001 From: Edward Hutchins Date: Thu, 12 Sep 2013 14:31:37 -0700 Subject: [PATCH 2/3] Sort to ensure ordering. --- test/stateSpec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/stateSpec.js b/test/stateSpec.js index 87743a7d7..66822fc38 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -395,7 +395,7 @@ describe('state', function () { })); it("should return all of the state's config", inject(function ($state) { - var list = $state.getAll(); + var list = $state.getAll().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); }); var names = [ '', // implicit root state 'A', @@ -407,14 +407,14 @@ describe('state', function () { 'H', 'HH', 'HHH', - 'home', - 'home.item', 'about', 'about.person', 'about.person.item', 'about.sidebar', 'about.sidebar.item', 'first', + 'home', + 'home.item', 'second' ]; expect(list.map(function(state) { return state.name; })).toEqual(names); From e1136b3c6ae3e22f769236411453396acb93550a Mon Sep 17 00:00:00 2001 From: Edward Hutchins Date: Thu, 12 Sep 2013 16:21:13 -0700 Subject: [PATCH 3/3] Switch to an empty `$state.get()` as the API (as per #411). --- src/state.js | 11 +++++------ test/stateSpec.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/state.js b/src/state.js index 9445c270b..a2717bd37 100644 --- a/src/state.js +++ b/src/state.js @@ -344,16 +344,15 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $ }; $state.get = function (stateOrName) { + if (!isDefined(stateOrName)) { + var list = []; + forEach(states, function(state) { list.push(state.self); }); + return list; + } var state = findState(stateOrName); return (state && state.self) ? state.self : null; }; - $state.getAll = function () { - var list = []; - forEach(states, function(state) { list.push(state.self); }); - return list; - }; - function resolveState(state, params, paramsAreFiltered, inherited, dst) { // Make a restricted $stateParams with only the parameters that apply to this state if // necessary. In addition to being available to the controller and onEnter/onExit callbacks, diff --git a/test/stateSpec.js b/test/stateSpec.js index 66822fc38..2f433e41a 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -395,7 +395,7 @@ describe('state', function () { })); it("should return all of the state's config", inject(function ($state) { - var list = $state.getAll().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); }); + var list = $state.get().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); }); var names = [ '', // implicit root state 'A',