1-
1+ import 'package:collection/collection.dart' ;
22
33/// Shorthand function to generate a new [Node] .
44Node h (String tagName,
5- [Map <String , dynamic > attributes = const {},
6- Iterable <Node > children = const []]) =>
5+ [Map <String , dynamic > attributes = const {},
6+ Iterable <Node > children = const []]) =>
77 new Node (tagName, attributes, children);
88
99/// Represents an HTML node.
@@ -14,14 +14,23 @@ class Node {
1414
1515 Node (this .tagName,
1616 [Map <String , dynamic > attributes = const {},
17- Iterable <Node > children = const []]) {
17+ Iterable <Node > children = const []]) {
1818 this ..attributes.addAll (attributes ?? {})..children.addAll (children ?? []);
1919 }
2020
2121 Node ._selfClosing (this .tagName,
2222 [Map <String , dynamic > attributes = const {}]) {
2323 this ..attributes.addAll (attributes ?? {});
2424 }
25+
26+ @override
27+ bool operator == (other) {
28+ return other is Node &&
29+ other.tagName == tagName &&
30+ const ListEquality <Node >().equals (other.children, children) &&
31+ const MapEquality <String , dynamic >()
32+ .equals (other.attributes, attributes);
33+ }
2534}
2635
2736/// Represents a self-closing tag, i.e. `<br>` .
@@ -41,4 +50,7 @@ class TextNode extends Node {
4150 final String text;
4251
4352 TextNode (this .text) : super (':text' );
44- }
53+
54+ @override
55+ bool operator == (other) => other is TextNode && other.text == text;
56+ }
0 commit comments