Browse Source

Refactor DataCondition

pull/6451/head
mohamedsalem401 2 years ago
parent
commit
1a90a5374b
  1. 24
      packages/core/src/data_sources/model/conditional_variables/DataCondition.ts

24
packages/core/src/data_sources/model/conditional_variables/DataCondition.ts

@ -26,8 +26,8 @@ export interface LogicGroupProps {
export interface DataConditionProps { export interface DataConditionProps {
type: typeof DataConditionType; type: typeof DataConditionType;
condition: ConditionProps; condition: ConditionProps;
ifTrue: any; ifTrue?: any;
ifFalse: any; ifFalse?: any;
} }
interface DataConditionPropsDefined extends Omit<DataConditionProps, 'condition'> { interface DataConditionPropsDefined extends Omit<DataConditionProps, 'condition'> {
@ -42,8 +42,8 @@ export class DataCondition extends Model<DataConditionPropsDefined> {
constructor( constructor(
props: { props: {
condition: ConditionProps; condition: ConditionProps;
ifTrue: any; ifTrue?: any;
ifFalse: any; ifFalse?: any;
}, },
opts: { em: EditorModel; onValueChange?: () => void }, opts: { em: EditorModel; onValueChange?: () => void },
) { ) {
@ -62,7 +62,7 @@ export class DataCondition extends Model<DataConditionPropsDefined> {
this.listenToDataVariables(); this.listenToDataVariables();
this._onValueChange = opts.onValueChange; this._onValueChange = opts.onValueChange;
this.on('change:condition change:ifTrue change:ifFalse', () => { this.listenTo(this, 'change:condition change:ifTrue change:ifFalse', () => {
this.listenToDataVariables(); this.listenToDataVariables();
this._onValueChange?.(); this._onValueChange?.();
}); });
@ -89,8 +89,8 @@ export class DataCondition extends Model<DataConditionPropsDefined> {
} }
getDataValue(skipDynamicValueResolution: boolean = false): any { getDataValue(skipDynamicValueResolution: boolean = false): any {
const ifTrue = this.get('ifTrue'); const ifTrue = this.getIfTrue();
const ifFalse = this.get('ifFalse'); const ifFalse = this.getIfFalse();
const isConditionTrue = this.isTrue(); const isConditionTrue = this.isTrue();
if (skipDynamicValueResolution) { if (skipDynamicValueResolution) {
@ -141,8 +141,8 @@ export class DataCondition extends Model<DataConditionPropsDefined> {
getDependentDataVariables() { getDependentDataVariables() {
const dataVariables: DataVariableProps[] = this.conditionEvaluator.getDependentDataVariables(); const dataVariables: DataVariableProps[] = this.conditionEvaluator.getDependentDataVariables();
const ifTrue = this.get('ifTrue'); const ifTrue = this.getIfTrue();
const ifFalse = this.get('ifFalse'); const ifFalse = this.getIfFalse();
if (isDataVariable(ifTrue)) dataVariables.push(ifTrue); if (isDataVariable(ifTrue)) dataVariables.push(ifTrue);
if (isDataVariable(ifFalse)) dataVariables.push(ifFalse); if (isDataVariable(ifFalse)) dataVariables.push(ifFalse);
@ -155,12 +155,12 @@ export class DataCondition extends Model<DataConditionPropsDefined> {
} }
toJSON() { toJSON() {
const ifTrue = this.get('ifTrue'); const ifTrue = this.getIfTrue();
const ifFalse = this.get('ifFalse'); const ifFalse = this.getIfFalse();
return { return {
type: DataConditionType, type: DataConditionType,
condition: this.conditionEvaluator, condition: this.conditionEvaluator.toJSON(),
ifTrue, ifTrue,
ifFalse, ifFalse,
}; };

Loading…
Cancel
Save