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

Commit 5f8e276

Browse files
committed
feat(directives): remove the @controller directive
Completely remove the deprecated Controller directive. Major update to the demos to use setRootContext (where applicable) and to move to Components for the beefier demos (bouncing balls and form). A temporary work around was required in demos (animation and todo) so that rootContext have Map interface. The work arounds will disappear after the context is set to the component. Library changes were pulled out of the first commit in #1269. Closes #1401
1 parent fb7a3aa commit 5f8e276

31 files changed

+531
-610
lines changed

example/pubspec.lock

+18-22
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ packages:
1010
path: ".."
1111
relative: true
1212
source: path
13-
version: "0.11.0"
13+
version: "0.14.0"
1414
args:
1515
description: args
1616
source: hosted
1717
version: "0.10.0+2"
1818
barback:
1919
description: barback
2020
source: hosted
21-
version: "0.13.0"
21+
version: "0.14.0+3"
2222
browser:
2323
description: browser
2424
source: hosted
@@ -30,72 +30,68 @@ packages:
3030
collection:
3131
description: collection
3232
source: hosted
33-
version: "0.9.2"
33+
version: "0.9.4"
3434
di:
3535
description: di
3636
source: hosted
37-
version: "2.0.1"
37+
version: "2.0.2"
3838
html5lib:
3939
description: html5lib
4040
source: hosted
4141
version: "0.10.0"
4242
intl:
4343
description: intl
4444
source: hosted
45-
version: "0.8.10+4"
45+
version: "0.11.6"
4646
logging:
4747
description: logging
4848
source: hosted
49-
version: "0.9.1+1"
49+
version: "0.9.2"
5050
matcher:
5151
description: matcher
5252
source: hosted
53-
version: "0.10.0"
54-
meta:
55-
description: meta
56-
source: hosted
57-
version: "0.8.8"
58-
mock:
59-
description: mock
60-
source: hosted
61-
version: "0.10.0+1"
53+
version: "0.11.1"
6254
path:
6355
description: path
6456
source: hosted
65-
version: "1.2.1"
57+
version: "1.3.0"
6658
perf_api:
6759
description: perf_api
6860
source: hosted
69-
version: "0.0.8"
61+
version: "0.0.9"
62+
quiver:
63+
description: quiver
64+
source: hosted
65+
version: "0.18.2"
7066
route_hierarchical:
7167
description: route_hierarchical
7268
source: hosted
7369
version: "0.4.22"
7470
source_maps:
7571
description: source_maps
7672
source: hosted
77-
version: "0.9.0"
73+
version: "0.9.4"
7874
source_span:
7975
description: source_span
8076
source: hosted
8177
version: "1.0.0"
8278
stack_trace:
8379
description: stack_trace
8480
source: hosted
85-
version: "0.9.3+1"
81+
version: "0.9.3+2"
8682
typed_mock:
8783
description: typed_mock
8884
source: hosted
8985
version: "0.0.4"
9086
unittest:
9187
description: unittest
9288
source: hosted
93-
version: "0.10.1+2"
89+
version: "0.11.0+5"
9490
utf:
9591
description: utf
9692
source: hosted
97-
version: "0.9.0"
93+
version: "0.9.0+1"
9894
web_components:
9995
description: web_components
10096
source: hosted
101-
version: "0.3.3"
97+
version: "0.6.0+1"

example/pubspec.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ dependencies:
55
path: ../
66
browser: any
77
unittest: any
8+
quiver: any
89
web_components: any
910

1011
transformers:
11-
- angular
12+
- angular:
13+
html_files:
14+
- web/bouncing_controller.html
15+
- web/form_controller.html

example/web/animation.dart

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@ library animation;
33
import 'package:angular/angular.dart';
44
import 'package:angular/application_factory.dart';
55
import 'package:angular/animate/module.dart';
6+
import 'package:quiver/collection.dart';
67

78
part 'animation/repeat_demo.dart';
89
part 'animation/visibility_demo.dart';
910
part 'animation/stress_demo.dart';
1011
part 'animation/css_demo.dart';
1112

12-
@Controller(
13-
selector: '[animation-demo]',
14-
publishAs: 'demo')
13+
@Injectable()
1514
class AnimationDemo {
1615
final pages = ["About", "ng-repeat", "Visibility", "Css", "Stress Test"];
1716
var currentPage = "About";
1817
}
1918

