1
1
import { Action } from "../internal/Action.js" ;
2
2
import { expression } from "../qualifiers/expression.js" ;
3
3
import { Transformation } from "../transformation/Transformation.js" ;
4
+ import { IConditionalActionModel } from "../internal/models/IConditionalActionModel.js" ;
5
+ import { IActionModel } from "../internal/models/IActionModel.js" ;
4
6
5
7
/**
6
8
* Sets up a conditional transformation.
@@ -35,6 +37,7 @@ import {Transformation} from "../transformation/Transformation.js";
35
37
* // Transformation will contain `if_ar_gte_1.0/w_100/if_end`
36
38
*/
37
39
class ConditionalAction extends Action {
40
+ protected _actionModel : IConditionalActionModel = { actionType : "ifCondition" } ;
38
41
private ifTx : Transformation ;
39
42
private elseTx : Transformation ;
40
43
private exp : string ;
@@ -48,6 +51,8 @@ class ConditionalAction extends Action{
48
51
super ( ) ;
49
52
this . exp = exp ;
50
53
this . ifTx = ifTx ;
54
+ this . _actionModel . expression = exp ;
55
+ this . _actionModel . transformation = ifTx ;
51
56
}
52
57
53
58
/**
@@ -57,6 +62,7 @@ class ConditionalAction extends Action{
57
62
*/
58
63
otherwise ( elseTx : Transformation ) : this {
59
64
this . elseTx = elseTx ;
65
+ this . _actionModel . otherwise = elseTx ;
60
66
return this ;
61
67
}
62
68
@@ -68,6 +74,17 @@ class ConditionalAction extends Action{
68
74
`if_end`
69
75
] . filter ( ( a ) => a ) . join ( '/' ) ;
70
76
}
77
+
78
+ static fromJson ( actionModel : IActionModel ) : ConditionalAction {
79
+ const { expression, transformation, otherwise} = ( actionModel as IConditionalActionModel ) ;
80
+
81
+ // We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
82
+ // This allows the inheriting classes to determine the class to be created
83
+ const result = new this ( expression , transformation ) ;
84
+ otherwise && result . otherwise ( otherwise ) ;
85
+
86
+ return result ;
87
+ }
71
88
}
72
89
73
90
0 commit comments