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 ad6c2db606631fed1e92e30c1182017ce2cab760..ada51b4964fd68edb07445403bdba7de18430b55 100644 |
| --- a/tools/dom/templates/html/impl/impl_Node.darttemplate |
| +++ b/tools/dom/templates/html/impl/impl_Node.darttemplate |
| @@ -330,5 +330,79 @@ $(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) { |
| + _model = value; |
|
Jennifer Messerly
2013/03/15 03:20:46
bail if old model == value?
blois
2013/03/15 18:26:05
Added check to eliminate invalid change notificati
|
| + _hasLocalModel = true; |
| + _ModelTreeObserver.initialize(); |
| + |
| + if (_modelChangedStream != null) { |
| + _modelChangedStream.add(value); |
|
Jennifer Messerly
2013/03/15 03:20:46
Does this deliver synchronously?
If so, it seems
blois
2013/03/15 18:26:05
Yeah, was going to mention that- still need to wor
|
| + } |
| + // 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. |
| + */ |
|
Jennifer Messerly
2013/03/15 03:20:46
mark this @Experimental too, along with onModelCha
blois
2013/03/15 18:26:05
Done.
|
| + void clearModel() { |
|
Jennifer Messerly
2013/03/15 03:20:46
out of curiosity, why not use `null` for this? Doe
blois
2013/03/15 18:26:05
If a detail view is set display the selected item
|
| + 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 { |
|
Jennifer Messerly
2013/03/15 03:20:46
One thing I was wondering about for this event. Wi
blois
2013/03/15 18:26:05
One thing that I was thinking about is that we sho
|
| + if (_modelChangedStream == null) { |
| + // Ensure the model is cached locally to minimize change notifications. |
| + _model = model; |
| + _modelChangedStream = new StreamController.broadcast(); |
| + } |
| + return _modelChangedStream.stream; |
| + } |
| + |
| $!MEMBERS |
| } |