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

Unified Diff: sky/sdk/lib/framework/components2/animated_component.dart

Issue 1175753003: Kill onDidMount()/onDidUnmount() in favour of just overriding the relevant methods. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/sdk/lib/framework/components2/input.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/components2/animated_component.dart
diff --git a/sky/sdk/lib/framework/components2/animated_component.dart b/sky/sdk/lib/framework/components2/animated_component.dart
index 4cc91e01d0c981dd4c8d4b6dfb36aaa922b6e995..9a02fd531dddd9e5b4ea10c6fea0e09382df625e 100644
--- a/sky/sdk/lib/framework/components2/animated_component.dart
+++ b/sky/sdk/lib/framework/components2/animated_component.dart
@@ -8,27 +8,44 @@ import 'dart:async';
typedef void SetterFunction(double value);
+class _AnimationEntry {
+ _AnimationEntry(this.value, this.setter);
+ final AnimatedValue value;
+ final SetterFunction setter;
+ StreamSubscription<double> subscription;
+}
+
abstract class AnimatedComponent extends Component {
AnimatedComponent({ Object key }) : super(key: key, stateful: true);
void syncFields(AnimatedComponent source) { }
+ List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>();
+
animate(AnimatedValue value, SetterFunction setter) {
+ assert(!mounted);
setter(value.value);
- StreamSubscription<double> subscription;
- onDidMount(() {
- subscription = value.onValueChanged.listen((_) {
- setter(value.value);
+ _animatedFields.add(new _AnimationEntry(value, setter));
+ }
+
+ void didMount() {
+ for (_AnimationEntry entry in _animatedFields) {
+ entry.subscription = entry.value.onValueChanged.listen((_) {
+ entry.setter(entry.value.value);
scheduleBuild();
});
- });
- onDidUnmount(() {
- if (subscription != null) {
- subscription.cancel();
- subscription = null;
- }
- });
+ }
+ super.didMount();
+ }
+
+ void didUnmount() {
+ for (_AnimationEntry entry in _animatedFields) {
+ assert(entry.subscription != null);
+ entry.subscription.cancel();
+ entry.subscription = null;
+ }
+ super.didUnmount();
}
}
« no previous file with comments | « no previous file | sky/sdk/lib/framework/components2/input.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698