OLD | NEW |
(Empty) | |
| 1 /** |
| 2 * Bootstrapping for Angular applications via code generation, for production. |
| 3 * |
| 4 * Most angular.dart apps rely on static transformation at compile time to gener
ate the artifacts |
| 5 * needed for tree shaking during compilation with `dart2js`. However, |
| 6 * if your deployment environment makes it impossible for you to use transformer
s, |
| 7 * you can call [staticApplicationFactory](#angular-app-factory-static@id_static
ApplicationFactory) |
| 8 * directly in your `main()` function, and explicitly define the getters, setter
s, annotations, and |
| 9 * factories yourself. |
| 10 * |
| 11 * import 'package:angular/angular.dart'; |
| 12 * import 'package:angular/application_factory_static.dart'; |
| 13 * |
| 14 * class MyModule extends Module { |
| 15 * MyModule() { |
| 16 * type(HelloWorldController); |
| 17 * } |
| 18 * } |
| 19 * |
| 20 * main() { |
| 21 * staticApplicationFactory() |
| 22 * .addModule(new MyModule()) |
| 23 * .run(); |
| 24 * } |
| 25 * |
| 26 * Note that you must explicitly import both |
| 27 * `angular.dart` and `application_factory_static.dart` at the start of your fil
e. See [staticApplicationFactory] |
| 28 * (#angular-app-factory-static@id_staticApplicationFactory) for more on explici
t definitions required with this |
| 29 * library. |
| 30 * |
| 31 */ |
| 32 library angular.app.factory.static; |
| 33 |
| 34 import 'package:di/static_injector.dart'; |
| 35 import 'package:di/di.dart' show TypeFactory, Injector; |
| 36 import 'package:angular/application.dart'; |
| 37 import 'package:angular/core/registry.dart'; |
| 38 import 'package:angular/core/parser/parser.dart'; |
| 39 import 'package:angular/core/parser/parser_static.dart'; |
| 40 import 'package:angular/core/parser/dynamic_parser.dart'; |
| 41 import 'package:angular/core/registry_static.dart'; |
| 42 import 'package:angular/change_detection/change_detection.dart'; |
| 43 import 'package:angular/change_detection/dirty_checking_change_detector_static.d
art'; |
| 44 |
| 45 export 'package:angular/change_detection/change_detection.dart' show |
| 46 FieldGetter, |
| 47 FieldSetter; |
| 48 |
| 49 class _StaticApplication extends Application { |
| 50 final Map<Type, TypeFactory> typeFactories; |
| 51 |
| 52 _StaticApplication(Map<Type, TypeFactory> this.typeFactories, |
| 53 Map<Type, Object> metadata, |
| 54 Map<String, FieldGetter> fieldGetters, |
| 55 Map<String, FieldSetter> fieldSetters, |
| 56 Map<String, Symbol> symbols) { |
| 57 ngModule |
| 58 ..value(MetadataExtractor, new StaticMetadataExtractor(metadata)) |
| 59 ..value(FieldGetterFactory, new StaticFieldGetterFactory(fieldGetters)) |
| 60 ..value(ClosureMap, new StaticClosureMap(fieldGetters, fieldSetters, |
| 61 symbols)); |
| 62 } |
| 63 |
| 64 Injector createInjector() => |
| 65 new StaticInjector(modules: modules, typeFactories: typeFactories); |
| 66 } |
| 67 /** |
| 68 * |
| 69 * Bootstraps Angular as part of the `main()` function. |
| 70 * |
| 71 * `staticApplication()` replaces `dynamicApplication()` in the main function du
ring pub build, |
| 72 * and is populated with the getters, setters, annotations, and factories generat
ed by |
| 73 * Angular's transformers for dart2js compilation. It is not typically called dir
ectly. |
| 74 * |
| 75 * For example, |
| 76 * |
| 77 * main() { |
| 78 * applicationFactory() |
| 79 * .addModule(new Module()..type(HelloWorld)) |
| 80 * .run(); |
| 81 * } |
| 82 * |
| 83 * becomes: |
| 84 * |
| 85 * main() { |
| 86 * staticApplication(generated_static_injector.factories, |
| 87 * generated_static_metadata.typeAnnotations, |
| 88 * generated_static_expressions.getters, |
| 89 * generated_static_expressions.setters, |
| 90 * generated_static_expressions.symbols) |
| 91 * .addModule(new Module()..type(HelloWorldController)) |
| 92 * .run(); |
| 93 * |
| 94 */ |
| 95 Application staticApplicationFactory( |
| 96 Map<Type, TypeFactory> typeFactories, |
| 97 Map<Type, Object> metadata, |
| 98 Map<String, FieldGetter> fieldGetters, |
| 99 Map<String, FieldSetter> fieldSetters, |
| 100 Map<String, Symbol> symbols) { |
| 101 return new _StaticApplication(typeFactories, metadata, fieldGetters, fieldSett
ers, |
| 102 symbols); |
| 103 } |
OLD | NEW |