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

Side by Side Diff: tools/dom/templates/html/impl/impl_Node.darttemplate

Issue 12754013: Adding an inheriting data model to Node (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 /** 7 /**
8 * Lazy implementation of the child nodes of an element that does not request 8 * Lazy implementation of the child nodes of an element that does not request
9 * the actual child nodes of an element until strictly necessary greatly 9 * the actual child nodes of an element until strictly necessary greatly
10 * improving performance for the typical cases where it is not required. 10 * improving performance for the typical cases where it is not required.
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // Should use $dom_firstChild, Bug 8886. 328 // Should use $dom_firstChild, Bug 8886.
329 this.insertBefore(newNodes[0], refChild); 329 this.insertBefore(newNodes[0], refChild);
330 } 330 }
331 } else { 331 } else {
332 for (var node in newNodes) { 332 for (var node in newNodes) {
333 this.insertBefore(node, refChild); 333 this.insertBefore(node, refChild);
334 } 334 }
335 } 335 }
336 } 336 }
337 337
338 // Note that this may either be the locally set model or a cached value
339 // of the inherited model. This is cached to minimize model change
340 // notifications.
341 var _model;
342 bool _hasLocalModel;
343 StreamController _modelChangedStream;
344
345 /**
346 * The data model which is inherited through the tree.
347 *
348 * Setting this will propagate the value to all descendant nodes. If the
349 * model is not set on this node then it will be inherited from ancestor
350 * nodes.
351 *
352 * [clearModel] must be used to remove the model property from this node
353 * and have the model inherit from ancestor nodes.
354 */
355 @Experimental
356 get model {
357 // If we have a change handler then we've cached the model locally.
358 if (_modelChangedStream != null) {
359 return _model;
360 }
361 // Otherwise start looking up the tree.
362 for (var node = this; node != null; node = node.parentNode) {
363 if (node._hasLocalModel == true) {
364 return node._model;
365 }
366 }
367 return null;
368 }
369
370 @Experimental
371 void set model(value) {
372 var changed = model != value;
373 _model = value;
374 _hasLocalModel = true;
375 _ModelTreeObserver.initialize();
376
377 if (changed) {
378 if (_modelChangedStream != null) {
379 _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
380 }
381 // Propagate new model to all descendants.
382 _ModelTreeObserver.propagateModel(this, value, false);
383 }
384 }
385
386 /**
387 * Clears the locally set model and makes this model be inherited from parent
388 * nodes.
389 */
390 @Experimental
391 void clearModel() {
392 if (_hasLocalModel == true) {
393 _hasLocalModel = false;
394
395 // Propagate new model to all descendants.
396 if (parentNode != null) {
397 _ModelTreeObserver.propagateModel(this, parentNode.model, false);
398 } else {
399 _ModelTreeObserver.propagateModel(this, null, false);
400 }
401 }
402 }
403
404 /**
405 * Get a stream of models, whenever the model changes.
406 */
407 Stream get onModelChanged {
408 if (_modelChangedStream == null) {
409 // Ensure the model is cached locally to minimize change notifications.
410 _model = model;
411 _modelChangedStream = new StreamController.broadcast();
412 }
413 return _modelChangedStream.stream;
414 }
415
338 $!MEMBERS 416 $!MEMBERS
339 } 417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698