Skip to content

Commit fa28b28

Browse files
committed
build(typescript): Migrated change detection to typescript
1 parent f0ef72d commit fa28b28

45 files changed

Lines changed: 2344 additions & 2577 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,40 @@
66
*/
77

88
export {
9-
ASTWithSource, AST, AstTransformer, AccessMember, LiteralArray, ImplicitReceiver
9+
ASTWithSource,
10+
AST,
11+
AstTransformer,
12+
AccessMember,
13+
LiteralArray,
14+
ImplicitReceiver
1015
} from './src/change_detection/parser/ast';
1116

1217
export {Lexer} from './src/change_detection/parser/lexer';
1318
export {Parser} from './src/change_detection/parser/parser';
1419
export {Locals} from './src/change_detection/parser/locals';
1520

16-
export {ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError} from './src/change_detection/exceptions';
17-
export {ProtoChangeDetector, ChangeDispatcher, ChangeDetector, ChangeDetection} from './src/change_detection/interfaces';
18-
export {CHECK_ONCE, CHECK_ALWAYS, DETACHED, CHECKED, ON_PUSH, DEFAULT} from './src/change_detection/constants';
19-
export {DynamicProtoChangeDetector, JitProtoChangeDetector} from './src/change_detection/proto_change_detector';
21+
export {
22+
ExpressionChangedAfterItHasBeenChecked,
23+
ChangeDetectionError
24+
} from './src/change_detection/exceptions';
25+
export {
26+
ProtoChangeDetector,
27+
ChangeDispatcher,
28+
ChangeDetector,
29+
ChangeDetection
30+
} from './src/change_detection/interfaces';
31+
export {
32+
CHECK_ONCE,
33+
CHECK_ALWAYS,
34+
DETACHED,
35+
CHECKED,
36+
ON_PUSH,
37+
DEFAULT
38+
} from './src/change_detection/constants';
39+
export {
40+
DynamicProtoChangeDetector,
41+
JitProtoChangeDetector
42+
} from './src/change_detection/proto_change_detector';
2043
export {BindingRecord} from './src/change_detection/binding_record';
2144
export {DirectiveIndex, DirectiveRecord} from './src/change_detection/directive_record';
2245
export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detector';
@@ -25,5 +48,13 @@ export {PipeRegistry} from './src/change_detection/pipes/pipe_registry';
2548
export {uninitialized} from './src/change_detection/change_detection_util';
2649
export {WrappedValue, Pipe} from './src/change_detection/pipes/pipe';
2750
export {
28-
defaultPipes, DynamicChangeDetection, JitChangeDetection, defaultPipeRegistry
51+
defaultPipes,
52+
DynamicChangeDetection,
53+
JitChangeDetection,
54+
defaultPipeRegistry
2955
} from './src/change_detection/change_detection';
56+
57+
// HACK: workaround for Traceur behavior.
58+
// It expects all transpiled modules to contain this marker.
59+
// TODO: remove this when we no longer use traceur
60+
export var __esModule = true;

modules/angular2/src/change_detection/abstract_change_detector.js renamed to modules/angular2/src/change_detection/abstract_change_detector.ts

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import {ChangeDetectorRef} from './change_detector_ref';
44
import {ChangeDetector} from './interfaces';
55
import {CHECK_ALWAYS, CHECK_ONCE, CHECKED, DETACHED, ON_PUSH} from './constants';
66

