File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments