Skip to content

Commit c004226

Browse files
committed
Make VarianceNode a CustomPropertiesMixin
1 parent 2d0727c commit c004226

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

lib/src/api/mixins.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,10 +747,17 @@ mixin CustomPropertiesMixin on BaseNode {
747747
/// the transformer will provide for the default reactions.
748748
bool get handlesDefaultReactionsInternally => true;
749749

750+
/// Custom properties of the node.
750751
abstract CustomProperties properties;
751752
}
752753

754+
/// A mixin that allows a node to have a custom properties object.
753755
abstract class CustomProperties with EquatableMixin {
756+
757+
/// Default constructor for this class.
758+
const CustomProperties();
759+
760+
/// Serializes the properties to a JSON object.
754761
Map<String, dynamic> toJson();
755762
}
756763

lib/src/api/nodes/variance_node.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ part 'variance_node.g.dart';
1111
/// and switch them based on certain conditions. For example, it can be used to
1212
/// create success and error states of a widget.
1313
@JsonSerializable()
14-
class VarianceNode extends SinglePlaceholderNode {
14+
class VarianceNode extends SinglePlaceholderNode with CustomPropertiesMixin {
1515
@override
1616
final String type = 'variance';
1717

@@ -52,6 +52,10 @@ class VarianceNode extends SinglePlaceholderNode {
5252
/// All variants of the node.
5353
List<Variant> variants;
5454

55+
/// Holds configurable properties of the variance node.
56+
@override
57+
covariant VarianceProperties properties;
58+
5559
/// Creates a [VarianceNode] instance with the given data.
5660
VarianceNode({
5761
bool? value,
@@ -77,8 +81,13 @@ class VarianceNode extends SinglePlaceholderNode {
7781
super.parentID,
7882
super.reactions,
7983
String? currentVariantId,
84+
super.maxAllowedSize,
85+
super.variables,
86+
super.multipleVariables,
87+
VarianceProperties? properties,
8088
}) : assert(variants.isNotEmpty),
8189
currentVariantId = currentVariantId ?? variants[0].id,
90+
properties = properties ?? const VarianceProperties(),
8291
super(
8392
children: [],
8493
allowedTypes: [],
@@ -93,6 +102,8 @@ class VarianceNode extends SinglePlaceholderNode {
93102
List<Object?> get props => [
94103
...super.props,
95104
variants,
105+
properties,
106+
currentVariantId,
96107
];
97108

98109
/// Creates a [VarianceNode] instance from a JSON object.
@@ -130,3 +141,20 @@ class Variant with SerializableMixin, EquatableMixin {
130141
/// Creates a [Variant] instance from a JSON object.
131142
factory Variant.fromJson(Map json) => _$VariantFromJson(json);
132143
}
144+
145+
/// [VarianceProperties] is used to store custom properties of a [VarianceNode].
146+
@JsonSerializable()
147+
class VarianceProperties extends CustomProperties {
148+
/// Creates a [VarianceProperties] instance with the given data.
149+
const VarianceProperties();
150+
151+
@override
152+
Map<String, dynamic> toJson() => _$VariancePropertiesToJson(this);
153+
154+
/// Creates a [VarianceProperties] instance from a JSON object.
155+
factory VarianceProperties.fromJson(Map<String, dynamic> json) =>
156+
_$VariancePropertiesFromJson(json);
157+
158+
@override
159+
List<Object?> get props => [];
160+
}

lib/src/api/nodes/variance_node.g.dart

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)