Skip to content

Commit

Permalink
fix(future): Allow future states to specify a parent:
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Jun 6, 2017
1 parent 284392d commit 828fe1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/state/stateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,21 @@ export class StateBuilder {
}

parentName(state: StateObject) {
// name = 'foo.bar.baz.**'
let name = state.name || "";

// segments = ['foo', 'bar', 'baz', '.**']
let segments = name.split('.');
if (segments.length > 1) {
// segments = ['foo', 'bar', 'baz']
let lastSegment = segments.pop();
// segments = ['foo', 'bar'] (ignore .** segment for future states)
if (lastSegment === '**') segments.pop();

if (segments.length) {
if (state.parent) {
throw new Error(`States that specify the 'parent:' property should not have a '.' in their name (${name})`);
}
var lastSegment = segments.pop();
if (lastSegment === '**') segments.pop();

// 'foo.bar'
return segments.join(".");
}

Expand Down
4 changes: 4 additions & 0 deletions test/stateBuilderSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ describe('StateBuilder', function() {
let errorState = { name: 'home.error', parent: 'home' };
expect(() => builder.parentName(errorState)).toThrowError();
});
it('should not error if parent: is specified and the (future state) name ends in .**', function() {
let futureState = { name: 'child.**', parent: 'home' };
expect(builder.parentName(futureState)).toBe('home');
});
});
});

Expand Down

0 comments on commit 828fe1b

Please sign in to comment.