Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: tools/dom/templates/html/impl/impl_Node.darttemplate

Issue 14908005: "Reverting 22561" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/impl/impl_Node.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_Node.darttemplate b/tools/dom/templates/html/impl/impl_Node.darttemplate
index 935794b877a1ac2d13d4cae6fee22ea772e7a158..4e9474bef91fd457e7dabb32bf2b75e36a7fbe86 100644
--- a/tools/dom/templates/html/impl/impl_Node.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Node.darttemplate
@@ -121,7 +121,7 @@ $endif
// time.
Node child = _this.$dom_firstChild;
while (child != null) {
- Node nextChild = child.nextNode;
+ Node nextChild = child.nextSibling;
if (test(child) == removeMatching) {
_this.$dom_removeChild(child);
}
@@ -245,49 +245,96 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
}
}
- /**
- * Print out a String representation of this Node.
- */
- String toString() => localName == null ?
- (nodeValue == null ? super.toString() : nodeValue) : localName;
+ // Note that this may either be the locally set model or a cached value
+ // of the inherited model. This is cached to minimize model change
+ // notifications.
+$if DART2JS
+ @Creates('Null')
+$endif
+ var _model;
+ bool _hasLocalModel;
+ Set<StreamController<Node>> _modelChangedStreams;
/**
- * Binds the attribute [name] to the [path] of the [model].
- * Path is a String of accessors such as `foo.bar.baz`.
+ * The data model which is inherited through the tree.
+ *
+ * Setting this will propagate the value to all descendant nodes. If the
+ * model is not set on this node then it will be inherited from ancestor
+ * nodes.
+ *
+ * Currently this does not support propagation through Shadow DOMs.
+ *
+ * [clearModel] must be used to remove the model property from this node
+ * and have the model inherit from ancestor nodes.
*/
@Experimental
- void bind(String name, model, String path) {
- // TODO(jmesserly): should we throw instead?
- window.console.error('Unhandled binding to Node: '
- '$this $name $model $path');
+ get model {
+ // If we have a change handler then we've cached the model locally.
+ if (_modelChangedStreams != null && !_modelChangedStreams.isEmpty) {
+ return _model;
+ }
+ // Otherwise start looking up the tree.
+ for (var node = this; node != null; node = node.parentNode) {
+ if (node._hasLocalModel == true) {
+ return node._model;
+ }
+ }
+ return null;
}
- /** Unbinds the attribute [name]. */
@Experimental
- void unbind(String name) {}
+ void set model(value) {
+ var changed = model != value;
+ _model = value;
+ _hasLocalModel = true;
+ _ModelTreeObserver.initialize();
+
+ if (changed) {
+ if (_modelChangedStreams != null && !_modelChangedStreams.isEmpty) {
+ _modelChangedStreams.toList().forEach((stream) => stream.add(this));
+ }
+ // Propagate new model to all descendants.
+ _ModelTreeObserver.propagateModel(this, value, false);
+ }
+ }
- /** Unbinds all bound attributes. */
+ /**
+ * Clears the locally set model and makes this model be inherited from parent
+ * nodes.
+ */
@Experimental
- void unbindAll() {}
-
- TemplateInstance _templateInstance;
-
- // TODO(arv): Consider storing all "NodeRareData" on a single object?
- int __instanceTerminatorCount;
- int get _instanceTerminatorCount {
- if (__instanceTerminatorCount == null) return 0;
- return __instanceTerminatorCount;
+ void clearModel() {
+ if (_hasLocalModel == true) {
+ _hasLocalModel = false;
+
+ // Propagate new model to all descendants.
+ if (parentNode != null) {
+ _ModelTreeObserver.propagateModel(this, parentNode.model, false);
+ } else {
+ _ModelTreeObserver.propagateModel(this, null, false);
+ }
+ }
}
- set _instanceTerminatorCount(int value) {
- if (value == 0) value = null;
- __instanceTerminatorCount = value;
+
+ /**
+ * Get a stream of models, whenever the model changes.
+ */
+ Stream<Node> get onModelChanged {
+ if (_modelChangedStreams == null) {
+ _modelChangedStreams = new Set<StreamController<Node>>();
+ }
+ var controller;
+ controller = new StreamController(
+ onListen: () { _modelChangedStreams.add(controller); },
+ onCancel: () { _modelChangedStreams.remove(controller); });
+ return controller.stream;
}
- /** Gets the template instance that instantiated this node, if any. */
- @Experimental
- TemplateInstance get templateInstance =>
- _templateInstance != null ? _templateInstance :
- (parent != null ? parent.templateInstance : null);
+ /**
+ * Print out a String representation of this Node.
+ */
+ String toString() => localName == null ?
+ (nodeValue == null ? super.toString() : nodeValue) : localName;
$!MEMBERS
}

Powered by Google App Engine
This is Rietveld 408576698