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

Side by Side Diff: sky/sdk/lib/framework/components2/animated_component.dart

Issue 1177243002: Refactor fn2.dart, since it breached our 1000-line threshold. (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 unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/framework/README.md ('k') | sky/sdk/lib/framework/components2/button.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import '../animation/animated_value.dart';
6 import '../fn2.dart';
7 import 'dart:async';
8
9 typedef void SetterFunction(double value);
10
11 class _AnimationEntry {
12 _AnimationEntry(this.value, this.setter);
13 final AnimatedValue value;
14 final SetterFunction setter;
15 StreamSubscription<double> subscription;
16 }
17
18 abstract class AnimatedComponent extends Component {
19
20 AnimatedComponent({ Object key }) : super(key: key, stateful: true);
21
22 void syncFields(AnimatedComponent source) { }
23
24 List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>();
25
26 animate(AnimatedValue value, SetterFunction setter) {
27 assert(!mounted);
28 setter(value.value);
29 _animatedFields.add(new _AnimationEntry(value, setter));
30 }
31
32 void didMount() {
33 for (_AnimationEntry entry in _animatedFields) {
34 entry.subscription = entry.value.onValueChanged.listen((_) {
35 entry.setter(entry.value.value);
36 scheduleBuild();
37 });
38 }
39 super.didMount();
40 }
41
42 void didUnmount() {
43 for (_AnimationEntry entry in _animatedFields) {
44 assert(entry.subscription != null);
45 entry.subscription.cancel();
46 entry.subscription = null;
47 }
48 super.didUnmount();
49 }
50
51 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/README.md ('k') | sky/sdk/lib/framework/components2/button.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698