| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:sky' as sky; | 7 import 'dart:sky' as sky; |
| 8 | 8 |
| 9 import 'package:sky/base/debug.dart'; | 9 import 'package:sky/base/debug.dart'; |
| 10 import 'package:sky/base/hit_test.dart'; | 10 import 'package:sky/base/hit_test.dart'; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 void didMount() { | 525 void didMount() { |
| 526 assert(!_disqualifiedFromEverAppearingAgain); | 526 assert(!_disqualifiedFromEverAppearingAgain); |
| 527 super.didMount(); | 527 super.didMount(); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void _buildIfDirty() { | 530 void _buildIfDirty() { |
| 531 assert(!_disqualifiedFromEverAppearingAgain); | 531 assert(!_disqualifiedFromEverAppearingAgain); |
| 532 super._buildIfDirty(); | 532 super._buildIfDirty(); |
| 533 } | 533 } |
| 534 | 534 |
| 535 void _sync(Widget old, dynamic slot) { | |
| 536 assert(!_disqualifiedFromEverAppearingAgain); | |
| 537 // TODO(ianh): _sync should only be called once when old == null | |
| 538 if (old == null && !_isStateInitialized) { | |
| 539 initState(); | |
| 540 _isStateInitialized = true; | |
| 541 } | |
| 542 super._sync(old, slot); | |
| 543 } | |
| 544 | |
| 545 Widget syncChild(Widget node, Widget oldNode, dynamic slot) { | |
| 546 assert(!_disqualifiedFromEverAppearingAgain); | |
| 547 return super.syncChild(node, oldNode, slot); | |
| 548 } | |
| 549 | |
| 550 bool retainStatefulNodeIfPossible(StatefulComponent newNode) { | 535 bool retainStatefulNodeIfPossible(StatefulComponent newNode) { |
| 551 assert(!_disqualifiedFromEverAppearingAgain); | 536 assert(!_disqualifiedFromEverAppearingAgain); |
| 552 assert(newNode != null); | 537 assert(newNode != null); |
| 553 assert(runtimeType == newNode.runtimeType); | 538 assert(runtimeType == newNode.runtimeType); |
| 554 assert(key == newNode.key); | 539 assert(key == newNode.key); |
| 555 assert(_built != null); | 540 assert(_built != null); |
| 556 newNode._disqualifiedFromEverAppearingAgain = true; | 541 newNode._disqualifiedFromEverAppearingAgain = true; |
| 557 | 542 |
| 558 newNode._built = _built; | 543 newNode._built = _built; |
| 559 _built = null; | 544 _built = null; |
| 560 | 545 |
| 561 syncFields(newNode); | 546 syncFields(newNode); |
| 562 _dirty = true; | 547 _dirty = true; |
| 563 | 548 |
| 564 return true; | 549 return true; |
| 565 } | 550 } |
| 566 | 551 |
| 552 void _sync(Widget old, dynamic slot) { |
| 553 assert(!_disqualifiedFromEverAppearingAgain); |
| 554 // TODO(ianh): _sync should only be called once when old == null |
| 555 if (old == null && !_isStateInitialized) { |
| 556 initState(); |
| 557 _isStateInitialized = true; |
| 558 } |
| 559 super._sync(old, slot); |
| 560 } |
| 561 |
| 562 // Stateful components can override initState if they want |
| 563 // to do non-trivial work to initialize state. This is |
| 564 // always called before build(). |
| 565 void initState() { } |
| 566 |
| 567 // This is called by retainStatefulNodeIfPossible(), during | 567 // This is called by retainStatefulNodeIfPossible(), during |
| 568 // syncChild(), just before _sync() is called. Derived | 568 // syncChild(), just before _sync() is called. Derived |
| 569 // classes should override this method to update `this` to | 569 // classes should override this method to update `this` to |
| 570 // account for the new values the parent passed to `source`. | 570 // account for the new values the parent passed to `source`. |
| 571 // Make sure to call super.syncFields(source) unless you are | 571 // Make sure to call super.syncFields(source) unless you are |
| 572 // extending StatefulComponent directly. | 572 // extending StatefulComponent directly. |
| 573 void syncFields(Component source); | 573 void syncFields(Component source); |
| 574 | 574 |
| 575 // Stateful components can override initState if they want | 575 Widget syncChild(Widget node, Widget oldNode, dynamic slot) { |
| 576 // to do non-trivial work to initialize state. This is | 576 assert(!_disqualifiedFromEverAppearingAgain); |
| 577 // always called before build(). | 577 return super.syncChild(node, oldNode, slot); |
| 578 void initState() { } | 578 } |
| 579 | 579 |
| 580 void setState(Function fn()) { | 580 void setState(Function fn()) { |
| 581 assert(!_disqualifiedFromEverAppearingAgain); | 581 assert(!_disqualifiedFromEverAppearingAgain); |
| 582 fn(); | 582 fn(); |
| 583 scheduleBuild(); | 583 scheduleBuild(); |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 | 586 |
| 587 Set<Component> _dirtyComponents = new Set<Component>(); | 587 Set<Component> _dirtyComponents = new Set<Component>(); |
| 588 bool _buildScheduled = false; | 588 bool _buildScheduled = false; |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 if (root.parent == null) { | 1140 if (root.parent == null) { |
| 1141 // we haven't attached it yet | 1141 // we haven't attached it yet |
| 1142 assert(_container.child == null); | 1142 assert(_container.child == null); |
| 1143 _container.child = root; | 1143 _container.child = root; |
| 1144 } | 1144 } |
| 1145 assert(root.parent == _container); | 1145 assert(root.parent == _container); |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 Widget build() => builder(); | 1148 Widget build() => builder(); |
| 1149 } | 1149 } |
| OLD | NEW |