Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 46578d5

Browse files
vicbmhevery
authored andcommitted
doc(NodeAttrs): rework class comments, make namings consistent
1 parent 5510a7a commit 46578d5

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/core_dom/directive.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ typedef void _AttributeChanged(String newValue);
77
typedef void Mustache(bool hasObservers);
88

99
/**
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.
1316
*/
1417
class NodeAttrs {
1518
final dom.Element element;
@@ -30,15 +33,20 @@ class NodeAttrs {
3033
} else {
3134
element.attributes[attrName] = value;
3235
}
36+
3337
if (_observers != null && _observers.containsKey(attrName)) {
3438
_observers[attrName].forEach((notifyFn) => notifyFn(value));
3539
}
3640
}
3741

3842
/**
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:]
4250
*/
4351
observe(String attrName, notifyFn(String value)) {
4452
if (_observers == null) _observers = <String, List<_AttributeChanged>>{};
@@ -61,14 +69,19 @@ class NodeAttrs {
6169

6270
Iterable<String> get keys => element.attributes.keys;
6371

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+
*/
6477
void listenObserverChanges(String attrName, Mustache notifyFn) {
6578
_mustacheAttrs[attrName] = new _MustacheAttr(notifyFn);
6679
notifyFn(false);
6780
}
6881
}
6982

7083
/**
71-
* TemplateLoader is an asynchronous access to ShadowRoot which is
84+
* [TemplateLoader] is an asynchronous access to ShadowRoot which is
7285
* loaded asynchronously. It allows a Component to be notified when its
7386
* ShadowRoot is ready.
7487
*/

lib/core_dom/view_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class _AnchorAttrs extends NodeAttrs {
248248

249249
_AnchorAttrs(DirectiveRef this._directiveRef): super(null);
250250

251-
operator [](name) => name == '.' ? _directiveRef.value : null;
251+
DirectiveRef operator [](name) => name == '.' ? _directiveRef.value : null;
252252

253253
void observe(String attributeName, _AttributeChanged notifyFn) {
254254
notifyFn(attributeName == '.' ? _directiveRef.value : null);

0 commit comments

Comments
 (0)