Index: third_party/pkg/angular/example/web/bouncing_balls.dart |
diff --git a/third_party/pkg/angular/demo/bouncing_balls/web/bouncy_balls.dart b/third_party/pkg/angular/example/web/bouncing_balls.dart |
similarity index 74% |
rename from third_party/pkg/angular/demo/bouncing_balls/web/bouncy_balls.dart |
rename to third_party/pkg/angular/example/web/bouncing_balls.dart |
index 783769740af66a8a43784333c44a4483f594f228..d6145295121502ffe09e9a15e8078984afa812d7 100644 |
--- a/third_party/pkg/angular/demo/bouncing_balls/web/bouncy_balls.dart |
+++ b/third_party/pkg/angular/example/web/bouncing_balls.dart |
@@ -1,4 +1,5 @@ |
import 'package:angular/angular.dart'; |
+import 'package:angular/application_factory.dart'; |
import 'dart:html'; |
import 'dart:math'; |
import 'dart:core'; |
@@ -25,23 +26,22 @@ class BallModel { |
} |
-@NgController( |
+@Controller( |
selector: '[bounce-controller]', |
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() { |
@@ -54,7 +54,7 @@ class BounceController { |
} |
void requestAnimationFrame(fn) { |
- window.requestAnimationFrame((_) => zone.run(fn)); |
+ window.requestAnimationFrame((_) => fn()); |
} |
void changeCount(count) { |
@@ -97,41 +97,38 @@ class BounceController { |
} |
} |
-@NgDirective( |
+List<String> _CACHE = new List.generate(500, (i) => '${i}px'); |
+ |
+@Decorator( |
selector: '[ball-position]', |
map: const { |
- "ball-position": '=>position'}) |
-class BallPositionDirective { |
+ "ball-position": '=>position'}, |
+ exportExpressions: const ['x', 'y']) |
+class BallPosition { |
final Element element; |
final Scope scope; |
- BallPositionDirective(this.element, this.scope); |
+ BallPosition(this.element, this.scope); |
+ |
+ px(x) => _CACHE[max(0, x.round())]; |
set position(BallModel model) { |
- element.style.backgroundColor = model.color; |
+ var style = element.style; |
+ style.backgroundColor = model.color; |
scope |
- ..watch('x', (x, _) => element.style.left = '${x + 10}px', context: model, readOnly: true) |
- ..watch('y', (y, _) => element.style.top = '${y + 10}px', context: model, readOnly: true); |
+ ..watch('x', (x, _) => element.style.left = '${x + 10}px', |
+ context: model, canChangeModel: false) |
+ ..watch('y', (y, _) => element.style.top = '${y + 10}px', |
+ context: model, canChangeModel: false); |
} |
} |
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)); |
+ type(BallPosition); |
} |
} |
main() { |
- ngBootstrap(module: new MyModule()); |
+ applicationFactory().addModule(new MyModule()).run(); |
} |