Skip to content

Commit 0eddd2c

Browse files
committed
Set List Variable Action #1
* Add list operaction and index fields to SetVariableAction model.
1 parent 7f0373a commit 0eddd2c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lib/src/api/models/action/set_variable_action.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ import 'action.dart';
1212

1313
part 'set_variable_action.g.dart';
1414

15+
/// Defines the operation to be perfomed on a list type variable.
16+
enum ListOperation {
17+
/// Replace entire list.
18+
replace,
19+
20+
/// Add [newValue] to the list.
21+
add,
22+
23+
/// Insert [newValue] at [index] in the list.
24+
insert,
25+
26+
/// Remove value at [index] from the list.
27+
remove,
28+
29+
/// Update value at [index] with [newValue] in the list.
30+
update;
31+
32+
/// Returns a string representation of this enum.
33+
String get prettify {
34+
switch (this) {
35+
case ListOperation.replace:
36+
return 'Replace';
37+
case ListOperation.add:
38+
return 'Add';
39+
case ListOperation.insert:
40+
return 'Insert';
41+
case ListOperation.remove:
42+
return 'Remove';
43+
case ListOperation.update:
44+
return 'Update';
45+
}
46+
}
47+
}
48+
1549
/// An action that sets value of a variable.
1650
@JsonSerializable()
1751
class SetVariableAction extends ActionModel
@@ -26,11 +60,19 @@ class SetVariableAction extends ActionModel
2660
/// if the variable is a boolean.
2761
final bool toggled;
2862

63+
final ListOperation listOperation;
64+
65+
/// Index of the value to be updated/removed/inserted.
66+
/// Used for list type variable.
67+
final int index;
68+
2969
/// Creates a new [SetValueAction].
3070
SetVariableAction({
3171
required this.variable,
3272
required this.newValue,
3373
this.toggled = false,
74+
this.listOperation = ListOperation.replace,
75+
this.index = 0,
3476
}) : super(type: ActionType.setVariable);
3577

3678
@override
@@ -41,11 +83,15 @@ class SetVariableAction extends ActionModel
4183
VariableData? variable,
4284
String? newValue,
4385
bool? toggled,
86+
ListOperation? listOperation,
87+
int? index,
4488
}) =>
4589
SetVariableAction(
4690
variable: variable ?? this.variable,
4791
newValue: newValue ?? this.newValue,
4892
toggled: toggled ?? this.toggled,
93+
listOperation: listOperation ?? this.listOperation,
94+
index: index ?? this.index,
4995
);
5096

5197
/// Creates a new [SetVariableAction] instance from a JSON data.

0 commit comments

Comments
 (0)