19+
// Temporary workaround, because context needs to extend Map.
20+
@Injectable()
21+
class AnimationDemoHashMap extends DelegatingMap {
22+
final Map _delegate;
23+
AnimationDemoHashMap(AnimationDemo demo) : _delegate = new Map() {
24+
_delegate['demo'] = demo;
25+
}
26+
Map get delegate => _delegate;
27+
}
28+
2029
class AnimationDemoModule extends Module {
2130
AnimationDemoModule() {
2231
install(new AnimationModule());
@@ -30,5 +39,6 @@ class AnimationDemoModule extends Module {
3039
main() {
3140
applicationFactory()
3241
.addModule(new AnimationDemoModule())
42+
.rootContextType(AnimationDemoHashMap)
3343
.run();
3444
}

example/web/animation.html

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</nav>
1515
<div class="content" ng-switch="demo.currentPage">
1616
<div class="demo" ng-switch-default>
17+
1718
<h2>About</h2>
1819
<p>The NgAnimate module is a port with modifications of the original
1920
AngularJS animation module. The default implementation does nothing.
@@ -22,6 +23,7 @@ <h2>About</h2>
2223
added it allows you define and run css animations on your elements with
2324
pure CSS.</p>
2425
<p>Check out the demos above.</p>
26+
2527
</div>
2628
<div class="demo" ng-switch-when="ng-repeat">
2729
<h2>ng-repeat Demo</h2>

example/web/bouncing_balls.dart

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import 'package:angular/angular.dart';
2-
import 'package:angular/application_factory.dart';
31
import 'dart:html';
42
import 'dart:math';
53
import 'dart:core';
64

5+
import 'package:angular/angular.dart';
6+
import 'package:angular/application_factory.dart';
7+
78
var random = new Random();
89
var width = 400;
910
var height = 400;
@@ -23,23 +24,26 @@ class BallModel {
2324
}
2425
return color;
2526
}
26-
2727
}
2828

29-
@Controller(
30-
selector: '[bounce-controller]',
31-
publishAs: 'bounce')
29+
30+
@Component(
31+
selector: 'bounce-controller',
32+
publishAs: 'ctrl',
33+
templateUrl: 'bouncing_controller.html',
34+
cssUrl: 'bouncing_controller.css'
35+
)
3236
class BounceController {
37+
RootScope rootScope;
3338
var lastTime = window.performance.now();
3439
var run = false;
3540
var fps = 0;
3641
var digestTime = 0;
3742
var currentDigestTime = 0;
3843
var balls = [];
39-
final Scope scope;
4044
var ballClassName = 'ball';
4145

42-
BounceController(this.scope) {
46+
BounceController(this.rootScope) {
4347
changeCount(100);
4448
if (run) tick();
4549
}
@@ -72,7 +76,7 @@ class BounceController {
7276
void timeDigest() {
7377
var start = window.performance.now();
7478
digestTime = currentDigestTime;
75-
scope.rootScope.domRead(() {
79+
rootScope.domRead(() {
7680
currentDigestTime = window.performance.now() - start;
7781
});
7882
}
@@ -82,7 +86,7 @@ class BounceController {
8286
var delay = now - lastTime;
8387

8488
fps = (1000/delay).round();
85-
for(var i=0, ii=balls.length; i<ii; i++) {
89+
for(var i = 0; i < balls.length; i++) {
8690
var b = balls[i];
8791
b.x += delay * b.velX;
8892
b.y += delay * b.velY;
@@ -124,11 +128,13 @@ class BallPosition {
124128

125129
class MyModule extends Module {
126130
MyModule() {
127-
bind(BounceController);
128131
bind(BallPosition);
132+
bind(BounceController);
129133
}
130134
}
131135

132136
main() {
133-
applicationFactory().addModule(new MyModule()).run();
137+
applicationFactory()
138+
.addModule(new MyModule())
139+
.run();
134140
}

example/web/bouncing_balls.html

+1-60
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,9 @@
22
<html>
33
<head>
44
<title>Bouncing balls</title>
5-
<style>
6-
.balls {
7-
border: 1px solid black;
8-
width: 420px;
9-
height: 420px;
10-
margin: 5px;
11-
}
12-
13-
.ball {
14-
display: inline-block;
15-
position: absolute;
16-
width: 20px;
17-
height: 20px;
18-
border: 1px solid black;
19-
-webkit-border-radius: 10px;
20-
-moz-border-radius: 10px;
21-
border-radius: 10px;
22-
}
23-
24-
.fps-bar {
25-
width: 200px;
26-
height: 10px;
27-
border: 1px solid black;
28-
display: inline-block;
29-
margin-left: 5px;
30-
}
31-
32-
.fps {
33-
height: 10px;
34-
width: 60px;
35-
background-color: green;
36-
}
37-
</style>
385
</head>
396
<body ng-app>
40-
<div bounce-controller>
41-
<div class="balls">
42-
<div ng-repeat="ball in bounce.balls"
43-
class="{{bounce.ballClassName}}"
44-
ball-position="ball"></div>
45-
</div>
46-
47-
<div>
48-
<div class="fps-bar">
49-
<div class="fps" ng-style-width="bounce.fps*4 + 'px'"></div>
50-
</div>
51-
</div>
52-
53-
{{bounce.fps}} fps. ({{bounce.balls.length}} balls) [{{1000/bounce.fps}} ms] <br>
54-
Digest: {{bounce.digestTime}} ms<br>
55-
<a href ng-click="bounce.changeCount(1)">+1</a>
56-
<a href ng-click="bounce.changeCount(10)">+10</a>
57-
<a href ng-click="bounce.changeCount(100)">+100</a>
58-
<br>
59-
<a href ng-click="bounce.changeCount(-1)">-1</a>
60-
<a href ng-click="bounce.changeCount(-10)">-10</a>
61-
<a href ng-click="bounce.changeCount(-100)">-100</a>
62-
<br>
63-
<a href ng-click="bounce.playPause()">&#x25B6;&#10073;&#10073;</a> <br>
64-
<a href ng-click="bounce.toggleCSS()">Toggle CSS</a><br>
65-
<a href ng-click="bounce.timeDigest()">noop</a><br>
66-
</div>
7+
<bounce-controller></bounce-controller>
678

689
<script type="application/dart" src="bouncing_balls.dart"></script>
6910
<script src="packages/browser/dart.js"></script>

example/web/bouncing_controller.css

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.balls {
2+
border: 1px solid black;
3+
width: 420px;
4+
height: 420px;
5+
margin: 5px;
6+
}
7+
8+
.ball {
9+
display: inline-block;
10+
position: absolute;
11+
width: 20px;
12+
height: 20px;
13+
border: 1px solid black;
14+
-webkit-border-radius: 10px;
15+
-moz-border-radius: 10px;
16+
border-radius: 10px;
17+
}
18+
19+
.fps-bar {
20+
width: 200px;
21+
height: 10px;
22+
border: 1px solid black;
23+
display: inline-block;
24+
margin-left: 5px;
25+
}
26+
27+
.fps {
28+
height: 10px;
29+
width: 60px;
30+
background-color: green;
31+
}

example/web/bouncing_controller.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="balls">
2+
<div ng-repeat="ball in ctrl.balls"
3+
class="{{ ctrl.ballClassName }}"
4+
ball-position="ball"></div>
5+
</div>
6+
7+
<div>
8+
<div class="fps-bar">
9+
<div class="fps" ng-style-width="ctrl.fps * 4 + 'px'"></div>
10+
</div>
11+
</div>
12+
13+
{{ ctrl.fps }} fps. ({{ ctrl.balls.length }} balls) [{{ 1000 / ctrl.fps }} ms] <br>
14+
Digest: {{ ctrl.digestTime }} ms<br>
15+
<a href ng-click="ctrl.changeCount(1)">+1</a>
16+
<a href ng-click="ctrl.changeCount(10)">+10</a>
17+
<a href ng-click="ctrl.changeCount(100)">+100</a>
18+
<br>
19+
<a href ng-click="ctrl.changeCount(-1)">-1</a>
20+
<a href ng-click="ctrl.changeCount(-10)">-10</a>
21+
<a href ng-click="ctrl.changeCount(-100)">-100</a>
22+
<br>
23+
<a href ng-click="ctrl.playPause()">&#x25B6;&#10073;&#10073;</a> <br>
24+
<a href ng-click="ctrl.toggleCSS()">Toggle CSS</a><br>
25+
<a href ng-click="ctrl.timeDigest()">noop</a><br>

0 commit comments

Comments
 (0)