OLD | NEW |
(Empty) | |
| 1 /** |
| 2 * Bootstrapping for Angular applications via [dart:mirrors](https://api.dartlan
g |
| 3 * .org/apidocs/channels/stable/dartdoc-viewer/dart-mirrors) for development. |
| 4 * |
| 5 * Angular apps that use [applicationFactory](#angular-app-factory@id_dynamicAp
plication) rely on |
| 6 * dynamic transformation at compile time to generate the getters, setters, anno
tations, and |
| 7 * factories needed for tree shaking during compilation with `dart2js`. See the
[angular:app] |
| 8 * (#angular-app) library for a discussion of how this works. |
| 9 */ |
| 10 library angular.app.factory; |
| 11 |
| 12 import 'package:di/dynamic_injector.dart'; |
| 13 import 'package:angular/angular.dart'; |
| 14 import 'package:angular/core/registry.dart'; |
| 15 import 'package:angular/core/parser/parser.dart' show ClosureMap; |
| 16 import 'package:angular/change_detection/change_detection.dart'; |
| 17 import 'package:angular/change_detection/dirty_checking_change_detector_dynamic.
dart'; |
| 18 import 'package:angular/core/registry_dynamic.dart'; |
| 19 import 'package:angular/core/parser/parser_dynamic.dart'; |
| 20 import 'dart:html'; |
| 21 |
| 22 /** |
| 23 * If you are writing code accessed from Angular expressions, you must include |
| 24 * your own @MirrorsUsed annotation or ensure that everything is tagged with |
| 25 * the Ng annotations. |
| 26 * |
| 27 * All programs should also include a @MirrorsUsed(override: '*') which |
| 28 * tells the compiler that only the explicitly listed libraries will |
| 29 * be reflected over. |
| 30 * |
| 31 * This is a short-term fix until we implement a transformer-based solution |
| 32 * which does not rely on mirrors. |
| 33 */ |
| 34 @MirrorsUsed(targets: const [ |
| 35 'angular', |
| 36 'angular.core_internal', |
| 37 'angular.core.dom_internal', |
| 38 'angular.formatter', |
| 39 'angular.perf', |
| 40 'angular.directive', |
| 41 'angular.routing', |
| 42 'angular.core.annotation_src', |
| 43 'angular.core.parser.Parser', |
| 44 'angular.core.parser.dynamic_parser', |
| 45 'angular.core.parser.lexer', |
| 46 'angular.core_dynamic.DynamicMetadataExtractor', |
| 47 'perf_api', |
| 48 List, |
| 49 NodeTreeSanitizer, |
| 50 ], |
| 51 metaTargets: const [ |
| 52 Injectable, |
| 53 Decorator, |
| 54 Controller, |
| 55 Component, |
| 56 Formatter |
| 57 ]) |
| 58 import 'dart:mirrors' show MirrorsUsed; |
| 59 |
| 60 class _DynamicApplication extends Application { |
| 61 _DynamicApplication() { |
| 62 ngModule |
| 63 ..type(MetadataExtractor, implementedBy: DynamicMetadataExtractor) |
| 64 ..type(FieldGetterFactory, implementedBy: DynamicFieldGetterFactory) |
| 65 ..type(ClosureMap, implementedBy: DynamicClosureMap); |
| 66 } |
| 67 |
| 68 Injector createInjector() => new DynamicInjector(modules: modules); |
| 69 } |
| 70 /** |
| 71 * Creates an `applicationFactory` that bootstraps Angular as part of the `main()
` function. |
| 72 * |
| 73 * main() { |
| 74 * applicationFactory() |
| 75 * .addModule(new MyModule()) |
| 76 * .run(); |
| 77 * } |
| 78 * |
| 79 * During `pub build`, `applicationFactory()` is replaced by `staticApplication()
` and |
| 80 * populated with the getters, setters, annotations, and factories generated by |
| 81 * Angular's transformers for dart2js compilation. |
| 82 */ |
| 83 Application applicationFactory() => new _DynamicApplication(); |
OLD | NEW |