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

Side by Side Diff: sky/framework/fn.dart

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr changes Created 5 years, 9 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/framework/editing/editable_text.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 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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 } 638 }
639 639
640 List<Component> _dirtyComponents = new List<Component>(); 640 List<Component> _dirtyComponents = new List<Component>();
641 Set<Component> _mountedComponents = new HashSet<Component>(); 641 Set<Component> _mountedComponents = new HashSet<Component>();
642 Set<Component> _unmountedComponents = new HashSet<Component>(); 642 Set<Component> _unmountedComponents = new HashSet<Component>();
643 643
644 bool _buildScheduled = false; 644 bool _buildScheduled = false;
645 bool _inRenderDirtyComponents = false; 645 bool _inRenderDirtyComponents = false;
646 646
647 void _notifyMountStatusChanged() { 647 void _notifyMountStatusChanged() {
648 _unmountedComponents.forEach((c) => c.didUnmount()); 648 _unmountedComponents.forEach((c) => c._didUnmount());
649 _mountedComponents.forEach((c) => c.didMount()); 649 _mountedComponents.forEach((c) => c._didMount());
650 _mountedComponents.clear(); 650 _mountedComponents.clear();
651 _unmountedComponents.clear(); 651 _unmountedComponents.clear();
652 } 652 }
653 653
654 void _buildDirtyComponents() { 654 void _buildDirtyComponents() {
655 Stopwatch sw; 655 Stopwatch sw;
656 if (_shouldLogRenderDuration) 656 if (_shouldLogRenderDuration)
657 sw = new Stopwatch()..start(); 657 sw = new Stopwatch()..start();
658 658
659 try { 659 try {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 bool _dirty = true; 693 bool _dirty = true;
694 694
695 sky.Node get _host => _root.parentNode; 695 sky.Node get _host => _root.parentNode;
696 sky.Node get _insertionPoint => _root == null ? _root : _root.nextSibling; 696 sky.Node get _insertionPoint => _root == null ? _root : _root.nextSibling;
697 697
698 Node _built; 698 Node _built;
699 final int _order; 699 final int _order;
700 static int _currentOrder = 0; 700 static int _currentOrder = 0;
701 bool _stateful; 701 bool _stateful;
702 static Component _currentlyBuilding; 702 static Component _currentlyBuilding;
703 List<Function> _mountCallbacks;
704 List<Function> _unmountCallbacks;
705
706 void onDidMount(Function fn) {
707 if (_mountCallbacks == null)
708 _mountCallbacks = new List<Function>();
709
710 _mountCallbacks.add(fn);
711 }
712
713 void onDidUnmount(Function fn) {
714 if (_unmountCallbacks == null)
715 _unmountCallbacks = new List<Function>();
716
717 _unmountCallbacks.add(fn);
718 }
719
703 720
704 Component({ Object key, bool stateful }) 721 Component({ Object key, bool stateful })
705 : _stateful = stateful != null ? stateful : false, 722 : _stateful = stateful != null ? stateful : false,
706 _order = _currentOrder + 1, 723 _order = _currentOrder + 1,
707 super(key:key); 724 super(key:key);
708 725
709 Component.fromArgs(Object key, bool stateful) 726 Component.fromArgs(Object key, bool stateful)
710 : this(key: key, stateful: stateful); 727 : this(key: key, stateful: stateful);
711 728
712 void didMount() {} 729 void _didMount() {
713 void didUnmount() {} 730 if (_mountCallbacks != null)
731 _mountCallbacks.forEach((fn) => fn());
732 }
733
734 void _didUnmount() {
735 if (_unmountCallbacks != null)
736 _unmountCallbacks.forEach((fn) => fn());
737 }
714 738
715 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently 739 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently
716 // needed to get sizing info. 740 // needed to get sizing info.
717 sky.Node getRoot() => _root; 741 sky.Node getRoot() => _root;
718 742
719 void _remove() { 743 void _remove() {
720 assert(_built != null); 744 assert(_built != null);
721 assert(_root != null); 745 assert(_root != null);
722 _removeChild(_built); 746 _removeChild(_built);
723 _built = null; 747 _built = null;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 831
808 abstract class App extends Component { 832 abstract class App extends Component {
809 sky.Node _host; 833 sky.Node _host;
810 834
811 App() : super(stateful: true) { 835 App() : super(stateful: true) {
812 _host = sky.document.createElement('div'); 836 _host = sky.document.createElement('div');
813 sky.document.appendChild(_host); 837 sky.document.appendChild(_host);
814 _scheduleComponentForRender(this); 838 _scheduleComponentForRender(this);
815 } 839 }
816 } 840 }
OLDNEW
« no previous file with comments | « sky/framework/editing/editable_text.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698