Skip to content

Commit 2d2e28e

Browse files
committed
Autocomplete #5
1 parent c61d5b8 commit 2d2e28e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

lib/src/api/models/variables_model.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,51 @@ class RuntimeVariableData extends VariableData {
296296
);
297297
}
298298
}
299+
300+
typedef GetValueCallback = Object? Function(Object? value);
301+
302+
/// Defines an accessor for a variable.
303+
class Accessor with EquatableMixin {
304+
/// Name of the accessor.
305+
final String name;
306+
307+
/// Type of the accessor.
308+
final VariableType type;
309+
310+
/// Defines a callback that can be used to get the value of the accessor.
311+
final GetValueCallback? _getValue;
312+
313+
/// Creates a new [Accessor].
314+
const Accessor({
315+
required this.name,
316+
required this.type,
317+
GetValueCallback? getValue,
318+
}) : _getValue = getValue;
319+
320+
@override
321+
List<Object?> get props => [name, type];
322+
323+
/// Returns the value of the accessor for the given [value].
324+
Object? getValue(Object? value) => _getValue?.call(value);
325+
326+
/// Converts this accessor to a leaf accessor.
327+
LeafAccessor toLeaf() => LeafAccessor.from(this);
328+
}
329+
330+
/// Defines an accessor for a variable that is a leaf node. Meaning it does not
331+
/// have any children.
332+
class LeafAccessor extends Accessor {
333+
/// Creates a new [LeafAccessor].
334+
const LeafAccessor({
335+
required super.name,
336+
required super.type,
337+
super.getValue,
338+
});
339+
340+
/// Creates a new [LeafAccessor] from an [Accessor].
341+
LeafAccessor.from(Accessor accessor)
342+
: super(
343+
name: accessor.name,
344+
type: accessor.type,
345+
getValue: accessor.getValue);
346+
}

0 commit comments

Comments
 (0)