Chromium Code Reviews| 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 8f091cc460d3d8c943822ad5de59a35f8935040a..b3e1a7af6b15258d7f91368a8c244f3ba5cf9551 100644 |
| --- a/tools/dom/templates/html/impl/impl_Node.darttemplate |
| +++ b/tools/dom/templates/html/impl/impl_Node.darttemplate |
| @@ -335,5 +335,83 @@ $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| } |
| } |
| + // 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. |
| + var _model; |
| + bool _hasLocalModel; |
| + StreamController _modelChangedStream; |
| + |
| + /** |
| + * 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. |
| + * |
| + * [clearModel] must be used to remove the model property from this node |
| + * and have the model inherit from ancestor nodes. |
| + */ |
| + @Experimental |
| + get model { |
| + // If we have a change handler then we've cached the model locally. |
| + if (_modelChangedStream != null) { |
| + 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; |
| + } |
| + |
| + @Experimental |
| + void set model(value) { |
| + var changed = model != value; |
| + _model = value; |
| + _hasLocalModel = true; |
| + _ModelTreeObserver.initialize(); |
| + |
| + if (changed) { |
| + if (_modelChangedStream != null) { |
| + _modelChangedStream.add(value); |
|
Jennifer Messerly
2013/03/15 18:49:21
A couple more questions:
* Should this be the nod
blois
2013/03/15 20:14:10
Changed callback to be Node rather than model, sho
|
| + } |
| + // Propagate new model to all descendants. |
| + _ModelTreeObserver.propagateModel(this, value, false); |
| + } |
| + } |
| + |
| + /** |
| + * Clears the locally set model and makes this model be inherited from parent |
| + * nodes. |
| + */ |
| + @Experimental |
| + 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); |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * Get a stream of models, whenever the model changes. |
| + */ |
| + Stream get onModelChanged { |
| + if (_modelChangedStream == null) { |
| + // Ensure the model is cached locally to minimize change notifications. |
| + _model = model; |
| + _modelChangedStream = new StreamController.broadcast(); |
| + } |
| + return _modelChangedStream.stream; |
| + } |
| + |
| $!MEMBERS |
| } |