refactor(render): ts’ify render api
This commit is contained in:
4
modules/angular2/src/core/compiler/view.js
vendored
4
modules/angular2/src/core/compiler/view.js
vendored
@ -6,6 +6,7 @@ import {ProtoElementInjector, ElementInjector, PreBuiltObjects, DirectiveBinding
|
||||
import {ElementBinder} from './element_binder';
|
||||
import {IMPLEMENTS, int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import {EventDispatcher} from 'angular2/src/render/api';
|
||||
|
||||
export class AppViewContainer {
|
||||
views: List<AppView>;
|
||||
@ -21,8 +22,7 @@ export class AppViewContainer {
|
||||
*
|
||||
*/
|
||||
@IMPLEMENTS(ChangeDispatcher)
|
||||
// TODO(tbosch): this is not supported in dart2js (no '.' is allowed)
|
||||
// @IMPLEMENTS(renderApi.EventDispatcher)
|
||||
@IMPLEMENTS(EventDispatcher)
|
||||
export class AppView {
|
||||
render:renderApi.RenderViewRef;
|
||||
/// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector
|
||||
|
@ -1,17 +0,0 @@
|
||||
// TODO(vicb): implement this class properly
|
||||
// The current stub implementation is only here to please cjs tests
|
||||
export class NgZone {
|
||||
constructor({enableLongStackTrace}) {
|
||||
}
|
||||
|
||||
initCallbacks({onTurnStart, onTurnDone, onScheduleMicrotask, onErrorHandler} = {}) {
|
||||
}
|
||||
|
||||
run(fn) {
|
||||
return fn();
|
||||
}
|
||||
|
||||
runOutsideAngular(fn) {
|
||||
return fn();
|
||||
}
|
||||
}
|
@ -19,12 +19,12 @@ export class NgZone {
|
||||
// onTurnDone hook at the end of the current VM turn.
|
||||
_innerZone;
|
||||
|
||||
_onTurnStart:Function;
|
||||
_onTurnDone:Function;
|
||||
_onErrorHandler:Function;
|
||||
_onTurnStart: () => void;
|
||||
_onTurnDone: () => void;
|
||||
_onErrorHandler: (error, stack) => void;
|
||||
|
||||
// Number of microtasks pending from _innerZone (& descendants)
|
||||
_pendingMicrotask: number;
|
||||
_pendingMicrotasks: number;
|
||||
// Whether some code has been executed in the _innerZone (& descendants) in the current turn
|
||||
_hasExecutedCodeInInnerZone: boolean;
|
||||
// run() call depth in _mountZone. 0 at the end of a macrotask
|
||||
@ -32,6 +32,10 @@ export class NgZone {
|
||||
// zone.run(() => {}); // nested call -> in-turn
|
||||
// });
|
||||
_nestedRun: number;
|
||||
|
||||
// TODO(vicb): implement this class properly for node.js environment
|
||||
// This disabled flag is only here to please cjs tests
|
||||
_disabled: boolean;
|
||||
|
||||
/**
|
||||
* Associates with this
|
||||
@ -50,19 +54,31 @@ export class NgZone {
|
||||
this._pendingMicrotasks = 0;
|
||||
this._hasExecutedCodeInInnerZone = false;
|
||||
this._nestedRun = 0;
|
||||
|
||||
this._mountZone = global.zone;
|
||||
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
|
||||
|
||||
if (global.zone) {
|
||||
this._disabled = false;
|
||||
this._mountZone = global.zone;
|
||||
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
|
||||
} else {
|
||||
this._disabled = true;
|
||||
this._mountZone = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the zone hooks.
|
||||
*
|
||||
* @param {Function} onTurnStart called before code executes in the inner zone for each VM turn
|
||||
* @param {Function} onTurnDone called at the end of a VM turn if code has executed in the inner zone
|
||||
* @param {Function} onErrorHandler called when an exception is thrown by a macro or micro task
|
||||
* @param {() => void} onTurnStart called before code executes in the inner zone for each VM turn
|
||||
* @param {() => void} onTurnDone called at the end of a VM turn if code has executed in the inner
|
||||
* zone
|
||||
* @param {(error, stack) => void} onErrorHandler called when an exception is thrown by a macro or
|
||||
* micro task
|
||||
*/
|
||||
initCallbacks({onTurnStart, onTurnDone, onErrorHandler} = {}) {
|
||||
initCallbacks({onTurnStart, onTurnDone, onErrorHandler}: {
|
||||
onTurnStart?: () => void,
|
||||
onTurnDone?: () => void,
|
||||
onErrorHandler?: (error, stack) => void
|
||||
} = {}) {
|
||||
this._onTurnStart = normalizeBlank(onTurnStart);
|
||||
this._onTurnDone = normalizeBlank(onTurnDone);
|
||||
this._onErrorHandler = normalizeBlank(onErrorHandler);
|
||||
@ -78,12 +94,17 @@ export class NgZone {
|
||||
* var zone: NgZone = [ref to the application zone];
|
||||
*
|
||||
* zone.run(() => {
|
||||
* // the change detection will run after this function and the microtasks it enqueues have executed.
|
||||
* // the change detection will run after this function and the microtasks it enqueues have
|
||||
* executed.
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
run(fn) {
|
||||
return this._innerZone.run(fn);
|
||||
run(fn) {
|
||||
if (this._disabled) {
|
||||
return fn();
|
||||
} else {
|
||||
return this._innerZone.run(fn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,8 +123,12 @@ export class NgZone {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
runOutsideAngular(fn) {
|
||||
return this._mountZone.run(fn);
|
||||
runOutsideAngular(fn) {
|
||||
if (this._disabled) {
|
||||
return fn();
|
||||
} else {
|
||||
return this._mountZone.run(fn);
|
||||
}
|
||||
}
|
||||
|
||||
_createInnerZone(zone, enableLongStackTrace) {
|
||||
@ -111,21 +136,15 @@ export class NgZone {
|
||||
var errorHandling;
|
||||
|
||||
if (enableLongStackTrace) {
|
||||
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, {
|
||||
onError: function (e) {
|
||||
ngZone._onError(this, e)
|
||||
}
|
||||
});
|
||||
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone,
|
||||
{onError: function(e) { ngZone._onError(this, e) }});
|
||||
} else {
|
||||
errorHandling = {
|
||||
onError: function (e) {
|
||||
ngZone._onError(this, e)
|
||||
}
|
||||
onError: function(e) { ngZone._onError(this, e) }
|
||||
};
|
||||
}
|
||||
|
||||
return zone
|
||||
.fork(errorHandling)
|
||||
return zone.fork(errorHandling)
|
||||
.fork({
|
||||
'$run': function(parentRun) {
|
||||
return function() {
|
||||
@ -140,8 +159,10 @@ export class NgZone {
|
||||
return parentRun.apply(this, arguments);
|
||||
} finally {
|
||||
ngZone._nestedRun--;
|
||||
// If there are no more pending microtasks, we are at the end of a VM turn (or in onTurnStart)
|
||||
// _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are nested calls
|
||||
// If there are no more pending microtasks, we are at the end of a VM turn (or in
|
||||
// onTurnStart)
|
||||
// _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are
|
||||
// nested calls
|
||||
// to run()).
|
||||
if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0) {
|
||||
if (ngZone._onTurnDone && ngZone._hasExecutedCodeInInnerZone) {
|
Reference in New Issue
Block a user