Skip to content

Commit 828fe1b

Browse files
fix(future): Allow future states to specify a parent:
1 parent 284392d commit 828fe1b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/state/stateBuilder.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,21 @@ export class StateBuilder {
295295
}
296296

297297
parentName(state: StateObject) {
298+
// name = 'foo.bar.baz.**'
298299
let name = state.name || "";
299-
300+
// segments = ['foo', 'bar', 'baz', '.**']
300301
let segments = name.split('.');
301-
if (segments.length > 1) {
302+
// segments = ['foo', 'bar', 'baz']
303+
let lastSegment = segments.pop();
304+
// segments = ['foo', 'bar'] (ignore .** segment for future states)
305+
if (lastSegment === '**') segments.pop();
306+
307+
if (segments.length) {
302308
if (state.parent) {
303309
throw new Error(`States that specify the 'parent:' property should not have a '.' in their name (${name})`);
304310
}
305-
var lastSegment = segments.pop();
306-
if (lastSegment === '**') segments.pop();
311+
312+
// 'foo.bar'
307313
return segments.join(".");
308314
}
309315

test/stateBuilderSpec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ describe('StateBuilder', function() {
6363
let errorState = { name: 'home.error', parent: 'home' };
6464
expect(() => builder.parentName(errorState)).toThrowError();
6565
});
66+
it('should not error if parent: is specified and the (future state) name ends in .**', function() {
67+
let futureState = { name: 'child.**', parent: 'home' };
68+
expect(builder.parentName(futureState)).toBe('home');
69+
});
6670
});
6771
});
6872

0 commit comments

Comments
 (0)