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

Side by Side Diff: sky/examples/fn/lib/node.dart

Issue 973613004: Clean up some Dart idioms in fn (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « sky/examples/fn/lib/fn.dart ('k') | sky/examples/fn/lib/reflect.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
1 part of fn; 5 part of fn;
2 6
3 void parentInsertBefore(sky.ParentNode parent, 7 void _parentInsertBefore(sky.ParentNode parent,
4 sky.Node node, 8 sky.Node node,
5 sky.Node ref) { 9 sky.Node ref) {
6 if (ref != null) { 10 if (ref != null) {
7 ref.insertBefore([node]); 11 ref.insertBefore([node]);
8 } else { 12 } else {
9 parent.appendChild(node); 13 parent.appendChild(node);
10 } 14 }
11 } 15 }
12 16
13 abstract class Node { 17 abstract class Node {
14 String _key = null; 18 String _key = null;
15 sky.Node _root = null; 19 sky.Node _root = null;
(...skipping 18 matching lines...) Expand all
34 38
35 // Text nodes are special cases of having non-unique keys (which don't need 39 // Text nodes are special cases of having non-unique keys (which don't need
36 // to be assigned as part of the API). Since they are unique in not having 40 // to be assigned as part of the API). Since they are unique in not having
37 // children, there's little point to reordering, so we always just re-assign 41 // children, there's little point to reordering, so we always just re-assign
38 // the data. 42 // the data.
39 Text(this.data) : super(key:'*text*'); 43 Text(this.data) : super(key:'*text*');
40 44
41 bool _sync(Node old, sky.ParentNode host, sky.Node insertBefore) { 45 bool _sync(Node old, sky.ParentNode host, sky.Node insertBefore) {
42 if (old == null) { 46 if (old == null) {
43 _root = new sky.Text(data); 47 _root = new sky.Text(data);
44 parentInsertBefore(host, _root, insertBefore); 48 _parentInsertBefore(host, _root, insertBefore);
45 return false; 49 return false;
46 } 50 }
47 51
48 _root = old._root; 52 _root = old._root;
49 (_root as sky.Text).data = data; 53 (_root as sky.Text).data = data;
50 return false; 54 return false;
51 } 55 }
52 } 56 }
53 57
54 var _emptyList = new List<Node>(); 58 final List<Node> _emptyList = new List<Node>();
55 59
56 abstract class Element extends Node { 60 abstract class Element extends Node {
57 61
58 String get _tagName; 62 String get _tagName;
59 63
60 Element get _emptyElement; 64 Element get _emptyElement;
61 65
62 String inlineStyle; 66 String inlineStyle;
63 67
64 sky.EventListener onClick; 68 sky.EventListener onClick;
(...skipping 30 matching lines...) Expand all
95 this.onPointerUp, 99 this.onPointerUp,
96 this.onScrollEnd, 100 this.onScrollEnd,
97 this.onScrollStart, 101 this.onScrollStart,
98 this.onScrollUpdate, 102 this.onScrollUpdate,
99 this.onWheel 103 this.onWheel
100 }) : super(key:key) { 104 }) : super(key:key) {
101 105
102 _className = style == null ? '': style._className; 106 _className = style == null ? '': style._className;
103 _children = children == null ? _emptyList : children; 107 _children = children == null ? _emptyList : children;
104 108
105 if (debugWarnings()) { 109 if (_debugWarnings()) {
106 _debugReportDuplicateIds(); 110 _debugReportDuplicateIds();
107 } 111 }
108 } 112 }
109 113
110 void _remove() { 114 void _remove() {
111 super._remove(); 115 super._remove();
112 if (_children != null) { 116 if (_children != null) {
113 for (var child in _children) { 117 for (var child in _children) {
114 child._remove(); 118 child._remove();
115 } 119 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // print("...no oldElement, initial render"); 191 // print("...no oldElement, initial render");
188 192
189 _root = sky.document.createElement(_tagName); 193 _root = sky.document.createElement(_tagName);
190 _syncNode(); 194 _syncNode();
191 195
192 for (var child in _children) { 196 for (var child in _children) {
193 child._sync(null, _root, null); 197 child._sync(null, _root, null);
194 assert(child._root is sky.Node); 198 assert(child._root is sky.Node);
195 } 199 }
196 200
197 parentInsertBefore(host, _root, insertBefore); 201 _parentInsertBefore(host, _root, insertBefore);
198 return false; 202 return false;
199 } 203 }
200 204
201 _root = oldElement._root; 205 _root = oldElement._root;
202 oldElement._root = null; 206 oldElement._root = null;
203 sky.Element root = (_root as sky.Element); 207 sky.Element root = (_root as sky.Element);
204 208
205 _syncNode(oldElement); 209 _syncNode(oldElement);
206 210
207 var startIndex = 0; 211 var startIndex = 0;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (currentNode is Text) 280 if (currentNode is Text)
277 return false; // Never re-order Text nodes. 281 return false; // Never re-order Text nodes.
278 282
279 ensureOldIdMap(); 283 ensureOldIdMap();
280 oldNode = oldNodeIdMap[currentNode._key]; 284 oldNode = oldNodeIdMap[currentNode._key];
281 if (oldNode == null) 285 if (oldNode == null)
282 return false; 286 return false;
283 287
284 oldNodeIdMap[currentNode._key] = null; // mark it reordered. 288 oldNodeIdMap[currentNode._key] = null; // mark it reordered.
285 // print("Reparenting ${currentNode._key}"); 289 // print("Reparenting ${currentNode._key}");
286 parentInsertBefore(root, oldNode._root, nextSibling); 290 _parentInsertBefore(root, oldNode._root, nextSibling);
287 return true; 291 return true;
288 } 292 }
289 293
290 // Scan forwards, this time we may re-order; 294 // Scan forwards, this time we may re-order;
291 // print("...scanning forward"); 295 // print("...scanning forward");
292 nextSibling = root.firstChild; 296 nextSibling = root.firstChild;
293 while (startIndex < endIndex && oldStartIndex < oldEndIndex) { 297 while (startIndex < endIndex && oldStartIndex < oldEndIndex) {
294 currentNode = _children[startIndex]; 298 currentNode = _children[startIndex];
295 oldNode = oldChildren[oldStartIndex]; 299 oldNode = oldChildren[oldStartIndex];
296 300
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 341
338 oldElement._children = null; 342 oldElement._children = null;
339 return false; 343 return false;
340 } 344 }
341 } 345 }
342 346
343 class Container extends Element { 347 class Container extends Element {
344 348
345 String get _tagName => 'div'; 349 String get _tagName => 'div';
346 350
347 static Container _emptyContainer = new Container(); 351 static final Container _emptyContainer = new Container();
348 352
349 Element get _emptyElement => _emptyContainer; 353 Element get _emptyElement => _emptyContainer;
350 354
351 Container({ 355 Container({
352 Object key, 356 Object key,
353 List<Node> children, 357 List<Node> children,
354 Style style, 358 Style style,
355 String inlineStyle, 359 String inlineStyle,
356 sky.EventListener onClick, 360 sky.EventListener onClick,
357 sky.EventListener onFlingCancel, 361 sky.EventListener onFlingCancel,
(...skipping 24 matching lines...) Expand all
382 onScrollStart: onScrollStart, 386 onScrollStart: onScrollStart,
383 onScrollUpdate: onScrollUpdate, 387 onScrollUpdate: onScrollUpdate,
384 onWheel: onWheel 388 onWheel: onWheel
385 ); 389 );
386 } 390 }
387 391
388 class Image extends Element { 392 class Image extends Element {
389 393
390 String get _tagName => 'img'; 394 String get _tagName => 'img';
391 395
392 static Image _emptyImage = new Image(); 396 static final Image _emptyImage = new Image();
393 Element get _emptyElement => _emptyImage; 397 Element get _emptyElement => _emptyImage;
394 398
395 String src; 399 String src;
396 int width; 400 int width;
397 int height; 401 int height;
398 402
399 Image({ 403 Image({
400 Object key, 404 Object key,
401 List<Node> children, 405 List<Node> children,
402 Style style, 406 Style style,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 if (height != oldImage.height) { 454 if (height != oldImage.height) {
451 skyImage.style['height'] = '${height}px'; 455 skyImage.style['height'] = '${height}px';
452 } 456 }
453 } 457 }
454 } 458 }
455 459
456 class Anchor extends Element { 460 class Anchor extends Element {
457 461
458 String get _tagName => 'a'; 462 String get _tagName => 'a';
459 463
460 static Anchor _emptyAnchor = new Anchor(); 464 static final Anchor _emptyAnchor = new Anchor();
461 465
462 String href; 466 String href;
463 467
464 Anchor({ 468 Anchor({
465 Object key, 469 Object key,
466 List<Node> children, 470 List<Node> children,
467 Style style, 471 Style style,
468 String inlineStyle, 472 String inlineStyle,
469 sky.EventListener onClick, 473 sky.EventListener onClick,
470 sky.EventListener onFlingCancel, 474 sky.EventListener onFlingCancel,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 void _syncNode([Element old]) { 507 void _syncNode([Element old]) {
504 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor; 508 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor;
505 super._syncNode(oldAnchor); 509 super._syncNode(oldAnchor);
506 510
507 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement; 511 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement;
508 if (href != oldAnchor.href) { 512 if (href != oldAnchor.href) {
509 skyAnchor.href = href; 513 skyAnchor.href = href;
510 } 514 }
511 } 515 }
512 } 516 }
OLDNEW
« no previous file with comments | « sky/examples/fn/lib/fn.dart ('k') | sky/examples/fn/lib/reflect.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698