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

Commit

Permalink
feat(transformers): Add angular transformers to pub for no-mirror cod…
Browse files Browse the repository at this point in the history
…e generation
  • Loading branch information
Pete Blois authored and mhevery committed Mar 28, 2014
1 parent 9bf04eb commit 3fb2181
Show file tree
Hide file tree
Showing 43 changed files with 2,251 additions and 490 deletions.
4 changes: 3 additions & 1 deletion bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io' as io;

import 'package:di/di.dart';
import 'package:di/dynamic_injector.dart';
import 'package:angular/core/module.dart';
Expand Down Expand Up @@ -489,5 +491,5 @@ main(arguments) {
'(foo)(0, a: 0)',
'(foo)(0, a: 0, b: 1)',
'(foo)(0, b: 1, a: 0)',
]);
], io.stdout);
}
17 changes: 8 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packages:
analyzer:
description: analyzer
source: hosted
version: "0.12.2"
version: "0.13.2"
angular:
description:
path: ".."
Expand All @@ -14,7 +14,7 @@ packages:
args:
description: args
source: hosted
version: "0.9.0"
version: "0.10.0+1"
barback:
description: barback
source: hosted
Expand All @@ -26,14 +26,17 @@ packages:
code_transformers:
description: code_transformers
source: hosted
version: "0.0.1-dev.2"
version: "0.1.0"
collection:
description: collection
source: hosted
version: "0.9.1"
di:
description: di
source: hosted
description:
ref: null
resolved-ref: a2de00d84934f4610d1f9e108c39614e66a773f5
url: "git://github.com/angular/di.dart.git"
source: git
version: "0.0.34"
html5lib:
description: html5lib
Expand Down Expand Up @@ -79,10 +82,6 @@ packages:
description: unittest
source: hosted
version: "0.10.0"
unmodifiable_collection:
description: unmodifiable_collection
source: hosted
version: "0.9.2+1"
utf:
description: utf
source: hosted
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ dependencies:
path: ../
browser: any
unittest: any

transformers:
- angular
2 changes: 1 addition & 1 deletion example/web/animation.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ <h2>Stress Test</h2>
</div>
</div>
<script type="application/dart" src="animation.dart"></script>
<script src="../packages/browser/dart.js"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
79 changes: 4 additions & 75 deletions example/web/bouncing_balls.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:perf_api/perf_api.dart';
import 'package:angular/angular.dart';
import 'package:angular/angular_static.dart';
import 'package:angular/angular_dynamic.dart';
import 'package:angular/change_detection/change_detection.dart';
import 'dart:html';
import 'dart:math';
Expand Down Expand Up @@ -102,7 +102,8 @@ class BounceController {
@NgDirective(
selector: '[ball-position]',
map: const {
"ball-position": '=>position'})
"ball-position": '=>position'},
exportExpressions: const ['x', 'y'])
class BallPositionDirective {
final Element element;
final Scope scope;
Expand All @@ -125,79 +126,7 @@ class MyModule extends Module {
}

main() {
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)
ngDynamicApp()
.addModule(new MyModule())
.run();
}
8 changes: 0 additions & 8 deletions example/web/hello_world.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
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.
//
// If you create classes that are referenced from the Angular
// expressions, you must include a library target in @MirrorsUsed.
@MirrorsUsed(override: '*')
import 'dart:mirrors';

@NgController(
selector: '[hello-world-controller]',
publishAs: 'ctrl')
Expand Down
11 changes: 0 additions & 11 deletions example/web/todo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@ library todo;
import 'package:angular/angular.dart';
import 'package:angular/angular_dynamic.dart';
import 'package:angular/playback/playback_http.dart';
import 'todo.dart';

import 'dart:html';

// 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(
targets: const [ 'Item' ],
override: '*')
import 'dart:mirrors';

