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

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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Should use $dom_firstChild, Bug 8886. 323 // Should use $dom_firstChild, Bug 8886.
324 this.insertBefore(newNodes[0], refChild); 324 this.insertBefore(newNodes[0], refChild);
325 } 325 }
326 } else { 326 } else {
327 for (var node in newNodes) { 327 for (var node in newNodes) {
328 this.insertBefore(node, refChild); 328 this.insertBefore(node, refChild);
329 } 329 }
330 } 330 }
331 } 331 }
332 332
333 // Note that this may either be the locally set model or a cached value
334 // of the inherited model. This is cached to minimize model change
335 // notifications.
336 var _model;
337 bool _hasLocalModel;
338 StreamController _modelChangedStream;
339
340 /**
341 * The data model which is inherited through the tree.
342 *
343 * Setting this will propagate the value to all descendant nodes. If the
344 * model is not set on this node then it will be inherited from ancestor
345 * nodes.
346 *
347 * [clearModel] must be used to remove the model property from this node
348 * and have the model inherit from ancestor nodes.
349 */
350 @Experimental
351 get model {
352 // If we have a change handler then we've cached the model locally.
353 if (_modelChangedStream != null) {
354 return _model;
355 }
356 // Otherwise start looking up the tree.
357 for (var node = this; node != null; node = node.parentNode) {
358 if (node._hasLocalModel == true) {
359 return node._model;
360 }
361 }
362 return null;
363 }
364
365 @Experimental
366 void set model(value) {
367 _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
368 _hasLocalModel = true;
369 _ModelTreeObserver.initialize();
370
371 if (_modelChangedStream != null) {
372 _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
373 }
374 // Propagate new model to all descendants.
375 _ModelTreeObserver.propagateModel(this, value, false);
376 }
377
378 /**
379 * Clears the locally set model and makes this model be inherited from parent
380 * nodes.
381 */
Jennifer Messerly 2013/03/15 03:20:46 mark this @Experimental too, along with onModelCha
blois 2013/03/15 18:26:05 Done.
382 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
383 if (_hasLocalModel == true) {
384 _hasLocalModel = false;
385
386 // Propagate new model to all descendants.
387 if (parentNode != null) {
388 _ModelTreeObserver.propagateModel(this, parentNode.model, false);
389 } else {
390 _ModelTreeObserver.propagateModel(this, null, false);
391 }
392 }
393 }
394
395 /**
396 * Get a stream of models, whenever the model changes.
397 */
398 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
399 if (_modelChangedStream == null) {
400 // Ensure the model is cached locally to minimize change notifications.
401 _model = model;
402 _modelChangedStream = new StreamController.broadcast();
403 }
404 return _modelChangedStream.stream;
405 }
406
333 $!MEMBERS 407 $!MEMBERS
334 } 408 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698