| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library observe.src.metadata; | 5 library observe.src.metadata; |
| 6 | 6 |
| 7 /// Use `@observable` to make a field automatically observable, or to indicate | 7 /// Use `@observable` to make a field automatically observable, or to indicate |
| 8 /// that a property is observable. | 8 /// that a property is observable. This only works on classes that extend or |
| 9 /// mix in `Observable`. |
| 9 const ObservableProperty observable = const ObservableProperty(); | 10 const ObservableProperty observable = const ObservableProperty(); |
| 10 | 11 |
| 11 /// An annotation that is used to make a property observable. | 12 /// An annotation that is used to make a property observable. |
| 12 /// Normally this is used via the [observable] constant, for example: | 13 /// Normally this is used via the [observable] constant, for example: |
| 13 /// | 14 /// |
| 14 /// class Monster { | 15 /// class Monster extends Observable { |
| 15 /// @observable int health; | 16 /// @observable int health; |
| 16 /// } | 17 /// } |
| 17 /// | 18 /// |
| 18 /// If needed, you can subclass this to create another annotation that will also | 19 // TODO(sigmund): re-add this to the documentation when it's really true: |
| 19 /// be treated as observable. | 20 // If needed, you can subclass this to create another annotation that will |
| 21 // also be treated as observable. |
| 20 // Note: observable properties imply reflectable. | 22 // Note: observable properties imply reflectable. |
| 21 class ObservableProperty { | 23 class ObservableProperty { |
| 22 const ObservableProperty(); | 24 const ObservableProperty(); |
| 23 } | 25 } |
| 24 | 26 |
| 25 | 27 |
| 26 /// Use `@reflectable` to make a type or member available to reflection in the | 28 /// This can be used to retain any properties that you wish to access with |
| 27 /// observe package. This is necessary to make the member visible to | 29 /// Dart's mirror system. If you import `package:observe/mirrors_used.dart`, all |
| 28 /// [PathObserver], or similar systems, once the code is deployed. | 30 /// classes or members annotated with `@reflectable` wil be preserved by dart2js |
| 31 /// during compilation. This is necessary to make the member visible to |
| 32 /// `PathObserver`, or similar systems, once the code is deployed, if you are |
| 33 /// not doing a different kind of code-generation for your app. If you are using |
| 34 /// polymer, you most likely don't need to use this annotation anymore. |
| 29 const Reflectable reflectable = const Reflectable(); | 35 const Reflectable reflectable = const Reflectable(); |
| 30 | 36 |
| 31 /// An annotation that is used to make a type or member reflectable. This makes | 37 /// An annotation that is used to make a type or member reflectable. This makes |
| 32 /// it available to [PathObserver] at runtime. For example: | 38 /// it available to `PathObserver` at runtime. For example: |
| 33 /// | 39 /// |
| 34 /// @reflectable | 40 /// @reflectable |
| 35 /// class Monster extends ChangeNotifier { | 41 /// class Monster extends ChangeNotifier { |
| 36 /// int _health; | 42 /// int _health; |
| 37 /// int get health => _health; | 43 /// int get health => _health; |
| 38 /// ... | 44 /// ... |
| 39 /// } | 45 /// } |
| 40 /// ... | 46 /// ... |
| 41 /// // This will work even if the code has been tree-shaken/minified: | 47 /// // This will work even if the code has been tree-shaken/minified: |
| 42 /// final monster = new Monster(); | 48 /// final monster = new Monster(); |
| 43 /// new PathObserver(monster, 'health').changes.listen(...); | 49 /// new PathObserver(monster, 'health').changes.listen(...); |
| 44 class Reflectable { | 50 class Reflectable { |
| 45 const Reflectable(); | 51 const Reflectable(); |
| 46 } | 52 } |
| OLD | NEW |