@@ -637,8 +637,21 @@ export class StateMachine {
637637 * If value or path do not exist it returns undefined
638638 * @param path the context path to read
639639 */
640- public getFromContext ( path ?: string | string [ ] ) : any {
641- return this . context . get ( path ) ;
640+ public getFromContext < T > ( path ?: string | string [ ] ) : T {
641+ return this . context . get < T > ( path ) ;
642+ }
643+
644+ /**
645+ * Resolves a value from the context if it specifies a path or returns it as a literal
646+ * @param value the literal value or read context object
647+ */
648+ public resolveContextPathOrLiteral < T = unknown > (
649+ value : ContextOrLiteral < T > | T
650+ ) : T {
651+ if ( value && typeof value === 'object' && 'contextPath' in value ) {
652+ return this . context . get < T > ( value . contextPath ) ;
653+ }
654+ return value ;
642655 }
643656
644657 /**
@@ -647,7 +660,7 @@ export class StateMachine {
647660 * @param path the context path to write
648661 * @param value the value to write in the context path
649662 */
650- public setToContext ( path : string | string [ ] , value : any ) : void {
663+ public setToContext ( path : string | string [ ] , value : unknown ) : void {
651664 this . context . set ( path , value ) ;
652665 }
653666
@@ -657,7 +670,7 @@ export class StateMachine {
657670 * @param path the context path to write
658671 * @param value the value to write in the context path
659672 */
660- public pushToContext ( path : string | string [ ] , value : any ) : void {
673+ public pushToContext ( path : string | string [ ] , value : unknown ) : void {
661674 this . context . push ( path , value ) ;
662675 }
663676
@@ -674,15 +687,6 @@ export class StateMachine {
674687 this . debug && console . log ( 'State machine stopped' ) ;
675688 }
676689
677- private resolveContextPathOrLiteral < T = unknown > (
678- value : ContextOrLiteral < T > | T
679- ) : T {
680- if ( value && typeof value === 'object' && 'contextPath' in value ) {
681- return this . context . get ( value . contextPath ) as T ;
682- }
683- return value ;
684- }
685-
686690 /**
687691 * Stops listening on the current state's transitions and exits the current state.
688692 */
0 commit comments