| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 void _removeChild(Node node) { | 116 void _removeChild(Node node) { |
| 117 _trace('_sync(remove) ${node._key}'); | 117 _trace('_sync(remove) ${node._key}'); |
| 118 node._remove(); | 118 node._remove(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Returns the child which should be retained as the child of this node. | 121 // Returns the child which should be retained as the child of this node. |
| 122 Node _syncChild(Node node, Node oldNode, sky.ParentNode host, | 122 Node _syncChild(Node node, Node oldNode, sky.ParentNode host, |
| 123 sky.Node insertBefore) { | 123 sky.Node insertBefore) { |
| 124 | 124 |
| 125 assert(oldNode == null || node._key == oldNode._key); |
| 126 |
| 125 if (node == oldNode) { | 127 if (node == oldNode) { |
| 126 _trace('_sync(identical) ${node._key}'); | 128 _trace('_sync(identical) ${node._key}'); |
| 127 return node; // Nothing to do. Subtrees must be identical. | 129 return node; // Nothing to do. Subtrees must be identical. |
| 128 } | 130 } |
| 129 | 131 |
| 130 // TODO(rafaelw): This eagerly removes the old DOM. It may be that a | 132 // TODO(rafaelw): This eagerly removes the old DOM. It may be that a |
| 131 // new component was built that could re-use some of it. Consider | 133 // new component was built that could re-use some of it. Consider |
| 132 // syncing the new VDOM against the old one. | 134 // syncing the new VDOM against the old one. |
| 133 if (oldNode != null && node._key != oldNode._key) { | 135 if (oldNode != null && node._key != oldNode._key) { |
| 134 _trace('_sync(remove) ${node._key}'); | 136 _trace('_sync(remove) ${node._key}'); |
| 135 oldNode._remove(); | 137 oldNode._remove(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 if (node._willSync(oldNode)) { | 140 if (node._willSync(oldNode)) { |
| 139 _trace('_sync(statefull) ${node._key} -> ${oldNode._key}'); | 141 _trace('_sync(statefull) ${node._key}'); |
| 140 oldNode._sync(node, host, insertBefore); | 142 oldNode._sync(node, host, insertBefore); |
| 141 node._defunct = true; | 143 node._defunct = true; |
| 142 assert(oldNode._root is sky.Node); | 144 assert(oldNode._root is sky.Node); |
| 143 return oldNode; | 145 return oldNode; |
| 144 } | 146 } |
| 145 | 147 |
| 146 node._parent = this; | 148 node._parent = this; |
| 147 | 149 |
| 148 if (oldNode == null) { | 150 if (oldNode == null) { |
| 149 _trace('_sync(insert) ${node._key}'); | 151 _trace('_sync(insert) ${node._key}'); |
| 150 } else { | 152 } else { |
| 151 _trace('_sync(stateless) ${node._key} <- ${oldNode._key}'); | 153 _trace('_sync(stateless) ${node._key}'); |
| 152 } | 154 } |
| 153 node._sync(oldNode, host, insertBefore); | 155 node._sync(oldNode, host, insertBefore); |
| 154 if (oldNode != null) | 156 if (oldNode != null) |
| 155 oldNode._defunct = true; | 157 oldNode._defunct = true; |
| 156 | 158 |
| 157 assert(node._root is sky.Node); | 159 assert(node._root is sky.Node); |
| 158 return node; | 160 return node; |
| 159 } | 161 } |
| 160 } | 162 } |
| 161 | 163 |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 | 807 |
| 806 abstract class App extends Component { | 808 abstract class App extends Component { |
| 807 sky.Node _host; | 809 sky.Node _host; |
| 808 | 810 |
| 809 App() : super(stateful: true) { | 811 App() : super(stateful: true) { |
| 810 _host = sky.document.createElement('div'); | 812 _host = sky.document.createElement('div'); |
| 811 sky.document.appendChild(_host); | 813 sky.document.appendChild(_host); |
| 812 _scheduleComponentForRender(this); | 814 _scheduleComponentForRender(this); |
| 813 } | 815 } |
| 814 } | 816 } |
| OLD | NEW |