OLD | NEW |
1 Initialize | 1 Initialize |
2 ========== | 2 ========== |
3 | 3 |
4 This package provides a common interface for initialization annotations on top | 4 This package provides a common interface for initialization annotations on top |
5 level methods, classes, and libraries. The interface looks like this: | 5 level methods, classes, and libraries. The interface looks like this: |
6 | 6 |
7 abstract class Initializer<T> { | 7 abstract class Initializer<T> { |
8 dynamic initialize(T target); | 8 dynamic initialize(T target); |
9 } | 9 } |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 For classes which are stateless, you can usually just have a single const | 85 For classes which are stateless, you can usually just have a single const |
86 instance, and that is how the actual InitMethod implementation works. Simply add | 86 instance, and that is how the actual InitMethod implementation works. Simply add |
87 something like the following: | 87 something like the following: |
88 | 88 |
89 const initMethod = const InitMethod(); | 89 const initMethod = const InitMethod(); |
90 | 90 |
91 Now when people use the annotation, it just looks like `@initMethod` without any | 91 Now when people use the annotation, it just looks like `@initMethod` without any |
92 parenthesis, and its a bit more efficient since there is a single instance. You | 92 parenthesis, and its a bit more efficient since there is a single instance. You |
93 can also make your class private to force users into using the static instance. | 93 can also make your class private to force users into using the static instance. |
| 94 |
| 95 ## Creating custom transformer plugins |
| 96 |
| 97 It is possible to create a custom plugin for the initialize transformer which |
| 98 allows you to have full control over what happens to your annotations at compile |
| 99 time. Implement `InitializerPlugin` class and pass that in to the |
| 100 `InitializeTransformer` to make it take effect. |
| 101 |
| 102 You will need to be familiar with the `analyzer` package in order to write these |
| 103 plugins, but they can be extremely powerful. See the `DefaultInitializerPlugin` |
| 104 in `lib/build/initializer_plugin.dart` as a reference. Chances are you may want |
| 105 to extend that class in order to get a lot of the default functionality. |
OLD | NEW |