Skip to content

Commit 6c1cb08

Browse files
committed
refactor(examples): ts’ify
relates to angular#2008
1 parent 4b98ed1 commit 6c1cb08

File tree

14 files changed

+163
-281
lines changed

14 files changed

+163
-281
lines changed

modules/examples/e2e_test/sourcemap/sourcemap_spec.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ describe('sourcemaps', function () {
3737
});
3838

3939
var finalMapData = fs.readFileSync(
40-
'dist/js/prod/es6/examples/src/sourcemap/index.map');
40+
'dist/js/prod/es6/examples/src/sourcemap/index.es6.map');
4141
var finalDecoder = new sourceMap.SourceMapConsumer(JSON.parse(finalMapData));
4242

4343
var finalPosition = finalDecoder.originalPositionFor(originalPosition);
4444

45-
var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.js',
45+
var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.ts',
4646
{encoding: 'UTF-8'}).split('\n');
4747
expect(sourceCodeLines[finalPosition.line - 1])
4848
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);

modules/examples/src/gestures/index.js

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {bootstrap, Component, View} from 'angular2/angular2';
2+
import {reflector} from 'angular2/src/reflection/reflection';
3+
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
4+
5+
@Component({selector: 'gestures-app'})
6+
@View({templateUrl: 'template.html'})
7+
class GesturesCmp {
8+
swipeDirection: string = '-';
9+
pinchScale: number = 1;
10+
rotateAngle: number = 0;
11+
12+
onSwipe(event): void { this.swipeDirection = event.deltaX > 0 ? 'right' : 'left'; }
13+
14+
onPinch(event): void { this.pinchScale = event.scale; }
15+
16+
onRotate(event): void { this.rotateAngle = event.rotation; }
17+
}
18+
19+
export function main() {
20+
reflector.reflectionCapabilities = new ReflectionCapabilities();
21+
bootstrap(GesturesCmp);
22+
}
Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import {ElementRef} from 'angular2/angular2';
2-
import {Injectable} from 'angular2/src/di/annotations_impl';
1+
import {ElementRef, Component, Directive, View, Injectable} from 'angular2/angular2';
32

4-
// TODO(radokirov): Once the application is transpiled by TS instead of Traceur,
5-
// add those imports back into 'angular2/angular2';
6-
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
7-
import {View} from 'angular2/src/core/annotations_impl/view';
3+
// A service available to the Injector, used by the HelloCmp component.
4+
@Injectable()
5+
class GreetingService {
6+
greeting: string = 'hello';
7+
}
88

9+
// Directives are light-weight. They don't allow new
10+
// expression contexts (use @Component for those needs).
11+
@Directive({selector: '[red]'})
12+
class RedDec {
13+
// ElementRef is always injectable and it wraps the element on which the
14+
// directive was found by the compiler.
15+
constructor(el: ElementRef) { el.domElement.style.color = 'red'; }
16+
}
917

1018
// Angular 2.0 supports 2 basic types of directives:
1119
// - Component - the basic building blocks of Angular 2.0 apps. Backed by
@@ -28,7 +36,7 @@ import {View} from 'angular2/src/core/annotations_impl/view';
2836
// Expressions in the template (like {{greeting}}) are evaluated in the
2937
// context of the HelloCmp class below.
3038
template: `<div class="greeting">{{greeting}} <span red>world</span>!</div>
31-
<button class="changeButton" (click)="changeGreeting()">change greeting</button><content></content>`,
39+
<button class="changeButton" (click)="changeGreeting()">change greeting</button>`,
3240
// All directives used in the template need to be specified. This allows for
3341
// modularity (RedDec can only be used in this template)
3442
// and better tooling (the template can be invalidated if the attribute is
@@ -37,32 +45,8 @@ import {View} from 'angular2/src/core/annotations_impl/view';
3745
})
3846
export class HelloCmp {
3947
greeting: string;
40-
constructor(service: GreetingService) {
41-
this.greeting = service.greeting;
42-
}
43-
changeGreeting() {
44-
this.greeting = 'howdy';
45-
}
46-
}
4748

48-
// Directives are light-weight. They don't allow new
49-
// expression contexts (use @Component for those needs).
50-
@Directive({
51-
selector: '[red]'
52-
})
53-
class RedDec {
54-
// ElementRef is always injectable and it wraps the element on which the
55-
// directive was found by the compiler.
56-
constructor(el: ElementRef) {
57-
el.domElement.style.color = 'red';
58-
}
59-
}
49+
constructor(service: GreetingService) { this.greeting = service.greeting; }
6050

61-
// A service available to the Injector, used by the HelloCmp component.
62-
@Injectable()
63-
class GreetingService {
64-
greeting:string;
65-
constructor() {
66-
this.greeting = 'hello';
67-
}
51+
changeGreeting(): void { this.greeting = 'howdy'; }
6852
}
Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import {bootstrap} from 'angular2/angular2';
1+
import {bootstrap, Component, View} from 'angular2/angular2';
22
import {KeyEventsPlugin} from 'angular2/src/render/dom/events/key_events';
33

4-
// TODO(radokirov): Once the application is transpiled by TS instead of Traceur,
5-
// add those imports back into 'angular2/angular2';
6-
import {Component} from 'angular2/src/core/annotations_impl/annotations';
7-
import {View} from 'angular2/src/core/annotations_impl/view';
8-
9-
// 2 imports for the Dart version:
104
import {reflector} from 'angular2/src/reflection/reflection';
115
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
126

13-
@Component({
14-
selector: 'key-events-app'
15-
})
7+
@Component({selector: 'key-events-app'})
168
@View({
179
template: `Click in the following area and press a key to display its name:<br>
1810
<div (keydown)="onKeyDown($event)" class="sample-area" tabindex="0">{{lastKey}}</div><br>
@@ -25,31 +17,23 @@ import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabil
2517
>{{shiftEnter ? 'You pressed shift.enter!' : ''}}</div>`
2618
})
2719
class KeyEventsApp {
28-
lastKey: string;
29-
shiftEnter: boolean;
30-
31-
constructor() {
32-
this.lastKey = '(none)';
33-
this.shiftEnter = false;
34-
}
20+
lastKey: string = '(none)';
21+
shiftEnter: boolean = false;
3522

36-
onKeyDown(event) {
23+
onKeyDown(event): void {
3724
this.lastKey = KeyEventsPlugin.getEventFullKey(event);
3825
event.preventDefault();
3926
}
4027

41-
onShiftEnter(event) {
28+
onShiftEnter(event): void {
4229
this.shiftEnter = true;
4330
event.preventDefault();
4431
}
4532

46-
resetShiftEnter() {
47-
this.shiftEnter = false;
48-
}
49-
33+
resetShiftEnter(): void { this.shiftEnter = false; }
5034
}
5135

5236
export function main() {
53-
reflector.reflectionCapabilities = new ReflectionCapabilities(); // for the Dart version
37+
reflector.reflectionCapabilities = new ReflectionCapabilities(); // for the Dart version
5438
bootstrap(KeyEventsApp);
5539
}

modules/examples/src/sourcemap/index.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {BaseException} from 'angular2/src/facade/lang';
2+
import {bootstrap, Component, View} from 'angular2/angular2';
3+
4+
@Component({
5+
selector: 'error-app',
6+
})
7+
@View({
8+
template: `
9+
<button class="errorButton" (click)="createError()">create error</button>`
10+
})
11+
export class ErrorComponent {
12+
createError(): void { throw new BaseException('Sourcemap test'); }
13+
}
14+
15+
export function main() {
16+
bootstrap(ErrorComponent);
17+
}

modules/examples/src/todo/index.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)