Skip to content

Commit

Permalink
refactor(VmTurnZone): renamed to NgZone
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

VmTurnZone has been renamed to NgZone.

- The public API has not chnanged,
- The "outer" zone is now named "mount" zone (private to NgZone).
  • Loading branch information
vicb committed May 12, 2015
1 parent c75e216 commit e11c205
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 83 deletions.
18 changes: 9 additions & 9 deletions modules/angular2/src/core/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {TemplateResolver} from './compiler/template_resolver';
import {DirectiveMetadataReader} from './compiler/directive_metadata_reader';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy';
import {EmulatedUnscopedShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/emulated_unscoped_shadow_dom_strategy';
Expand Down Expand Up @@ -77,10 +77,10 @@ function _injectorBindings(appComponentType): List<Binding> {
bind(appComponentType).toFactory((ref) => ref.instance,
[appComponentRefToken]),
bind(LifeCycle).toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()),[ExceptionHandler]),
bind(EventManager).toFactory((zone) => {
bind(EventManager).toFactory((ngZone) => {
var plugins = [new HammerGesturesPlugin(), new KeyEventsPlugin(), new DomEventsPlugin()];
return new EventManager(plugins, zone);
}, [VmTurnZone]),
return new EventManager(plugins, ngZone);
}, [NgZone]),
bind(ShadowDomStrategy).toFactory(
(styleUrlResolver, doc) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, doc.head),
[StyleUrlResolver, DOCUMENT_TOKEN]),
Expand Down Expand Up @@ -123,7 +123,7 @@ function _injectorBindings(appComponentType): List<Binding> {
];
}

