11import { Action } from "../internal/Action.js" ;
22import { expression } from "../qualifiers/expression.js" ;
33import { Transformation } from "../transformation/Transformation.js" ;
4+ import { IConditionalActionModel } from "../internal/models/IConditionalActionModel.js" ;
5+ import { IActionModel } from "../internal/models/IActionModel.js" ;
46
57/**
68 * Sets up a conditional transformation.
@@ -35,6 +37,7 @@ import {Transformation} from "../transformation/Transformation.js";
3537 * // Transformation will contain `if_ar_gte_1.0/w_100/if_end`
3638 */
3739class ConditionalAction extends Action {
40+ protected _actionModel : IConditionalActionModel = { actionType : "ifCondition" } ;
3841 private ifTx : Transformation ;
3942 private elseTx : Transformation ;
4043 private exp : string ;
@@ -48,6 +51,8 @@ class ConditionalAction extends Action{
4851 super ( ) ;
4952 this . exp = exp ;
5053 this . ifTx = ifTx ;
54+ this . _actionModel . expression = exp ;
55+ this . _actionModel . transformation = ifTx ;
5156 }
5257
5358 /**
@@ -57,6 +62,7 @@ class ConditionalAction extends Action{
5762 */
5863 otherwise ( elseTx : Transformation ) : this {
5964 this . elseTx = elseTx ;
65+ this . _actionModel . otherwise = elseTx ;
6066 return this ;
6167 }
6268
@@ -68,6 +74,17 @@ class ConditionalAction extends Action{
6874 `if_end`
6975 ] . filter ( ( a ) => a ) . join ( '/' ) ;
7076 }
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+ }
7188}
7289
7390
0 commit comments