Skip to content

Commit 62a4609

Browse files
feat(StateReference): Add .name() method to StateReference class
1 parent 50cef21 commit 62a4609

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/state/stateReference.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@ import {abstractKey} from "../common/common";
1818
* @returns {Function}
1919
*/
2020
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) { }
2522

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;
3125
}
3226

3327
identifier() {
@@ -58,15 +52,15 @@ export default class StateReference {
5852
}
5953

6054
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()}'`;
7165
}
7266
}

0 commit comments

Comments
 (0)