| 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 /** | 7 /// Use `@observable` to make a field automatically observable, or to indicate |
| 8 * Use `@observable` to make a field automatically observable, or to indicate | 8 /// that a property is observable. |
| 9 * that a property is observable. | |
| 10 */ | |
| 11 const ObservableProperty observable = const ObservableProperty(); | 9 const ObservableProperty observable = const ObservableProperty(); |
| 12 | 10 |
| 13 /** | 11 /// An annotation that is used to make a property observable. |
| 14 * An annotation that is used to make a property observable. | 12 /// Normally this is used via the [observable] constant, for example: |
| 15 * Normally this is used via the [observable] constant, for example: | 13 /// |
| 16 * | 14 /// class Monster { |
| 17 * class Monster { | 15 /// @observable int health; |
| 18 * @observable int health; | 16 /// } |
| 19 * } | 17 /// |
| 20 * | 18 /// If needed, you can subclass this to create another annotation that will also |
| 21 * If needed, you can subclass this to create another annotation that will also | 19 /// be treated as observable. |
| 22 * be treated as observable. | |
| 23 */ | |
| 24 // Note: observable properties imply reflectable. | 20 // Note: observable properties imply reflectable. |
| 25 class ObservableProperty { | 21 class ObservableProperty { |
| 26 const ObservableProperty(); | 22 const ObservableProperty(); |
| 27 } | 23 } |
| 28 | 24 |
| 29 | 25 |
| 30 /** | 26 /// Use `@reflectable` to make a type or member available to reflection in the |
| 31 * Use `@reflectable` to make a type or member available to reflection in the | 27 /// observe package. This is necessary to make the member visible to |
| 32 * observe package. This is necessary to make the member visible to | 28 /// [PathObserver], or similar systems, once the code is deployed. |
| 33 * [PathObserver], or similar systems, once the code is deployed. | |
| 34 */ | |
| 35 const Reflectable reflectable = const Reflectable(); | 29 const Reflectable reflectable = const Reflectable(); |
| 36 | 30 |
| 37 /** | 31 /// An annotation that is used to make a type or member reflectable. This makes |
| 38 * An annotation that is used to make a type or member reflectable. This makes | 32 /// it available to [PathObserver] at runtime. For example: |
| 39 * it available to [PathObserver] at runtime. For example: | 33 /// |
| 40 * | 34 /// @reflectable |
| 41 * @reflectable | 35 /// class Monster extends ChangeNotifier { |
| 42 * class Monster extends ChangeNotifier { | 36 /// int _health; |
| 43 * int _health; | 37 /// int get health => _health; |
| 44 * int get health => _health; | 38 /// ... |
| 45 * ... | 39 /// } |
| 46 * } | 40 /// ... |
| 47 * ... | 41 /// // This will work even if the code has been tree-shaken/minified: |
| 48 * // This will work even if the code has been tree-shaken/minified: | 42 /// final monster = new Monster(); |
| 49 * final monster = new Monster(); | 43 /// new PathObserver(monster, 'health').changes.listen(...); |
| 50 * new PathObserver(monster, 'health').changes.listen(...); | |
| 51 */ | |
| 52 class Reflectable { | 44 class Reflectable { |
| 53 const Reflectable(); | 45 const Reflectable(); |
| 54 } | 46 } |
| OLD | NEW |