@@ -7,9 +7,12 @@ typedef void _AttributeChanged(String newValue);
7
7
typedef void Mustache (bool hasObservers);
8
8
9
9
/**
10
- * NodeAttrs is a facade for element attributes. The facade is responsible
11
- * for normalizing attribute names as well as allowing access to the
12
- * value of the directive.
10
+ * NodeAttrs is a facade for element attributes.
11
+ *
12
+ * This facade allows reading and writing the attribute values as well as
13
+ * adding observers triggered when:
14
+ * - The value of an attribute changes,
15
+ * - An element becomes observed.
13
16
*/
14
17
class NodeAttrs {
15
18
final dom.Element element;
@@ -30,15 +33,20 @@ class NodeAttrs {
30
33
} else {
31
34
element.attributes[attrName] = value;
32
35
}
36
+
33
37
if (_observers != null && _observers.containsKey (attrName)) {
34
38
_observers[attrName].forEach ((notifyFn) => notifyFn (value));
35
39
}
36
40
}
37
41
38
42
/**
39
- * Observe changes to the attribute by invoking the [notifyFn] function. On
40
- * registration the [notifyFn] function gets invoked synchronize with the
41
- * current value.
43
+ * Observes changes to the attribute by invoking the [notifyFn]
44
+ * function. On registration the [notifyFn] function gets invoked in order to
45
+ * synchronize with the current value.
46
+ *
47
+ * When an observed is registered on an attributes any existing
48
+ * [_observerListeners] will be called with the first parameter set to
49
+ * [:true:]
42
50
*/
43
51
observe (String attrName, notifyFn (String value)) {
44
52
if (_observers == null ) _observers = < String , List <_AttributeChanged >> {};
@@ -61,14 +69,19 @@ class NodeAttrs {
61
69
62
70
Iterable <String > get keys => element.attributes.keys;
63
71
72
+ /**
73
+ * Registers a listener to be called when the attribute [attrName] becomes
74
+ * observed. On registration [notifyFn] function gets invoked with [:false:]
75
+ * as the first argument.
76
+ */
64
77
void listenObserverChanges (String attrName, Mustache notifyFn) {
65
78
_mustacheAttrs[attrName] = new _MustacheAttr (notifyFn);
66
79
notifyFn (false );
67
80
}
68
81
}
69
82
70
83
/**
71
- * TemplateLoader is an asynchronous access to ShadowRoot which is
84
+ * [ TemplateLoader] is an asynchronous access to ShadowRoot which is
72
85
* loaded asynchronously. It allows a Component to be notified when its
73
86
* ShadowRoot is ready.
74
87
*/
0 commit comments