Skip to content

Commit 93846d8

Browse files
committed
Override ==
1 parent f66c93f commit 93846d8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/src/node.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
1+
import 'package:collection/collection.dart';
22

33
/// Shorthand function to generate a new [Node].
44
Node 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

Comments
 (0)