7+
// HACK: workaround for Traceur behavior.
8+
// It expects all transpiled modules to contain this marker.
9+
// TODO: remove this when we no longer use traceur
10+
export var __esModule = true;
11+
712
export class AbstractChangeDetector extends ChangeDetector {
8-
lightDomChildren:List;
9-
shadowDomChildren:List;
10-
parent:ChangeDetector;
11-
mode:string;
12-
ref:ChangeDetectorRef;
13+
lightDomChildren: List<any>;
14+
shadowDomChildren: List<any>;
15+
parent: ChangeDetector;
16+
mode: string;
17+
ref: ChangeDetectorRef;
1318

1419
constructor() {
1520
super();
@@ -19,37 +24,27 @@ export class AbstractChangeDetector extends ChangeDetector {
1924
this.mode = null;
2025
}
2126

22-
addChild(cd:ChangeDetector) {
27+
addChild(cd: ChangeDetector) {
2328
ListWrapper.push(this.lightDomChildren, cd);
2429
cd.parent = this;
2530
}
2631

27-
removeChild(cd:ChangeDetector) {
28-
ListWrapper.remove(this.lightDomChildren, cd);
29-
}
32+
removeChild(cd: ChangeDetector) { ListWrapper.remove(this.lightDomChildren, cd); }
3033

31-
addShadowDomChild(cd:ChangeDetector) {
34+
addShadowDomChild(cd: ChangeDetector) {
3235
ListWrapper.push(this.shadowDomChildren, cd);
3336
cd.parent = this;
3437
}
3538

36-
removeShadowDomChild(cd:ChangeDetector) {
37-
ListWrapper.remove(this.shadowDomChildren, cd);
38-
}
39+
removeShadowDomChild(cd: ChangeDetector) { ListWrapper.remove(this.shadowDomChildren, cd); }
3940

40-
remove() {
41-
this.parent.removeChild(this);
42-
}
41+
remove() { this.parent.removeChild(this); }
4342

44-
detectChanges() {
45-
this._detectChanges(false);
46-
}
43+
detectChanges() { this._detectChanges(false); }
4744

48-
checkNoChanges() {
49-
this._detectChanges(true);
50-
}
45+
checkNoChanges() { this._detectChanges(true); }
5146

52-
_detectChanges(throwOnChange:boolean) {
47+
_detectChanges(throwOnChange: boolean) {
5348
if (this.mode === DETACHED || this.mode === CHECKED) return;
5449

5550
this.detectChangesInRecords(throwOnChange);
@@ -63,30 +58,28 @@ export class AbstractChangeDetector extends ChangeDetector {
6358
if (this.mode === CHECK_ONCE) this.mode = CHECKED;
6459
}
6560

66-
detectChangesInRecords(throwOnChange:boolean){}
67-
callOnAllChangesDone(){}
61+
detectChangesInRecords(throwOnChange: boolean) {}
62+
callOnAllChangesDone() {}
6863

69-
_detectChangesInLightDomChildren(throwOnChange:boolean) {
64+
_detectChangesInLightDomChildren(throwOnChange: boolean) {
7065
var c = this.lightDomChildren;
71-
for(var i = 0; i < c.length; ++i) {
66+
for (var i = 0; i < c.length; ++i) {
7267
c[i]._detectChanges(throwOnChange);
7368
}
7469
}
7570

76-
_detectChangesInShadowDomChildren(throwOnChange:boolean) {
71+
_detectChangesInShadowDomChildren(throwOnChange: boolean) {
7772
var c = this.shadowDomChildren;
78-
for(var i = 0; i < c.length; ++i) {
73+
for (var i = 0; i < c.length; ++i) {
7974
c[i]._detectChanges(throwOnChange);
8075
}
8176
}
8277

83-
markAsCheckOnce() {
84-
this.mode = CHECK_ONCE;
85-
}
78+
markAsCheckOnce() { this.mode = CHECK_ONCE; }
8679

8780
markPathToRootAsCheckOnce() {
88-
var c = this;
89-
while(isPresent(c) && c.mode != DETACHED) {
81+
var c: ChangeDetector = this;
82+
while (isPresent(c) && c.mode != DETACHED) {
9083
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
9184
c = c.parent;
9285
}

modules/angular2/src/change_detection/binding_record.js

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {isPresent, isBlank} from 'angular2/src/facade/lang';
2+
import {SetterFn} from 'angular2/src/reflection/types';
3+
import {AST} from './parser/ast';
4+
import {DirectiveIndex, DirectiveRecord} from './directive_record';
5+
6+
// HACK: workaround for Traceur behavior.
7+
// It expects all transpiled modules to contain this marker.
8+
// TODO: remove this when we no longer use traceur
9+
export var __esModule = true;
10+
11+
const DIRECTIVE = "directive";
12+
const ELEMENT = "element";
13+
const TEXT_NODE = "textNode";
14+
15+
export class BindingRecord {
16+
constructor(public mode: string, public implicitReceiver: any, public ast: AST,
17+
public elementIndex: number, public propertyName: string, public setter: SetterFn,
18+
public directiveRecord: DirectiveRecord) {}
19+
20+
callOnChange() { return isPresent(this.directiveRecord) && this.directiveRecord.callOnChange; }
21+
22+
isOnPushChangeDetection() {
23+
return isPresent(this.directiveRecord) && this.directiveRecord.isOnPushChangeDetection();
24+
}
25+
26+
isDirective() { return this.mode === DIRECTIVE; }
27+
28+
isElement() { return this.mode === ELEMENT; }
29+
30+
isTextNode() { return this.mode === TEXT_NODE; }
31+
32+
static createForDirective(ast: AST, propertyName: string, setter: SetterFn,
33+
directiveRecord: DirectiveRecord) {
34+
return new BindingRecord(DIRECTIVE, 0, ast, 0, propertyName, setter, directiveRecord);
35+
}
36+
37+
static createForElement(ast: AST, elementIndex: number, propertyName: string) {
38+
return new BindingRecord(ELEMENT, 0, ast, elementIndex, propertyName, null, null);
39+
}
40+
41+
static createForHostProperty(directiveIndex: DirectiveIndex, ast: AST, propertyName: string) {
42+
return new BindingRecord(ELEMENT, directiveIndex, ast, directiveIndex.elementIndex,
43+
propertyName, null, null);
44+
}
45+
46+
static createForTextNode(ast: AST, elementIndex: number) {
47+
return new BindingRecord(TEXT_NODE, 0, ast, elementIndex, null, null, null);
48+
}
49+
}

modules/angular2/src/change_detection/change_detection.js

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

0 commit comments

Comments
 (0)