| 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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (!_buildScheduled) { | 640 if (!_buildScheduled) { |
| 641 _buildScheduled = true; | 641 _buildScheduled = true; |
| 642 new Future.microtask(_buildDirtyComponents); | 642 new Future.microtask(_buildDirtyComponents); |
| 643 } | 643 } |
| 644 } | 644 } |
| 645 | 645 |
| 646 abstract class Component extends Node { | 646 abstract class Component extends Node { |
| 647 bool get _isBuilding => _currentlyBuilding == this; | 647 bool get _isBuilding => _currentlyBuilding == this; |
| 648 bool _dirty = true; | 648 bool _dirty = true; |
| 649 | 649 |
| 650 sky.Node get _host => _root.parentNode; |
| 651 sky.Node get _insertionPoint => _root == null ? _root : _root.nextSibling; |
| 652 |
| 650 Node _built; | 653 Node _built; |
| 651 final int _order; | 654 final int _order; |
| 652 static int _currentOrder = 0; | 655 static int _currentOrder = 0; |
| 653 bool _stateful; | 656 bool _stateful; |
| 654 static Component _currentlyBuilding; | 657 static Component _currentlyBuilding; |
| 655 | 658 |
| 656 Component({ Object key, bool stateful }) | 659 Component({ Object key, bool stateful }) |
| 657 : _stateful = stateful != null ? stateful : false, | 660 : _stateful = stateful != null ? stateful : false, |
| 658 _order = _currentOrder + 1, | 661 _order = _currentOrder + 1, |
| 659 super(key:key); | 662 super(key:key); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 | 731 |
| 729 _built = _syncChild(_built, oldBuilt, host, insertBefore); | 732 _built = _syncChild(_built, oldBuilt, host, insertBefore); |
| 730 _dirty = false; | 733 _dirty = false; |
| 731 _root = _built._root; | 734 _root = _built._root; |
| 732 } | 735 } |
| 733 | 736 |
| 734 void _buildIfDirty() { | 737 void _buildIfDirty() { |
| 735 if (!_dirty || _defunct) | 738 if (!_dirty || _defunct) |
| 736 return; | 739 return; |
| 737 | 740 |
| 738 assert(_root != null); | 741 assert(_host != null); |
| 739 _sync(null, _root.parentNode, _root.nextSibling); | 742 _sync(null, _host, _insertionPoint); |
| 740 } | 743 } |
| 741 | 744 |
| 742 void scheduleBuild() { | 745 void scheduleBuild() { |
| 743 setState(() {}); | 746 setState(() {}); |
| 744 } | 747 } |
| 745 | 748 |
| 746 void setState(Function fn()) { | 749 void setState(Function fn()) { |
| 747 _stateful = true; | 750 _stateful = true; |
| 748 fn(); | 751 fn(); |
| 749 if (_isBuilding || _dirty || _defunct) | 752 if (_isBuilding || _dirty || _defunct) |
| 750 return; | 753 return; |
| 751 | 754 |
| 752 _dirty = true; | 755 _dirty = true; |
| 753 _scheduleComponentForRender(this); | 756 _scheduleComponentForRender(this); |
| 754 } | 757 } |
| 755 | 758 |
| 756 Node build(); | 759 Node build(); |
| 757 } | 760 } |
| 758 | 761 |
| 759 abstract class App extends Component { | 762 abstract class App extends Component { |
| 760 sky.Node _host = null; | 763 sky.Node _host; |
| 764 |
| 761 App() : super(stateful: true) { | 765 App() : super(stateful: true) { |
| 762 _host = sky.document.createElement('div'); | 766 _host = sky.document.createElement('div'); |
| 763 sky.document.appendChild(_host); | 767 sky.document.appendChild(_host); |
| 764 | 768 _scheduleComponentForRender(this); |
| 765 new Future.microtask(() { | |
| 766 Stopwatch sw = new Stopwatch()..start(); | |
| 767 | |
| 768 _sync(null, _host, null); | |
| 769 assert(_root is sky.Node); | |
| 770 _notifyMountStatusChanged(); | |
| 771 | |
| 772 sw.stop(); | |
| 773 if (_shouldLogRenderDuration) | |
| 774 print("Initial build: ${sw.elapsedMicroseconds} microseconds"); | |
| 775 }); | |
| 776 } | 769 } |
| 777 } | 770 } |
| OLD | NEW |