| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library fn; | 5 library fn; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:sky' as sky; | 9 import 'dart:sky' as sky; |
| 10 import 'reflect.dart' as reflect; | 10 import 'reflect.dart' as reflect; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 /* | 69 /* |
| 70 * All Effen nodes derive from UINode. All nodes have a _parent, a _key and | 70 * All Effen nodes derive from UINode. All nodes have a _parent, a _key and |
| 71 * can be sync'd. | 71 * can be sync'd. |
| 72 */ | 72 */ |
| 73 abstract class UINode { | 73 abstract class UINode { |
| 74 String _key; | 74 String _key; |
| 75 UINode _parent; | 75 UINode _parent; |
| 76 sky.Node _root; | 76 sky.Node _root; |
| 77 bool _defunct = false; | 77 bool _defunct = false; |
| 78 int _nodeDepth; | |
| 79 | 78 |
| 80 UINode({ Object key }) { | 79 UINode({ Object key }) { |
| 81 _key = key == null ? "$runtimeType" : "$runtimeType-$key"; | 80 _key = key == null ? "$runtimeType" : "$runtimeType-$key"; |
| 82 } | 81 } |
| 83 | 82 |
| 84 // Subclasses which implements Nodes that become stateful may return true | 83 // Subclasses which implements Nodes that become stateful may return true |
| 85 // if the |old| node has become stateful and should be retained. | 84 // if the |old| node has become stateful and should be retained. |
| 86 bool _willSync(UINode old) => false; | 85 bool _willSync(UINode old) => false; |
| 87 | 86 |
| 88 void _sync(UINode old, sky.ParentNode host, sky.Node insertBefore); | 87 void _sync(UINode old, sky.ParentNode host, sky.Node insertBefore); |
| 89 | 88 |
| 90 void _remove() { | 89 void _remove() { |
| 91 _defunct = true; | 90 _defunct = true; |
| 92 _root = null; | 91 _root = null; |
| 93 } | 92 } |
| 94 | 93 |
| 94 int _nodeDepth; |
| 95 void _ensureDepth() { | 95 void _ensureDepth() { |
| 96 if (_nodeDepth == null) { | 96 if (_nodeDepth == null) { |
| 97 _nodeDepth = 0; | 97 _parent.ensureDepth(); |
| 98 UINode parent = _parent; | 98 _nodeDepth = _parent._nodeDepth + 1; |
| 99 while (parent != null) { | |
| 100 _nodeDepth++; | |
| 101 parent = parent._parent; | |
| 102 } | |
| 103 } | 99 } |
| 104 } | 100 } |
| 105 | 101 |
| 106 void _trace(String message) { | 102 void _trace(String message) { |
| 107 if (!_shouldTrace) | 103 if (!_shouldTrace) |
| 108 return; | 104 return; |
| 109 | 105 |
| 110 _ensureDepth(); | 106 _ensureDepth(); |
| 111 StringBuffer buffer = new StringBuffer(); | 107 print((' ' * _nodeDepth) + message); |
| 112 int depth = _nodeDepth; | |
| 113 while (depth-- > 0) { | |
| 114 buffer.write(' '); | |
| 115 } | |
| 116 buffer.write(message); | |
| 117 print(buffer); | |
| 118 } | 108 } |
| 119 | 109 |
| 120 void _traceSync(_SyncOperation op, String key) { | 110 void _traceSync(_SyncOperation op, String key) { |
| 121 if (!_shouldTrace) | 111 if (!_shouldTrace) |
| 122 return; | 112 return; |
| 123 | 113 |
| 124 String opString = op.toString().toLowerCase(); | 114 String opString = op.toString().toLowerCase(); |
| 125 String outString = opString.substring(opString.indexOf('.') + 1); | 115 String outString = opString.substring(opString.indexOf('.') + 1); |
| 126 _trace('_sync($outString) $key'); | 116 _trace('_sync($outString) $key'); |
| 127 } | 117 } |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 | 889 |
| 900 abstract class App extends Component { | 890 abstract class App extends Component { |
| 901 sky.Node _host; | 891 sky.Node _host; |
| 902 | 892 |
| 903 App() : super(stateful: true) { | 893 App() : super(stateful: true) { |
| 904 _host = sky.document.createElement('div'); | 894 _host = sky.document.createElement('div'); |
| 905 sky.document.appendChild(_host); | 895 sky.document.appendChild(_host); |
| 906 _scheduleComponentForRender(this); | 896 _scheduleComponentForRender(this); |
| 907 } | 897 } |
| 908 } | 898 } |
| OLD | NEW |