function _createVmZone(givenReporter:Function): VmTurnZone {
function _createNgZone(givenReporter:Function): NgZone {
var defaultErrorReporter = (exception, stackTrace) => {
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
DOM.logError(`${exception}\n\n${longStackTrace}`);
Expand All @@ -132,7 +132,7 @@ function _createVmZone(givenReporter:Function): VmTurnZone {

var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter;

var zone = new VmTurnZone({enableLongStackTrace: assertionsEnabled()});
var zone = new NgZone({enableLongStackTrace: assertionsEnabled()});
zone.initCallbacks({onErrorHandler: reporter});
return zone;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ export function bootstrap(appComponentType: Type,
BrowserDomAdapter.makeCurrent();
var bootstrapProcess = PromiseWrapper.completer();

var zone = _createVmZone(errorReporter);
var zone = _createNgZone(errorReporter);
zone.run(() => {
// TODO(rado): prepopulate template cache, so applications with only
// index.html and main.js are possible.
Expand Down Expand Up @@ -295,11 +295,11 @@ export class ApplicationRef {
}
}

function _createAppInjector(appComponentType: Type, bindings: List<Binding>, zone: VmTurnZone): Injector {
function _createAppInjector(appComponentType: Type, bindings: List<Binding>, zone: NgZone): Injector {
if (isBlank(_rootInjector)) _rootInjector = Injector.resolveAndCreate(_rootBindings);
var mergedBindings = isPresent(bindings) ?
ListWrapper.concat(_injectorBindings(appComponentType), bindings) :
_injectorBindings(appComponentType);
ListWrapper.push(mergedBindings, bind(VmTurnZone).toValue(zone));
ListWrapper.push(mergedBindings, bind(NgZone).toValue(zone));
return _rootInjector.resolveAndCreateChild(mergedBindings);
}
4 changes: 2 additions & 2 deletions modules/angular2/src/core/life_cycle/life_cycle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Injectable} from 'angular2/src/di/annotations_impl';
import {ChangeDetector} from 'angular2/change_detection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {isPresent} from 'angular2/src/facade/lang';

Expand Down Expand Up @@ -46,7 +46,7 @@ export class LifeCycle {
/**
* @private
*/
registerWith(zone:VmTurnZone, changeDetector:ChangeDetector = null) {
registerWith(zone:NgZone, changeDetector:ChangeDetector = null) {
if (isPresent(changeDetector)) {
this._changeDetector=changeDetector;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO(vicb): implement this class properly
// The current stub implementation is only here to please cjs tests
export class VmTurnZone {
export class NgZone {
constructor({enableLongStackTrace}) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import 'package:stack_trace/stack_trace.dart' show Chain;
*
* A VM turn consist of a single macrotask followed 0 to many microtasks.
*
* The wrapper maintains an "inner" and "outer" `Zone`. The application code will executes
* The wrapper maintains an "inner" and "mount" `Zone`. The application code will executes
* in the "inner" zone unless `runOutsideAngular` is explicitely called.
*
* A typical application will create a singleton `VmTurnZone`. The outer `Zone` is a fork of the root
* `Zone`. The default `onTurnDone` runs the Angular change detection.
* A typical application will create a singleton `NgZone`. The mount zone is the `Zone` where the singleton has been
* instantiated. The default `onTurnDone` runs the Angular change detection.
*/
class VmTurnZone {
class NgZone {
Function _onTurnStart;
Function _onTurnDone;
Function _onErrorHandler;

// Code executed in _outerZone does not trigger the onTurnDone.
Zone _outerZone;
// _innerZone is the child of _outerZone. Any code executed in this zone will trigger the
// Code executed in _mountZone does not trigger the onTurnDone.
Zone _mountZone;
// _innerZone is the child of _mountZone. Any code executed in this zone will trigger the
// onTurnDone hook at the end of the current VM turn.
Zone _innerZone;

Expand All @@ -42,14 +42,14 @@ class VmTurnZone {
/**
* Associates with this
*
* - an "outer" [Zone], which is a the one that created this.
* - an "inner" [Zone], which is a child of the outer [Zone].
* - a "mount" [Zone], which is a the one that instantiated this.
* - an "inner" [Zone], which is a child of the mount [Zone].
*
* @param {bool} enableLongStackTrace whether to enable long stack trace. They should only be
* enabled in development mode as they significantly impact perf.
*/
VmTurnZone({bool enableLongStackTrace}) {
_outerZone = Zone.current;
NgZone({bool enableLongStackTrace}) {
_mountZone = Zone.current;

if (enableLongStackTrace) {
_innerZone = Chain.capture(
Expand All @@ -68,7 +68,7 @@ class VmTurnZone {
* Initializes the zone hooks.
*
* The given error handler should re-throw the passed exception. Otherwise, exceptions will not
* propagate outside of the [VmTurnZone] and can alter the application execution flow.
* propagate outside of the [NgZone] and can alter the application execution flow.
* Not re-throwing could be used to help testing the code or advanced use cases.
*
* @param {Function} onTurnStart called before code executes in the inner zone for each VM turn
Expand All @@ -88,7 +88,7 @@ class VmTurnZone {
* Angular's auto digest mechanism.
*
* ```
* VmTurnZone zone = <ref to the application zone>;
* NgZone zone = <ref to the application zone>;
*
* void functionCalledFromJS() {
* zone.run(() {
Expand All @@ -105,13 +105,13 @@ class VmTurnZone {
}

/**
* Runs `fn` in the outer zone and returns whatever it returns.
* Runs `fn` in the mount zone and returns whatever it returns.
*
* In a typical app where the inner zone is the Angular zone, this allows one to escape Angular's
* auto-digest mechanism.
*
* ```
* void myFunction(VmTurnZone zone, Element element) {
* void myFunction(NgZone zone, Element element) {
* element.onClick.listen(() {
* // auto-digest will run after element click.
* });
Expand All @@ -124,7 +124,7 @@ class VmTurnZone {
* ```
*/
dynamic runOutsideAngular(fn()) {
return _outerZone.run(fn);
return _mountZone.run(fn);
}

void _maybeStartVmTurn(ZoneDelegate parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import {normalizeBlank, isPresent, global} from 'angular2/src/facade/lang';
/**
* A wrapper around zones that lets you schedule tasks after it has executed a task.
*
* The wrapper maintains an "inner" and "outer" `Zone`. The application code will executes
* The wrapper maintains an "inner" and an "mount" `Zone`. The application code will executes
* in the "inner" zone unless `runOutsideAngular` is explicitely called.
*
* A typical application will create a singleton `VmTurnZone`. The outer `Zone` is a fork of the root
* A typical application will create a singleton `NgZone`. The outer `Zone` is a fork of the root
* `Zone`. The default `onTurnDone` runs the Angular change detection.
*
* @exportedAs angular2/core
*/
export class VmTurnZone {
// Code executed in _outerZone does not trigger the onTurnDone.
_outerZone;
// _innerZone is the child of _outerZone. Any code executed in this zone will trigger the
export class NgZone {
// Code executed in _mountZone does not trigger the onTurnDone.
_mountZone;
// _innerZone is the child of _mountZone. Any code executed in this zone will trigger the
// onTurnDone hook at the end of the current VM turn.
_innerZone;

_onTurnStart:Function;
_onTurnDone:Function;
_onErrorHandler:Function;

// Number of microtasks pending from _outerZone (& descendants)
// Number of microtasks pending from _innerZone (& descendants)
_pendingMicrotask: number;
// Whether some code has been executed in the _innerZone (& descendants) in the current turn
_hasExecutedCodeInInnerZone: boolean;
// run() call depth in _outerZone. 0 at the end of a macrotask
// run() call depth in _mountZone. 0 at the end of a macrotask
// zone.run(() => { // top-level call
// zone.run(() => {}); // nested call -> in-turn
// });
Expand All @@ -36,8 +36,8 @@ export class VmTurnZone {
/**
* Associates with this
*
* - an "outer" zone, which is a child of the one that created this.
* - an "inner" zone, which is a child of the outer zone.
* - a "root" zone, which the one that instantiated this.
* - an "inner" zone, which is a child of the root zone.
*
* @param {bool} enableLongStackTrace whether to enable long stack trace. They should only be
* enabled in development mode as they significantly impact perf.
Expand All @@ -51,8 +51,8 @@ export class VmTurnZone {
this._hasExecutedCodeInInnerZone = false;
this._nestedRun = 0;

this._outerZone = global.zone;
this._innerZone = this._createInnerZone(this._outerZone, enableLongStackTrace)
this._mountZone = global.zone;
this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace)
}

/**
Expand All @@ -75,7 +75,7 @@ export class VmTurnZone {
* Angular's auto digest mechanism.
*
* ```
* var zone: VmTurnZone = [ref to the application zone];
* 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.
Expand All @@ -93,7 +93,7 @@ export class VmTurnZone {
* auto-digest mechanism.
*
* ```
* var zone: VmTurnZone = [ref to the application zone];
* var zone: NgZone = [ref to the application zone];
*
* zone.runOusideAngular(() => {
* element.onClick(() => {
Expand All @@ -103,23 +103,23 @@ export class VmTurnZone {
* ```
*/
runOutsideAngular(fn) {
return this._outerZone.run(fn);
return this._mountZone.run(fn);
}

_createInnerZone(zone, enableLongStackTrace) {
var vmTurnZone = this;
var ngZone = this;
var errorHandling;

if (enableLongStackTrace) {
errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, {
onError: function (e) {
vmTurnZone._onError(this, e)
ngZone._onError(this, e)
}
});
} else {
errorHandling = {
onError: function (e) {
vmTurnZone._onError(this, e)
ngZone._onError(this, e)
}
};
}
Expand All @@ -130,25 +130,25 @@ export class VmTurnZone {
'$run': function(parentRun) {
return function() {
try {
vmTurnZone._nestedRun++;
if (!vmTurnZone._hasExecutedCodeInInnerZone) {
vmTurnZone._hasExecutedCodeInInnerZone = true;
if (vmTurnZone._onTurnStart) {
parentRun.call(vmTurnZone._innerZone, vmTurnZone._onTurnStart);
ngZone._nestedRun++;
if (!ngZone._hasExecutedCodeInInnerZone) {
ngZone._hasExecutedCodeInInnerZone = true;
if (ngZone._onTurnStart) {
parentRun.call(ngZone._innerZone, ngZone._onTurnStart);
}
}
return parentRun.apply(this, arguments);
} finally {
vmTurnZone._nestedRun--;
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
// to run()).
if (vmTurnZone._pendingMicrotasks == 0 && vmTurnZone._nestedRun == 0) {
if (vmTurnZone._onTurnDone && vmTurnZone._hasExecutedCodeInInnerZone) {
if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0) {
if (ngZone._onTurnDone && ngZone._hasExecutedCodeInInnerZone) {
try {
parentRun.call(vmTurnZone._innerZone, vmTurnZone._onTurnDone);
parentRun.call(ngZone._innerZone, ngZone._onTurnDone);
} finally {
vmTurnZone._hasExecutedCodeInInnerZone = false;
ngZone._hasExecutedCodeInInnerZone = false;
}
}
}
Expand All @@ -157,12 +157,12 @@ export class VmTurnZone {
},
'$scheduleMicrotask': function(parentScheduleMicrotask) {
return function(fn) {
vmTurnZone._pendingMicrotasks++;
ngZone._pendingMicrotasks++;
var microtask = function() {
try {
fn();
} finally {
vmTurnZone._pendingMicrotasks--;
ngZone._pendingMicrotasks--;
}
};
parentScheduleMicrotask.call(this, microtask);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {NgZone} from 'angular2/src/core/zone/ng_zone';

export class MockVmTurnZone extends VmTurnZone {
export class MockNgZone extends NgZone {
constructor() {
super({enableLongStackTrace: false});
}

run(fn) {
fn();
return fn();
}

runOutsideAngular(fn) {
Expand Down
10 changes: 5 additions & 5 deletions modules/angular2/src/render/dom/events/event_manager.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {isBlank, BaseException, isPresent, StringWrapper} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {NgZone} from 'angular2/src/core/zone/ng_zone';

var BUBBLE_SYMBOL = '^';

export class EventManager {
_plugins: List<EventManagerPlugin>;
_zone: VmTurnZone;
_zone: NgZone;

constructor(plugins: List<EventManagerPlugin>, zone: VmTurnZone) {
constructor(plugins: List<EventManagerPlugin>, zone: NgZone) {
this._zone = zone;
this._plugins = plugins;
for (var i = 0; i < plugins.length; i++) {
Expand All @@ -29,7 +29,7 @@ export class EventManager {
return plugin.addGlobalEventListener(target, withoutBubbleSymbol, handler, withoutBubbleSymbol != eventName);
}

getZone(): VmTurnZone {
getZone(): NgZone {
return this._zone;
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export class DomEventsPlugin extends EventManagerPlugin {
});
}

_getOutsideHandler(shouldSupportBubble: boolean, element, handler: Function, zone: VmTurnZone) {
_getOutsideHandler(shouldSupportBubble: boolean, element, handler: Function, zone: NgZone) {
return shouldSupportBubble ?
DomEventsPlugin.bubbleCallback(element, handler, zone) :
DomEventsPlugin.sameElementCallback(element, handler, zone);
Expand Down
Loading

0 comments on commit e11c205

Please sign in to comment.