| 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 '../animation/animated_value.dart'; | 5 import '../animation/animated_value.dart'; |
| 6 import '../fn.dart'; | 6 import '../fn.dart'; |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 class AnimatedComponent extends Component { | 9 abstract class AnimatedComponent extends Component { |
| 10 AnimatedComponent({ Object key }) : super(key: key, stateful: true); | 10 AnimatedComponent({ Object key }) : super(key: key, stateful: true); |
| 11 | 11 |
| 12 animateField(AnimatedValue value, Symbol symbol) { | 12 animateField(AnimatedValue value, Symbol symbol) { |
| 13 // TODO(rafaelw): Assert symbol is present on |this|, is private and | 13 // TODO(rafaelw): Assert symbol is present on |this|, is private and |
| 14 // is over the same parameterized type as the animated value. | 14 // is over the same parameterized type as the animated value. |
| 15 var mirror = reflect(this); | 15 var mirror = reflect(this); |
| 16 var subscription; | 16 var subscription; |
| 17 | 17 |
| 18 mirror.setField(symbol, value.value); | 18 mirror.setField(symbol, value.value); |
| 19 | 19 |
| 20 onDidMount(() { | 20 onDidMount(() { |
| 21 subscription = value.onValueChanged.listen((_) { | 21 subscription = value.onValueChanged.listen((_) { |
| 22 mirror.setField(symbol, value.value); | 22 mirror.setField(symbol, value.value); |
| 23 scheduleBuild(); | 23 scheduleBuild(); |
| 24 }); | 24 }); |
| 25 }); | 25 }); |
| 26 | 26 |
| 27 onDidUnmount(() { | 27 onDidUnmount(() { |
| 28 if (subscription != null) { | 28 if (subscription != null) { |
| 29 subscription.cancel(); | 29 subscription.cancel(); |
| 30 subscription = null; | 30 subscription = null; |
| 31 } | 31 } |
| 32 }); | 32 }); |
| 33 } | 33 } |
| 34 } | 34 } |
| OLD | NEW |