class Item {
String text;
bool done;
Expand Down
2 changes: 1 addition & 1 deletion example/web/todo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="css/todo.css">
<title>Things To Do</title>
<script src="todo.dart" type="application/dart"></script>
<script src="../packages/browser/dart.js"></script>
<script src="packages/browser/dart.js"></script>
</head>
<body ng-app>

Expand Down
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = function(config) {
],

exclude: [
'test/io/**'
'test/io/**',
'test/tools/transformer/**'
],

autoWatch: false,
Expand Down
12 changes: 7 additions & 5 deletions lib/animate/animation_loop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ part of angular.animate;
* Window.animationFrame update loop that tracks and drives
* [LoopedAnimations]'s.
*/
@NgInjectableService()
class AnimationLoop {
final AnimationFrame _frames;
final Profiler _profiler;
Expand All @@ -23,7 +24,7 @@ class AnimationLoop {
* Start and play an animation through the state transitions defined in
* [Animation].
*/
void play(LoopedAnimation animation) {
void play(LoopedAnimation animation) {
_animations.add(animation);
_queueAnimationFrame();
}
Expand All @@ -42,7 +43,7 @@ class AnimationLoop {

/* On the browsers animation frame event, update each of the tracked
* animations. Group dom reads first, and and writes second.
*
*
* At any point any animation may be updated by calling interrupt and cancel
* with a reference to the [Animation] to cancel. The [AnimationRunner] will
* then forget about the [Animation] and will not call any further methods on
Expand All @@ -56,7 +57,7 @@ class AnimationLoop {
// Dom reads
_read(timeInMs);
_profiler.stopTimer("AnimationRunner.AnimationFrame.DomReads");

_profiler.startTimer("AnimationRunner.AnimationFrame.DomMutates");
// Dom mutates
_update(timeInMs);
Expand Down Expand Up @@ -86,7 +87,7 @@ class AnimationLoop {
animation.read(timeInMs);
}
}

/**
* Stop tracking and updating the [animation].
*/
Expand All @@ -100,9 +101,10 @@ class AnimationLoop {
* Wrapper around window.requestAnimationFrame so it can be intercepted and
* tested.
*/
@NgInjectableService()
class AnimationFrame {
final dom.Window _wnd;
Future<num> get animationFrame => _wnd.animationFrame;

AnimationFrame(this._wnd);
}
1 change: 1 addition & 0 deletions lib/animate/animation_optimizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ part of angular.animate;
* running animations on child elements while the dom parent is also running an
* animation.
*/
@NgInjectableService()
class AnimationOptimizer {
final Map<dom.Element, Set<Animation>> _elements = new Map<dom.Element,
Set<Animation>>();
Expand Down
2 changes: 2 additions & 0 deletions lib/animate/css_animate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ part of angular.animate;
* animation framework. This implementation uses the [AnimationLoop] class to
* queue and run CSS based transition and keyframe animations.
*/
@NgInjectableService()
class CssAnimate implements NgAnimate {
static const NG_ANIMATE = "ng-animate";
static const NG_MOVE = "ng-move";
Expand Down Expand Up @@ -130,6 +131,7 @@ class CssAnimate implements NgAnimate {
/**
* Tracked set of currently running css animations grouped by element.
*/
@NgInjectableService()
class CssAnimationMap {
final Map<dom.Element, Map<String, CssAnimation>> cssAnimations
= new Map<dom.Element, Map<String, CssAnimation>>();
Expand Down
1 change: 0 additions & 1 deletion lib/core/parser/dynamic_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:angular/core/parser/eval.dart';
import 'package:angular/core/parser/utils.dart' show EvalError;
import 'package:angular/utils.dart';

@NgInjectableService()
abstract class ClosureMap {
Getter lookupGetter(String name);
Setter lookupSetter(String name);
Expand Down
2 changes: 0 additions & 2 deletions lib/core/registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ abstract class AnnotationsMap<K> {
}
}


@NgInjectableService()
abstract class MetadataExtractor {
Iterable call(Type type);
}
1 change: 0 additions & 1 deletion lib/core/registry_dynamic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library angular.core_dynamic;
import 'dart:mirrors';
import 'package:angular/core/module.dart';

@NgInjectableService()
class DynamicMetadataExtractor implements MetadataExtractor {
final _fieldAnnotations = [
reflectType(NgAttr),
Expand Down
3 changes: 2 additions & 1 deletion lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class ScopeStats {
'Process: ${_stat(digestProcessStopwatch)}';
}


@NgInjectableService()
class RootScope extends Scope {
static final STATE_APPLY = 'apply';
static final STATE_DIGEST = 'digest';
Expand Down Expand Up @@ -849,6 +849,7 @@ class _FunctionChain {
}
}

@NgInjectableService()
class AstParser {
final Parser _parser;
int _id = 0;
Expand Down
3 changes: 2 additions & 1 deletion lib/core_dom/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ part of angular.core.dom;
* controlled and so that custom dom manipulations can occur when animations
* complete.
*/
@NgInjectableService()
class NgAnimate {
/**
* Add the [cssClass] to the classes on [element] after running any
Expand Down Expand Up @@ -135,4 +136,4 @@ class AnimationResult {

final String value;
const AnimationResult._(this.value);
}
}
1 change: 1 addition & 0 deletions lib/core_dom/ng_element.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of angular.core.dom;

@NgInjectableService()
class NgElement {

final dom.Element node;
Expand Down
10 changes: 9 additions & 1 deletion lib/mock/http_backend.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
part of angular.mock;
library angular.mock.http_backend;

import 'dart:async' as dart_async;
import 'dart:convert' show JSON;
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:angular/utils.dart' as utils;


class _MockXhr {
var $$method, $$url, $$async, $$reqHeaders, $$respHeaders;
Expand Down
Loading

0 comments on commit 3fb2181

Please sign in to comment.