Skip to content

Commit

Permalink
Adds currentPath to Ember.StateManager
Browse files Browse the repository at this point in the history
This is a shorthand so you don't have to type
router.get('currentState.path') all the time.
  • Loading branch information
Tom Dale committed Aug 28, 2012
1 parent bad5379 commit 9ecb570
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/ember-states/lib/state_manager.js
Expand Up @@ -585,6 +585,17 @@ Ember.StateManager = Ember.State.extend(
*/
currentState: null,

/**
The path of the current state. Returns a string representation of the current
state.
@type String
@readOnly
*/
currentPath: Ember.computed('currentState', function() {
return get(this, 'currentState.path');
}).cacheable(),

/**
The name of transitionEvent that this stateManager will dispatch
Expand Down
10 changes: 10 additions & 0 deletions packages/ember-states/tests/state_manager_test.js
Expand Up @@ -77,6 +77,16 @@ test("it reports its current state", function() {
ok(get(stateManager, 'currentState') === loadedState, "currentState can change to a sibling state");
});

test("it reports its current state path", function() {
strictEqual(get(stateManager, 'currentPath'), null, "currentPath defaults to null if no state is specified");

stateManager.transitionTo('loadingState');
equal(get(stateManager, 'currentPath'), 'loadingState', "currentPath changes after transitionTo() is called");

stateManager.transitionTo('loadedState');
equal(get(stateManager, 'currentPath'), 'loadedState', "currentPath can change to a sibling state");
});

test("it sends enter and exit events during state transitions", function() {
stateManager.transitionTo('loadingState');

Expand Down

0 comments on commit 9ecb570

Please sign in to comment.