addDirective method
Adds a directive to the asset graph.
Implementation
@override
void addDirective(Asset src, DirectiveStatement statement) {
assert(assets.containsKey(src.id));
final String directiveSrcId = addAsset(statement.asset);
final List<List<dynamic>> srcDirectives = directives[src.id] ?? <List<dynamic>>[];
if (srcDirectives.isNotEmpty) {
for (final List<dynamic> directive in srcDirectives) {
final int directiveType = directive[GraphIndex.directiveType];
/// return early if the directive is already present
if (directiveType == DirectiveStatement.part &&
statement.type == DirectiveStatement.partOf &&
directive[GraphIndex.directiveSrc] == statement.asset.id) {
return;
}
final List<dynamic>? shows = directive[GraphIndex.directiveShow];
final List<dynamic>? hides = directive[GraphIndex.directiveHide];
final String? prefix = directive.elementAtOrNull(
GraphIndex.directivePrefix,
);
if (directive[GraphIndex.directiveSrc] == directiveSrcId &&
directiveType == statement.type &&
prefix == statement.prefix &&
_listEquals(shows, statement.show) &&
_listEquals(hides, statement.hide)) {
return;
}
}
}
srcDirectives.add(<dynamic>[
statement.type,
directiveSrcId,
statement.stringUri,
statement.show.isEmpty ? null : statement.show,
statement.hide.isEmpty ? null : statement.hide,
if (statement.prefix != null) statement.prefix,
if (statement.deferred) 1,
]);
directives[src.id] = srcDirectives;
}