From d34c452cf0ffc307d65efa31e35c652da0803d4d Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Sun, 4 Jun 2017 20:30:30 -0700 Subject: [PATCH] fix(future): Allow future states to specify a `parent:` --- src/state/stateBuilder.ts | 14 ++++++++++---- test/stateBuilderSpec.ts | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/state/stateBuilder.ts b/src/state/stateBuilder.ts index ec1764f0..0f029a0a 100644 --- a/src/state/stateBuilder.ts +++ b/src/state/stateBuilder.ts @@ -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("."); } diff --git a/test/stateBuilderSpec.ts b/test/stateBuilderSpec.ts index 38734b8e..79dd215c 100644 --- a/test/stateBuilderSpec.ts +++ b/test/stateBuilderSpec.ts @@ -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'); + }); }); });