| 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; |
| 11 | 11 |
| 12 bool _checkedMode; | 12 bool _initIsInCheckedMode() { |
| 13 void testFn(double i) {} |
| 14 try { |
| 15 testFn('not a double'); |
| 16 } catch (ex) { |
| 17 return true; |
| 18 } |
| 19 return false; |
| 20 } |
| 13 | 21 |
| 14 bool _debugWarnings() { | 22 final bool _isInCheckedMode = _initIsInCheckedMode(); |
| 15 void testFn(double i) {} | 23 final bool _shouldLogRenderDuration = false; |
| 16 | |
| 17 if (_checkedMode == null) { | |
| 18 _checkedMode = false; | |
| 19 try { | |
| 20 testFn('not a double'); | |
| 21 } catch (ex) { | |
| 22 _checkedMode = true; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 return _checkedMode; | |
| 27 } | |
| 28 | 24 |
| 29 class EventHandler { | 25 class EventHandler { |
| 30 final String type; | 26 final String type; |
| 31 final sky.EventListener listener; | 27 final sky.EventListener listener; |
| 32 | 28 |
| 33 EventHandler(this.type, this.listener); | 29 EventHandler(this.type, this.listener); |
| 34 } | 30 } |
| 35 | 31 |
| 36 class EventMap { | 32 class EventMap { |
| 37 final List<EventHandler> _handlers = new List<EventHandler>(); | 33 final List<EventHandler> _handlers = new List<EventHandler>(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Object key, | 141 Object key, |
| 146 List<Node> children, | 142 List<Node> children, |
| 147 Style style, | 143 Style style, |
| 148 | 144 |
| 149 this.inlineStyle | 145 this.inlineStyle |
| 150 }) : super(key:key) { | 146 }) : super(key:key) { |
| 151 | 147 |
| 152 _className = style == null ? '': style._className; | 148 _className = style == null ? '': style._className; |
| 153 _children = children == null ? _emptyList : children; | 149 _children = children == null ? _emptyList : children; |
| 154 | 150 |
| 155 if (_debugWarnings()) { | 151 if (_isInCheckedMode) { |
| 156 _debugReportDuplicateIds(); | 152 _debugReportDuplicateIds(); |
| 157 } | 153 } |
| 158 } | 154 } |
| 159 | 155 |
| 160 void _remove() { | 156 void _remove() { |
| 161 super._remove(); | 157 super._remove(); |
| 162 if (_children != null) { | 158 if (_children != null) { |
| 163 for (var child in _children) { | 159 for (var child in _children) { |
| 164 child._remove(); | 160 child._remove(); |
| 165 } | 161 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 void _renderDirtyComponents() { | 505 void _renderDirtyComponents() { |
| 510 Stopwatch sw = new Stopwatch()..start(); | 506 Stopwatch sw = new Stopwatch()..start(); |
| 511 | 507 |
| 512 _dirtyComponents.sort((a, b) => a._order - b._order); | 508 _dirtyComponents.sort((a, b) => a._order - b._order); |
| 513 for (var comp in _dirtyComponents) { | 509 for (var comp in _dirtyComponents) { |
| 514 comp._renderIfDirty(); | 510 comp._renderIfDirty(); |
| 515 } | 511 } |
| 516 | 512 |
| 517 _dirtyComponents.clear(); | 513 _dirtyComponents.clear(); |
| 518 _renderScheduled = false; | 514 _renderScheduled = false; |
| 515 |
| 519 sw.stop(); | 516 sw.stop(); |
| 520 print("Render took ${sw.elapsedMicroseconds} microseconds"); | 517 if (_shouldLogRenderDuration) |
| 518 print("Render took ${sw.elapsedMicroseconds} microseconds"); |
| 521 } | 519 } |
| 522 | 520 |
| 523 void _scheduleComponentForRender(Component c) { | 521 void _scheduleComponentForRender(Component c) { |
| 524 _dirtyComponents.add(c); | 522 _dirtyComponents.add(c); |
| 525 | 523 |
| 526 if (!_renderScheduled) { | 524 if (!_renderScheduled) { |
| 527 _renderScheduled = true; | 525 _renderScheduled = true; |
| 528 new Future.microtask(_renderDirtyComponents); | 526 new Future.microtask(_renderDirtyComponents); |
| 529 } | 527 } |
| 530 } | 528 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 _dirty = true; | 637 _dirty = true; |
| 640 _scheduleComponentForRender(this); | 638 _scheduleComponentForRender(this); |
| 641 } | 639 } |
| 642 } | 640 } |
| 643 | 641 |
| 644 Node render(); | 642 Node render(); |
| 645 } | 643 } |
| 646 | 644 |
| 647 abstract class App extends Component { | 645 abstract class App extends Component { |
| 648 sky.Node _host = null; | 646 sky.Node _host = null; |
| 649 App() | 647 App() : super(stateful: true) { |
| 650 : super(stateful: true) { | |
| 651 | |
| 652 _host = sky.document.createElement('div'); | 648 _host = sky.document.createElement('div'); |
| 653 sky.document.appendChild(_host); | 649 sky.document.appendChild(_host); |
| 654 | 650 |
| 655 new Future.microtask(() { | 651 new Future.microtask(() { |
| 656 Stopwatch sw = new Stopwatch()..start(); | 652 Stopwatch sw = new Stopwatch()..start(); |
| 653 |
| 657 _sync(null, _host, null); | 654 _sync(null, _host, null); |
| 658 assert(_root is sky.Node); | 655 assert(_root is sky.Node); |
| 656 |
| 659 sw.stop(); | 657 sw.stop(); |
| 660 print("Initial render: ${sw.elapsedMicroseconds} microseconds"); | 658 if (_shouldLogRenderDuration) |
| 659 print("Initial render: ${sw.elapsedMicroseconds} microseconds"); |
| 661 }); | 660 }); |
| 662 } | 661 } |
| 663 } | 662 } |
| OLD | NEW |