Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: sky/sdk/lib/widgets/widget.dart

Issue 1183143012: Widgets should be stateful before calling setState (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/widgets/button_base.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:mirrors'; 7 import 'dart:mirrors';
8 import 'dart:sky' as sky; 8 import 'dart:sky' as sky;
9 9
10 import '../base/hit_test.dart'; 10 import '../base/hit_test.dart';
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 assert(root != null); 409 assert(root != null);
410 _sync(null, _slot); 410 _sync(null, _slot);
411 } 411 }
412 412
413 void scheduleBuild() { 413 void scheduleBuild() {
414 setState(() {}); 414 setState(() {});
415 } 415 }
416 416
417 void setState(Function fn()) { 417 void setState(Function fn()) {
418 assert(!_disqualifiedFromEverAppearingAgain); 418 assert(!_disqualifiedFromEverAppearingAgain);
419 _stateful = true; 419 assert(_stateful);
420 fn(); 420 fn();
421 if (_isBuilding || _dirty || !_mounted) 421 if (_isBuilding || _dirty || !_mounted)
422 return; 422 return;
423 423
424 _dirty = true; 424 _dirty = true;
425 _scheduleComponentForRender(this); 425 _scheduleComponentForRender(this);
426 } 426 }
427 427
428 Widget build(); 428 Widget build();
429 429
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 if (target is Listener) 806 if (target is Listener)
807 target._handleEvent(event); 807 target._handleEvent(event);
808 target = target._parent; 808 target = target._parent;
809 } 809 }
810 } 810 }
811 } 811 }
812 812
813 } 813 }
814 814
815 abstract class App extends Component { 815 abstract class App extends Component {
816
817 // Apps are assumed to be stateful
818 App({ String key }) : super(key: key, stateful: true);
819
816 void _handleEvent(sky.Event event) { 820 void _handleEvent(sky.Event event) {
817 if (event.type == 'back') 821 if (event.type == 'back')
818 onBack(); 822 onBack();
819 } 823 }
820 824
821 void didMount() { 825 void didMount() {
822 super.didMount(); 826 super.didMount();
823 SkyBinding.instance.addEventListener(_handleEvent); 827 SkyBinding.instance.addEventListener(_handleEvent);
824 } 828 }
825 829
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 if (root.parent == null) { 911 if (root.parent == null) {
908 // we haven't attached it yet 912 // we haven't attached it yet
909 assert(_container.child == null); 913 assert(_container.child == null);
910 _container.child = root; 914 _container.child = root;
911 } 915 }
912 assert(root.parent == _container); 916 assert(root.parent == _container);
913 } 917 }
914 918
915 Widget build() => builder(); 919 Widget build() => builder();
916 } 920 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/widgets/button_base.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698