@@ -18,16 +18,10 @@ import {abstractKey} from "../common/common";
18
18
* @returns {Function }
19
19
*/
20
20
export default class StateReference {
21
- private _identifier ;
22
- private _definition : IState ;
23
- private _params ;
24
- private _base ;
21
+ constructor ( private _identifier , private _definition : IState , private _params , private _base ) { }
25
22
26
- constructor ( identifier , definition : IState , params , base ) {
27
- this . _identifier = identifier ;
28
- this . _definition = definition ;
29
- this . _params = params ;
30
- this . _base = base ;
23
+ name ( ) {
24
+ return this . _definition && this . _definition . name || this . _identifier ;
31
25
}
32
26
33
27
identifier ( ) {
@@ -58,15 +52,15 @@ export default class StateReference {
58
52
}
59
53
60
54
error ( ) {
61
- switch ( true ) {
62
- case ( ! this . _definition && ! ! this . _base ) :
63
- return `Could not resolve ' ${ this . _identifier } ' from state ' ${ this . _base } '` ;
64
- case ( ! this . _definition ) :
65
- return `No such state ' ${ this . _identifier } '` ;
66
- case ! this . _definition . self :
67
- return `State ' ${ this . _identifier } ' has an invalid definition` ;
68
- case this . _definition . self [ abstractKey ] :
69
- return `Cannot transition to abstract state ' ${ this . _identifier } '` ;
70
- }
55
+ if ( ! this . _definition && ! ! this . _base )
56
+ return `Could not resolve ' ${ this . name ( ) } ' from state ' ${ this . _base } '` ;
57
+ if ( ! this . _definition )
58
+ return `No such state ' ${ this . name ( ) } '` ;
59
+ if ( ! this . _definition . self )
60
+ return `State ' ${ this . name ( ) } ' has an invalid definition` ;
61
+ if ( this . _definition . self [ abstractKey ] )
62
+ return `Cannot transition to abstract state ' ${ this . name ( ) } '` ;
63
+ if ( ! this . _definition . params . $$validates ( this . _params ) )
64
+ return `Param values not valid for state ' ${ this . name ( ) } '` ;
71
65
}
72
66
}
0 commit comments