Skip to content

Commit 1beadb8

Browse files
committed
refactor(render): ts’ify render api
1 parent bd8724e commit 1beadb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+931
-941
lines changed

modules/angular2/globals.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
* This file contains declarations of global symbols we reference in our code
33
*/
44

5+
/// <reference path="typings/hammerjs/hammerjs"/>
6+
/// <reference path="typings/zone/zone.d.ts"/>
7+
58
declare var assert: any;
69
declare var global: Window;
710
type int = number;
811

912
interface List<T> extends Array<T> {}
1013

14+
interface StringMap<K,V> extends Object {}
15+
1116
interface Window {
1217
Object: typeof Object;
1318
Array: typeof Array;
@@ -20,4 +25,6 @@ interface Window {
2025
assert: typeof assert;
2126
gc(): void;
2227
Reflect: any;
28+
zone: Zone;
29+
Hammer: HammerStatic;
2330
}

modules/angular2/src/core/compiler/view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {ProtoElementInjector, ElementInjector, PreBuiltObjects, DirectiveBinding
66
import {ElementBinder} from './element_binder';
77
import {IMPLEMENTS, int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
88
import * as renderApi from 'angular2/src/render/api';
9+
import {EventDispatcher} from 'angular2/src/render/api';
910

1011
export class AppViewContainer {
1112
views: List<AppView>;
@@ -21,8 +22,7 @@ export class AppViewContainer {
2122
*
2223
*/
2324
@IMPLEMENTS(ChangeDispatcher)
24-
// TODO(tbosch): this is not supported in dart2js (no '.' is allowed)
25-
// @IMPLEMENTS(renderApi.EventDispatcher)
25+
@IMPLEMENTS(EventDispatcher)
2626
export class AppView {
2727
render:renderApi.RenderViewRef;
2828
/// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector

modules/angular2/src/core/zone/ng_zone.cjs

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

modules/angular2/src/core/zone/ng_zone.es6 renamed to modules/angular2/src/core/zone/ng_zone.ts

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ export class NgZone {
1919
// onTurnDone hook at the end of the current VM turn.
2020
_innerZone;
2121

22-
_onTurnStart:Function;
23-
_onTurnDone:Function;
24-
_onErrorHandler:Function;
22+
_onTurnStart: () => void;
23+
_onTurnDone: () => void;
24+
_onErrorHandler: (error, stack) => void;
2525

2626
// Number of microtasks pending from _innerZone (& descendants)
27-
_pendingMicrotask: number;
27+
_pendingMicrotasks: number;
2828
// Whether some code has been executed in the _innerZone (& descendants) in the current turn
2929
_hasExecutedCodeInInnerZone: boolean;
3030
// run() call depth in _mountZone. 0 at the end of a macrotask
3131
// zone.run(() => { // top-level call
3232
// zone.run(() => {}); // nested call -> in-turn
3333
// });
3434
_nestedRun: number;
35+
36+
// TODO(vicb): implement this class properly for node.js environment
37+
// This disabled flag is only here to please cjs tests
38+
_disabled: boolean;
3539

3640
/**
3741
* Associates with this
@@ -50,19 +54,31 @@ export class NgZone {
5054
this._pendingMicrotasks = 0;
5155
this._hasExecutedCodeInInnerZone = false;
5256
this._nestedRun = 0;
53-
54-
this._mountZone = global.zone;
55-
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
57+
58+
if (global.zone) {
59+
this._disabled = false;
60+
this._mountZone = global.zone;
61+
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
62+
} else {
63+
this._disabled = true;
64+
this._mountZone = null;
65+
}
5666
}
5767

5868
/**
5969
* Initializes the zone hooks.
6070
*
61-
* @param {Function} onTurnStart called before code executes in the inner zone for each VM turn
62-
* @param {Function} onTurnDone called at the end of a VM turn if code has executed in the inner zone
63-
* @param {Function} onErrorHandler called when an exception is thrown by a macro or micro task
71+
* @param {() => void} onTurnStart called before code executes in the inner zone for each VM turn
72+
* @param {() => void} onTurnDone called at the end of a VM turn if code has executed in the inner
73+
* zone
74+
* @param {(error, stack) => void} onErrorHandler called when an exception is thrown by a macro or
75+
* micro task
6476
*/
65-
initCallbacks({onTurnStart, onTurnDone, onErrorHandler} = {}) {
77+
initCallbacks({onTurnStart, onTurnDone, onErrorHandler}: {
78+
onTurnStart?: () => void,
79+
onTurnDone?: () => void,
80+
onErrorHandler?: (error, stack) => void
81+
} = {}) {
6682
this._onTurnStart = normalizeBlank(onTurnStart);
6783
this._onTurnDone = normalizeBlank(onTurnDone);
6884
this._onErrorHandler = normalizeBlank(onErrorHandler);
@@ -78,12 +94,17 @@ export class NgZone {
7894
* var zone: NgZone = [ref to the application zone];
7995
*
8096
* zone.run(() => {
81-
* // the change detection will run after this function and the microtasks it enqueues have executed.
97+
* // the change detection will run after this function and the microtasks it enqueues have
98+
* executed.
8299
* });
83100
* ```
84101
*/
85-
run(fn) {
86-
return this._innerZone.run(fn);
102+
run(fn) {
103+
if (this._disabled) {
104+
return fn();
105+
} else {
106+
return this._innerZone.run(fn);
107+
}
87108
}
88109

89110
/**
@@ -102,30 +123,28 @@ export class NgZone {
102123
* });
103124
* ```
104125
*/
105-
runOutsideAngular(fn) {
106-
return this._mountZone.run(fn);
126+
runOutsideAngular(fn) {
127+
if (this._disabled) {
128+
return fn();
129+
} else {
130+
return this._mountZone.run(fn);
131+
}
107132
}
108133

109134
_createInnerZone(zone, enableLongStackTrace) {
110135
var ngZone = this;
111136
var errorHandling;
112137

113138
if (enableLongStackTrace) {
114-
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, {
115-
onError: function (e) {
116-
ngZone._onError(this, e)
117-
}
118-
});
139+
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone,
140+
{onError: function(e) { ngZone._onError(this, e) }});
119141
} else {
120142
errorHandling = {
121-
onError: function (e) {
122-
ngZone._onError(this, e)
123-
}
143+
onError: function(e) { ngZone._onError(this, e) }
124144
};
125145
}
126146

127-
return zone
128-
.fork(errorHandling)
147+
return zone.fork(errorHandling)
129148
.fork({
130149
'$run': function(parentRun) {
131150
return function() {
@@ -140,8 +159,10 @@ export class NgZone {
140159
return parentRun.apply(this, arguments);
141160
} finally {
142161
ngZone._nestedRun--;
143-
// If there are no more pending microtasks, we are at the end of a VM turn (or in onTurnStart)
144-
// _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are nested calls
162+
// If there are no more pending microtasks, we are at the end of a VM turn (or in
163+
// onTurnStart)
164+
// _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are
165+
// nested calls
145166
// to run()).
146167
if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0) {
147168
if (ngZone._onTurnDone && ngZone._hasExecutedCodeInInnerZone) {

modules/angular2/src/dom/browser_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ defaultDoc() {
273273
getBoundingClientRect(el) {
274274
return el.getBoundingClientRect();
275275
}
276-
getTitle() {
276+
getTitle(): string {
277277
return document.title;
278278
}
279279
setTitle(newTitle: string) {

modules/angular2/src/dom/dom_adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class DomAdapter {
8181
removeStyle(element, stylename: string) { throw _abstract(); }
8282
getStyle(element, stylename: string) { throw _abstract(); }
8383
tagName(element): string { throw _abstract(); }
84-
attributeMap(element) { throw _abstract(); }
84+
attributeMap(element): Map<string, string> { throw _abstract(); }
8585
hasAttribute(element, attribute: string): boolean { throw _abstract(); }
8686
getAttribute(element, attribute: string): string { throw _abstract(); }
8787
setAttribute(element, name: string, value: string) { throw _abstract(); }
@@ -90,7 +90,7 @@ export class DomAdapter {
9090
createHtmlDocument() { throw _abstract(); }
9191
defaultDoc(): any { throw _abstract(); }
9292
getBoundingClientRect(el) { throw _abstract(); }
93-
getTitle() { throw _abstract(); }
93+
getTitle(): string { throw _abstract(); }
9494
setTitle(newTitle: string) { throw _abstract(); }
9595
elementMatches(n, selector: string): boolean { throw _abstract(); }
9696
isTemplateElement(el: any): boolean { throw _abstract(); }

0 commit comments

Comments
 (0)