Skip to content

Commit 69818c9

Browse files
committed
Merge pull request #411 from Demeterr/add-state-getAll
Add `$state.getAll()`
2 parents f07ab2d + e1136b3 commit 69818c9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/state.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
365365
};
366366

367367
$state.get = function (stateOrName) {
368+
if (!isDefined(stateOrName)) {
369+
var list = [];
370+
forEach(states, function(state) { list.push(state.self); });
371+
return list;
372+
}
368373
var state = findState(stateOrName);
369374
return (state && state.self) ? state.self : null;
370375
};

test/stateSpec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,32 @@ describe('state', function () {
394394
expect($state.get('A')).toBe(A);
395395
expect($state.get('Z')).toBeNull();
396396
}));
397+
398+
it("should return all of the state's config", inject(function ($state) {
399+
var list = $state.get().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); });
400+
var names = [
401+
'', // implicit root state
402+
'A',
403+
'B',
404+
'C',
405+
'D',
406+
'DD',
407+
'E',
408+
'H',
409+
'HH',
410+
'HHH',
411+
'about',
412+
'about.person',
413+
'about.person.item',
414+
'about.sidebar',
415+
'about.sidebar.item',
416+
'first',
417+
'home',
418+
'home.item',
419+
'second'
420+
];
421+
expect(list.map(function(state) { return state.name; })).toEqual(names);
422+
}));
397423
});
398424

399425
describe('url handling', function () {

0 commit comments

Comments
 (0)