Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(deploy): Move all reflection behind separate import
Browse files Browse the repository at this point in the history
This is a pre-cursor to having a generated deployment without reflection for smaller deployment size.
  • Loading branch information
mhevery committed Mar 28, 2014
1 parent e5baa50 commit 9bf04eb
Show file tree
Hide file tree
Showing 64 changed files with 938 additions and 994 deletions.
12 changes: 2 additions & 10 deletions bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@ import 'package:di/di.dart';
import 'package:di/dynamic_injector.dart';
import 'package:angular/core/module.dart';
import 'package:angular/core/parser/parser.dart';
import 'package:angular/tools/parser_generator/generator.dart';
import 'package:angular/tools/parser_getter_setter/generator.dart';

main(arguments) {
var isGetter = !arguments.isEmpty;

Module module = new Module()..type(Parser, implementedBy: DynamicParser);
if (isGetter) {
module.type(ParserBackend, implementedBy: DartGetterSetterGen);
} else {
module.type(ParserBackend, implementedBy: DynamicParserBackend);
module.type(FilterMap, implementedBy: NullFilterMap);
}
module.type(ParserBackend, implementedBy: DartGetterSetterGen);
Injector injector = new DynamicInjector(modules: [module],
allowImplicitInjection: true);

// List generated using:
// node node_modules/karma/bin/karma run | grep -Eo ":XNAY:.*:XNAY:" | sed -e 's/:XNAY://g' | sed -e "s/^/'/" | sed -e "s/$/',/" | sort | uniq > missing_expressions
injector.get(isGetter ? ParserGetterSetter : ParserGenerator).generateParser([
injector.get(ParserGetterSetter).generateParser([
"foo == 'bar' ||\nbaz",
"nonmap['hello']",
"nonmap['hello']=3",
Expand Down
17 changes: 6 additions & 11 deletions example/web/animation.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
library animation;

import 'package:angular/angular.dart';
import 'package:angular/angular_dynamic.dart';
import 'package:angular/animate/module.dart';

// This annotation allows Dart to shake away any classes
// not used from Dart code nor listed in another @MirrorsUsed.
//
// If you create classes that are referenced from the Angular
// expressions, you must include a library target in @MirrorsUsed.
@MirrorsUsed(override: '*')
import 'dart:mirrors';

part 'animation/repeat_demo.dart';
part 'animation/visibility_demo.dart';
part 'animation/stress_demo.dart';
Expand All @@ -25,11 +18,13 @@ class AnimationDemoController {
}

main() {
ngBootstrap(module: new Module()
..install(new NgAnimateModule())
ngDynamicApp()
.addModule(new Module()
..type(RepeatDemoComponent)
..type(VisibilityDemoComponent)
..type(StressDemoComponent)
..type(CssDemoComponent)
..type(AnimationDemoController));
..type(AnimationDemoController))
.addModule(new NgAnimateModule())
.run();
}
98 changes: 82 additions & 16 deletions example/web/bouncing_balls.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:perf_api/perf_api.dart';
import 'package:angular/angular.dart';
import 'package:angular/angular_static.dart';
import 'package:angular/change_detection/change_detection.dart';
import 'dart:html';
import 'dart:math';
import 'dart:core';
Expand Down Expand Up @@ -30,18 +33,17 @@ class BallModel {
publishAs: 'bounce')
class BounceController {
var lastTime = window.performance.now();
var run = true;
var run = false;
var fps = 0;
var digestTime = 0;
var currentDigestTime = 0;
var balls = [];
final NgZone zone;
final Scope scope;
var ballClassName = 'ball';

BounceController(this.zone, this.scope) {
BounceController(this.scope) {
changeCount(100);
tick();
if (run) tick();
}

void toggleCSS() {
Expand All @@ -54,7 +56,7 @@ class BounceController {
}

void requestAnimationFrame(fn) {
window.requestAnimationFrame((_) => zone.run(fn));
window.requestAnimationFrame((_) => fn());
}

void changeCount(count) {
Expand Down Expand Up @@ -118,20 +120,84 @@ class MyModule extends Module {
MyModule() {
type(BounceController);
type(BallPositionDirective);
value(GetterCache, new GetterCache({
'x': (o) => o.x,
'y': (o) => o.y,
'bounce': (o) => o.bounce,
'fps': (o) => o.fps,
'balls': (o) => o.balls,
'length': (o) => o.length,
'digestTime': (o) => o.digestTime,
'ballClassName': (o) => o.ballClassName
}));
value(ScopeStats, new ScopeStats(report: true));
}
}

main() {
ngBootstrap(module: new MyModule());
var getters = {
'x': (o) => o.x,
'y': (o) => o.y,
'bounce': (o) => o.bounce,
'fps': (o) => o.fps,
'balls': (o) => o.balls,
'length': (o) => o.length,
'digestTime': (o) => o.digestTime,
'ballClassName': (o) => o.ballClassName,
'position': (o) => o.position,
'onClick': (o) => o.onClick,
'ball': (o) => o.ball,
'color': (o) => o.color,
'changeCount': (o) => o.changeCount,
'playPause': (o) => o.playPause,
'toggleCSS': (o) => o.toggleCSS,
'timeDigest': (o) => o.timeDigest,
'expression': (o) => o.expression,
};
var setters = {
'position': (o, v) => o.position = v,
'onClick': (o, v) => o.onClick = v,
'ball': (o, v) => o.ball = v,
'x': (o, v) => o.x = v,
'y': (o, v) => o.y = v,
'balls': (o, v) => o.balls = v,
'bounce': (o, v) => o.bounce = v,
'expression': (o, v) => o.expression = v,
'fps': (o, v) => o.fps = v,
'length': (o, v) => o.length = v,
'digestTime': (o, v) => o.digestTime = v,
'ballClassName': (o, v) => o.ballClassName = v,
};
var metadata = {
BounceController: [new NgController(selector: '[bounce-controller]', publishAs: 'bounce')],
BallPositionDirective: [new NgDirective(selector: '[ball-position]', map: const { "ball-position": '=>position'})],
NgEventDirective: [new NgDirective(selector: '[ng-click]', map: const {'ng-click': '&onClick'})],
NgADirective: [new NgDirective(selector: 'a[href]')],
NgRepeatDirective: [new NgDirective(children: NgAnnotation.TRANSCLUDE_CHILDREN, selector: '[ng-repeat]', map: const {'.': '@expression'})],
NgTextMustacheDirective: [new NgDirective(selector: r':contains(/{{.*}}/)')],
NgAttrMustacheDirective: [new NgDirective(selector: r'[*=/{{.*}}/]')],
};
var types = {
Profiler: (t) => new Profiler(),
DirectiveSelectorFactory: (t) => new DirectiveSelectorFactory(),
DirectiveMap: (t) => new DirectiveMap(t(Injector), t(MetadataExtractor), t(DirectiveSelectorFactory)),
Lexer: (t) => new Lexer(),
ClosureMap: (t) => new StaticClosureMap(getters, setters), // TODO: types don't match
DynamicParserBackend: (t) => new DynamicParserBackend(t(ClosureMap)),
DynamicParser: (t) => new DynamicParser(t(Lexer), t(ParserBackend)),
Compiler: (t) => new Compiler(t(Profiler), t(Parser), t(Expando)),
WalkingCompiler: (t) => new WalkingCompiler(t(Profiler), t(Expando)),
DirectiveSelectorFactory: (t) => new DirectiveSelectorFactory(t(ElementBinderFactory)),
ElementBinderFactory: (t) => new ElementBinderFactory(t(Parser), t(Profiler), t(Expando)),
EventHandler: (t) => new EventHandler(t(Node), t(Expando), t(ExceptionHandler)),
AstParser: (t) => new AstParser(t(Parser)),
FilterMap: (t) => new FilterMap(t(Injector), t(MetadataExtractor)),
ExceptionHandler: (t) => new ExceptionHandler(),
FieldGetterFactory: (t) => new StaticFieldGetterFactory(getters),
ScopeDigestTTL: (t) => new ScopeDigestTTL(),
ScopeStats: (t) => new ScopeStats(),
RootScope: (t) => new RootScope(t(Object), t(AstParser), t(Parser), t(FieldGetterFactory), t(FilterMap), t(ExceptionHandler), t(ScopeDigestTTL), t(NgZone), t(ScopeStats)),
NgAnimate: (t) => new NgAnimate(),
Interpolate: (t) => new Interpolate(t(Parser)),

NgEventDirective: (t) => new NgEventDirective(t(Element), t(Scope)),
NgADirective: (t) => new NgADirective(t(Element)),
NgRepeatDirective: (t) => new NgRepeatDirective(t(ViewPort), t(BoundViewFactory), t(Scope), t(Parser), t(AstParser), t(FilterMap)),

BounceController: (t) => new BounceController(t(Scope)),
BallPositionDirective: (t) => new BallPositionDirective(t(Element), t(Scope)),
};
ngStaticApp(types, metadata, getters, setters)
.addModule(new MyModule())
.run();
}
5 changes: 4 additions & 1 deletion example/web/hello_world.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:angular/angular.dart';
import 'package:angular/angular_dynamic.dart';

// This annotation allows Dart to shake away any classes
// not used from Dart code nor listed in another @MirrorsUsed.
Expand All @@ -16,5 +17,7 @@ class HelloWorldController {
}

main() {
ngBootstrap(module: new Module()..type(HelloWorldController));
ngDynamicApp()
.addModule(new Module()..type(HelloWorldController))
.run();
}
3 changes: 2 additions & 1 deletion example/web/todo.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library todo;

import 'package:angular/angular.dart';
import 'package:angular/angular_dynamic.dart';
import 'package:angular/playback/playback_http.dart';
import 'todo.dart';

Expand Down Expand Up @@ -132,5 +133,5 @@ main() {
module.type(HttpBackend, implementedBy: PlaybackHttpBackend);
}

ngBootstrap(module: module);
ngDynamicApp().addModule(module).run();
}
3 changes: 0 additions & 3 deletions karma-parser-generator/index.js

This file was deleted.

24 changes: 0 additions & 24 deletions karma-parser-generator/preprocessor.js

This file was deleted.

2 changes: 0 additions & 2 deletions karma-perf.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ module.exports = function(config) {
'karma-chrome-launcher',
'karma-script-launcher',
'karma-junit-reporter',
'../../../karma-parser-generator',
'../../../karma-parser-getter-setter'
],

preprocessors: {
'test/core/parser/generated_functions.dart': ['parser-generator'],
'test/core/parser/generated_getter_setter.dart': ['parser-getter-setter']
},

Expand Down
2 changes: 0 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = function(config) {
'karma-chrome-launcher',
'karma-script-launcher',
'karma-junit-reporter',
'../../../karma-parser-generator',
'../../../karma-parser-getter-setter'
],

Expand All @@ -45,7 +44,6 @@ module.exports = function(config) {
browsers: ['Dartium'],

preprocessors: {
'test/core/parser/generated_functions.dart': ['parser-generator'],
'test/core/parser/generated_getter_setter.dart': ['parser-getter-setter']
},

Expand Down
39 changes: 0 additions & 39 deletions lib/angular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,8 @@ library angular;
import 'dart:html' as dom;
import 'dart:js' as js;
import 'package:di/di.dart';
import 'package:di/dynamic_injector.dart';
import 'package:intl/date_symbol_data_local.dart';

/**
* If you are writing code accessed from Angular expressions, you must include
* your own @MirrorsUsed annotation or ensure that everything is tagged with
* the Ng annotations.
*
* All programs should also include a @MirrorsUsed(override: '*') which
* tells the compiler that only the explicitly listed libraries will
* be reflected over.
*
* This is a short-term fix until we implement a transformer-based solution
* which does not rely on mirrors.
*/
@MirrorsUsed(targets: const [
'angular',
'angular.core',
'angular.core.dom',
'angular.filter',
'angular.perf',
'angular.directive',
'angular.routing',
'angular.core.parser.Parser',
'angular.core.parser.dynamic_parser',
'angular.core.parser.lexer',
'perf_api',
List,
dom.NodeTreeSanitizer,
],
metaTargets: const [
NgInjectableService,
NgDirective,
NgController,
NgComponent,
NgFilter
])
import 'dart:mirrors' show MirrorsUsed;

import 'package:angular/core/module.dart';
import 'package:angular/core_dom/module.dart';
import 'package:angular/directive/module.dart';
Expand All @@ -67,8 +30,6 @@ export 'package:angular/core/parser/lexer.dart';
export 'package:angular/directive/module.dart';
export 'package:angular/filter/module.dart';
export 'package:angular/routing/module.dart';
export 'package:angular/change_detection/dirty_checking_change_detector.dart'
show FieldGetter, GetterCache;

part 'bootstrap.dart';
part 'introspection.dart';
Loading

0 comments on commit 9bf04eb

Please sign in to comment.