OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library observe.src.metadata; | |
6 | |
7 /// Use `@observable` to make a field automatically observable, or to indicate | |
8 /// that a property is observable. This only works on classes that extend or | |
9 /// mix in `Observable`. | |
10 const ObservableProperty observable = const ObservableProperty(); | |
11 | |
12 /// An annotation that is used to make a property observable. | |
13 /// Normally this is used via the [observable] constant, for example: | |
14 /// | |
15 /// class Monster extends Observable { | |
16 /// @observable int health; | |
17 /// } | |
18 /// | |
19 // TODO(sigmund): re-add this to the documentation when it's really true: | |
20 // If needed, you can subclass this to create another annotation that will | |
21 // also be treated as observable. | |
22 // Note: observable properties imply reflectable. | |
23 class ObservableProperty { | |
24 const ObservableProperty(); | |
25 } | |
26 | |
27 | |
28 /// This can be used to retain any properties that you wish to access with | |
29 /// Dart's mirror system. If you import `package:observe/mirrors_used.dart`, all | |
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. | |
35 const Reflectable reflectable = const Reflectable(); | |
36 | |
37 /// An annotation that is used to make a type or member reflectable. This makes | |
38 /// it available to `PathObserver` at runtime. For example: | |
39 /// | |
40 /// @reflectable | |
41 /// class Monster extends ChangeNotifier { | |
42 /// int _health; | |
43 /// int get health => _health; | |
44 /// ... | |
45 /// } | |
46 /// ... | |
47 /// // This will work even if the code has been tree-shaken/minified: | |
48 /// final monster = new Monster(); | |
49 /// new PathObserver(monster, 'health').changes.listen(...); | |
50 class Reflectable { | |
51 const Reflectable(); | |
52 } | |
OLD | NEW |