feat(core): enable dev mode by default
BREAKING CHANGE Before Previously Angular would run in dev prod mode by default, and you could enable the dev mode by calling enableDevMode. After Now, Angular runs in the dev mode by default, and you can enable the prod mode by calling enableProdMode.
This commit is contained in:
parent
de996ec50b
commit
3dca9d522a
|
@ -2,7 +2,7 @@ library angular2.core;
|
||||||
|
|
||||||
export './src/core/metadata.dart';
|
export './src/core/metadata.dart';
|
||||||
export './src/core/util.dart';
|
export './src/core/util.dart';
|
||||||
export './src/core/dev_mode.dart';
|
export 'package:angular2/src/facade/lang.dart' show enableProdMode;
|
||||||
export './src/core/di.dart' hide ForwardRefFn, resolveForwardRef, forwardRef;
|
export './src/core/di.dart' hide ForwardRefFn, resolveForwardRef, forwardRef;
|
||||||
export './src/facade/facade.dart';
|
export './src/facade/facade.dart';
|
||||||
export './src/core/application_ref.dart' show platform, createNgZone, PlatformRef, ApplicationRef;
|
export './src/core/application_ref.dart' show platform, createNgZone, PlatformRef, ApplicationRef;
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
*/
|
*/
|
||||||
export * from './src/core/metadata';
|
export * from './src/core/metadata';
|
||||||
export * from './src/core/util';
|
export * from './src/core/util';
|
||||||
export * from './src/core/dev_mode';
|
export * from './src/core/prod_mode';
|
||||||
export * from './src/core/di';
|
export * from './src/core/di';
|
||||||
export * from './src/facade/facade';
|
export * from './src/facade/facade';
|
||||||
|
export {enableProdMode} from 'angular2/src/facade/lang';
|
||||||
export {platform, createNgZone, PlatformRef, ApplicationRef} from './src/core/application_ref';
|
export {platform, createNgZone, PlatformRef, ApplicationRef} from './src/core/application_ref';
|
||||||
export {
|
export {
|
||||||
APP_ID,
|
APP_ID,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// #docregion enableDevMode
|
// #docregion enableProdMode
|
||||||
import {enableDevMode} from 'angular2/core';
|
import {enableProdMode} from 'angular2/core';
|
||||||
import {bootstrap} from 'angular2/bootstrap';
|
import {bootstrap} from 'angular2/bootstrap';
|
||||||
import {MyComponent} from 'my_component';
|
import {MyComponent} from 'my_component';
|
||||||
|
|
||||||
enableDevMode();
|
enableProdMode();
|
||||||
bootstrap(MyComponent);
|
bootstrap(MyComponent);
|
||||||
// #enddocregion
|
// #enddocregion
|
|
@ -30,7 +30,6 @@ interface BrowserNodeGlobal {
|
||||||
zone: Zone;
|
zone: Zone;
|
||||||
getAngularTestability: Function;
|
getAngularTestability: Function;
|
||||||
getAllAngularTestabilities: Function;
|
getAllAngularTestabilities: Function;
|
||||||
angularDevMode: boolean;
|
|
||||||
setTimeout: Function;
|
setTimeout: Function;
|
||||||
clearTimeout: Function;
|
clearTimeout: Function;
|
||||||
setInterval: Function;
|
setInterval: Function;
|
||||||
|
|
|
@ -34,9 +34,10 @@ import {
|
||||||
unimplemented
|
unimplemented
|
||||||
} from 'angular2/src/facade/exceptions';
|
} from 'angular2/src/facade/exceptions';
|
||||||
import {internalView} from 'angular2/src/core/linker/view_ref';
|
import {internalView} from 'angular2/src/core/linker/view_ref';
|
||||||
|
import {Console} from 'angular2/src/core/console';
|
||||||
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
||||||
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
|
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
|
||||||
import {lockDevMode} from 'angular2/src/facade/lang';
|
import {lockMode} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct providers specific to an individual root component.
|
* Construct providers specific to an individual root component.
|
||||||
|
@ -98,7 +99,7 @@ var _platformProviders: any[];
|
||||||
* provides, Angular will throw an exception.
|
* provides, Angular will throw an exception.
|
||||||
*/
|
*/
|
||||||
export function platform(providers?: Array<Type | Provider | any[]>): PlatformRef {
|
export function platform(providers?: Array<Type | Provider | any[]>): PlatformRef {
|
||||||
lockDevMode();
|
lockMode();
|
||||||
if (isPresent(_platform)) {
|
if (isPresent(_platform)) {
|
||||||
if (ListWrapper.equals(_platformProviders, providers)) {
|
if (ListWrapper.equals(_platformProviders, providers)) {
|
||||||
return _platform;
|
return _platform;
|
||||||
|
@ -425,7 +426,15 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||||
completer.reject(e, e.stack);
|
completer.reject(e, e.stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return completer.promise;
|
return completer.promise.then(_ => {
|
||||||
|
let c = this._injector.get(Console);
|
||||||
|
let modeDescription =
|
||||||
|
assertionsEnabled() ?
|
||||||
|
"in the development mode. Call enableProdMode() to enable the production mode." :
|
||||||
|
"in the production mode. Call enableDevMode() to enable the development mode.";
|
||||||
|
c.log(`Angular 2 is running ${modeDescription}`);
|
||||||
|
return _;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import {Injectable} from 'angular2/src/core/di';
|
||||||
|
import {print} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class Console {
|
||||||
|
log(message: string): void { print(message); }
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
export {enableDevMode} from 'angular2/src/facade/lang';
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {Type, isBlank, isPresent, assertionsEnabled, CONST_EXPR} from 'angular2/src/facade/lang';
|
import {Type, isBlank, isPresent, assertionsEnabled, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||||
import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
|
import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
|
||||||
|
import {Console} from 'angular2/src/core/console';
|
||||||
import {Reflector, reflector} from './reflection/reflection';
|
import {Reflector, reflector} from './reflection/reflection';
|
||||||
import {TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
import {TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||||
|
|
||||||
|
@ -10,5 +11,5 @@ function _reflector(): Reflector {
|
||||||
/**
|
/**
|
||||||
* A default set of providers which should be included in any Angular platform.
|
* A default set of providers which should be included in any Angular platform.
|
||||||
*/
|
*/
|
||||||
export const PLATFORM_COMMON_PROVIDERS: Array<Type | Provider | any[]> =
|
export const PLATFORM_COMMON_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR(
|
||||||
CONST_EXPR([new Provider(Reflector, {useFactory: _reflector, deps: []}), TestabilityRegistry]);
|
[new Provider(Reflector, {useFactory: _reflector, deps: []}), TestabilityRegistry, Console]);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
export {enableProdMode} from 'angular2/src/facade/lang';
|
|
@ -249,23 +249,34 @@ bool isJsObject(o) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _forceDevMode = false;
|
bool _forceDevMode = true;
|
||||||
bool _devModeLocked = false;
|
bool _modeLocked = false;
|
||||||
|
|
||||||
void lockDevMode() {
|
void lockMode() {
|
||||||
_devModeLocked = true;
|
_modeLocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@deprecated
|
||||||
void enableDevMode() {
|
void enableDevMode() {
|
||||||
if (_forceDevMode) {
|
if (_forceDevMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_devModeLocked) {
|
if (_modeLocked) {
|
||||||
throw new Exception("Cannot enable dev mode after platform setup.");
|
throw new Exception("Cannot enable dev mode after platform setup.");
|
||||||
}
|
}
|
||||||
_forceDevMode = true;
|
_forceDevMode = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enableProdMode() {
|
||||||
|
if (_forceDevMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_modeLocked) {
|
||||||
|
throw new Exception("Cannot enable prod mode after platform setup.");
|
||||||
|
}
|
||||||
|
_forceDevMode = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool assertionsEnabled() {
|
bool assertionsEnabled() {
|
||||||
var k = false;
|
var k = false;
|
||||||
assert((k = true));
|
assert((k = true));
|
||||||
|
|
|
@ -43,30 +43,27 @@ export function getTypeNameForDebugging(type: Type): string {
|
||||||
export var Math = _global.Math;
|
export var Math = _global.Math;
|
||||||
export var Date = _global.Date;
|
export var Date = _global.Date;
|
||||||
|
|
||||||
var _devMode: boolean = !!_global.angularDevMode;
|
var _devMode: boolean = true;
|
||||||
var _devModeLocked: boolean = false;
|
var _modeLocked: boolean = false;
|
||||||
|
|
||||||
export function lockDevMode() {
|
export function lockMode() {
|
||||||
_devModeLocked = true;
|
_modeLocked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable Angular's development mode, which turns on assertions and other
|
* Disable Angular's development mode, which turns off assertions and other
|
||||||
* checks within the framework.
|
* checks within the framework.
|
||||||
*
|
*
|
||||||
* One important assertion this enables verifies that a change detection pass
|
* One important assertion this disables verifies that a change detection pass
|
||||||
* does not result in additional changes to any bindings (also known as
|
* does not result in additional changes to any bindings (also known as
|
||||||
* unidirectional data flow).
|
* unidirectional data flow).
|
||||||
*
|
|
||||||
* {@example core/ts/dev_mode/dev_mode_example.ts region='enableDevMode'}
|
|
||||||
*/
|
*/
|
||||||
export function enableDevMode() {
|
export function enableProdMode() {
|
||||||
// TODO(alxhub): Refactor out of facade/lang as per issue #5157.
|
if (_modeLocked) {
|
||||||
if (_devModeLocked) {
|
|
||||||
// Cannot use BaseException as that ends up importing from facade/lang.
|
// Cannot use BaseException as that ends up importing from facade/lang.
|
||||||
throw 'Cannot enable dev mode after platform setup.';
|
throw 'Cannot enable prod mode after platform setup.';
|
||||||
}
|
}
|
||||||
_devMode = true;
|
_devMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertionsEnabled(): boolean {
|
export function assertionsEnabled(): boolean {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {
|
||||||
import {IS_DART, isPresent, stringify} from 'angular2/src/facade/lang';
|
import {IS_DART, isPresent, stringify} from 'angular2/src/facade/lang';
|
||||||
import {bootstrap} from 'angular2/platform/browser';
|
import {bootstrap} from 'angular2/platform/browser';
|
||||||
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
||||||
|
import {Console} from 'angular2/src/core/console';
|
||||||
import {Component, Directive, View, OnDestroy, platform} from 'angular2/core';
|
import {Component, Directive, View, OnDestroy, platform} from 'angular2/core';
|
||||||
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
|
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
|
||||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||||
|
@ -88,6 +89,10 @@ class _ArrayLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DummyConsole implements Console {
|
||||||
|
log(message) {}
|
||||||
|
}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
var fakeDoc, el, el2, testProviders, lightDom;
|
var fakeDoc, el, el2, testProviders, lightDom;
|
||||||
|
|
||||||
|
@ -101,7 +106,8 @@ export function main() {
|
||||||
DOM.appendChild(fakeDoc.body, el2);
|
DOM.appendChild(fakeDoc.body, el2);
|
||||||
DOM.appendChild(el, lightDom);
|
DOM.appendChild(el, lightDom);
|
||||||
DOM.setText(lightDom, 'loading');
|
DOM.setText(lightDom, 'loading');
|
||||||
testProviders = [provide(DOCUMENT, {useValue: fakeDoc})];
|
testProviders =
|
||||||
|
[provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})];
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(disposePlatform);
|
afterEach(disposePlatform);
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ var NG_CORE = [
|
||||||
'EventEmitter.emit():js',
|
'EventEmitter.emit():js',
|
||||||
'OutputMetadata',
|
'OutputMetadata',
|
||||||
'OutputMetadata.bindingPropertyName',
|
'OutputMetadata.bindingPropertyName',
|
||||||
'enableDevMode():js',
|
'enableProdMode():js',
|
||||||
'ExpressionChangedAfterItHasBeenCheckedException',
|
'ExpressionChangedAfterItHasBeenCheckedException',
|
||||||
'ExpressionChangedAfterItHasBeenCheckedException.message',
|
'ExpressionChangedAfterItHasBeenCheckedException.message',
|
||||||
'ExpressionChangedAfterItHasBeenCheckedException.stackTrace',
|
'ExpressionChangedAfterItHasBeenCheckedException.stackTrace',
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {
|
||||||
import {bootstrap} from 'angular2/platform/browser';
|
import {bootstrap} from 'angular2/platform/browser';
|
||||||
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
||||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||||
|
import {Console} from 'angular2/src/core/console';
|
||||||
import {provide, ViewChild, AfterViewInit} from 'angular2/core';
|
import {provide, ViewChild, AfterViewInit} from 'angular2/core';
|
||||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||||
import {RouteConfig, Route, Redirect, AuxRoute} from 'angular2/src/router/route_config_decorator';
|
import {RouteConfig, Route, Redirect, AuxRoute} from 'angular2/src/router/route_config_decorator';
|
||||||
|
@ -36,6 +37,10 @@ import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
|
||||||
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
||||||
import {MockApplicationRef} from 'angular2/src/mock/mock_application_ref';
|
import {MockApplicationRef} from 'angular2/src/mock/mock_application_ref';
|
||||||
|
|
||||||
|
class DummyConsole implements Console {
|
||||||
|
log(message) {}
|
||||||
|
}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('router bootstrap', () => {
|
describe('router bootstrap', () => {
|
||||||
beforeEachProviders(() => [
|
beforeEachProviders(() => [
|
||||||
|
@ -56,7 +61,8 @@ export function main() {
|
||||||
ROUTER_PROVIDERS,
|
ROUTER_PROVIDERS,
|
||||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||||
provide(DOCUMENT, {useValue: fakeDoc})
|
provide(DOCUMENT, {useValue: fakeDoc}),
|
||||||
|
provide(Console, {useClass: DummyConsole})
|
||||||
])
|
])
|
||||||
.then((applicationRef) => {
|
.then((applicationRef) => {
|
||||||
var router = applicationRef.hostComponent.router;
|
var router = applicationRef.hostComponent.router;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
import {bootstrap} from 'angular2/platform/browser';
|
import {bootstrap} from 'angular2/platform/browser';
|
||||||
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
||||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||||
|
import {Console} from 'angular2/src/core/console';
|
||||||
import {provide} from 'angular2/core';
|
import {provide} from 'angular2/core';
|
||||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||||
import {Type, IS_DART} from 'angular2/src/facade/lang';
|
import {Type, IS_DART} from 'angular2/src/facade/lang';
|
||||||
|
@ -38,6 +39,10 @@ class _ArrayLogger {
|
||||||
logGroupEnd(){};
|
logGroupEnd(){};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DummyConsole implements Console {
|
||||||
|
log(message) {}
|
||||||
|
}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('RouteConfig with POJO arguments', () => {
|
describe('RouteConfig with POJO arguments', () => {
|
||||||
var fakeDoc, el, testBindings;
|
var fakeDoc, el, testBindings;
|
||||||
|
@ -51,7 +56,8 @@ export function main() {
|
||||||
ROUTER_PROVIDERS,
|
ROUTER_PROVIDERS,
|
||||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||||
provide(DOCUMENT, {useValue: fakeDoc}),
|
provide(DOCUMENT, {useValue: fakeDoc}),
|
||||||
provide(ExceptionHandler, {useValue: exceptionHandler})
|
provide(ExceptionHandler, {useValue: exceptionHandler}),
|
||||||
|
provide(Console, {useClass: DummyConsole})
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ System.config({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.angularDevMode = true;
|
|
||||||
|
|
||||||
// Import all the specs, execute their `main()` method and kick off Karma (Jasmine).
|
// Import all the specs, execute their `main()` method and kick off Karma (Jasmine).
|
||||||
System.import('angular2/src/platform/browser/browser_adapter').then(function(browser_adapter) {
|
System.import('angular2/src/platform/browser/browser_adapter').then(function(browser_adapter) {
|
||||||
browser_adapter.BrowserDomAdapter.makeCurrent();
|
browser_adapter.BrowserDomAdapter.makeCurrent();
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
<script src="/bundle/router.dev.js"></script>
|
<script src="/bundle/router.dev.js"></script>
|
||||||
<script src="/rxjs/bundles/Rx.js"></script>
|
<script src="/rxjs/bundles/Rx.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.angularDevMode = true;
|
|
||||||
var filename = '@@PATH/@@FILENAME';
|
var filename = '@@PATH/@@FILENAME';
|
||||||
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
|
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
self.angularDevMode = true;
|
|
||||||
importScripts("es6-shim.js", "zone-microtask.js", "long-stack-trace-zone.js", "system.src.js",
|
importScripts("es6-shim.js", "zone-microtask.js", "long-stack-trace-zone.js", "system.src.js",
|
||||||
"Reflect.js");
|
"Reflect.js");
|
||||||
|
|
|
@ -6,8 +6,6 @@ var path = require('path');
|
||||||
require('es6-shim/es6-shim.js');
|
require('es6-shim/es6-shim.js');
|
||||||
require('reflect-metadata/Reflect');
|
require('reflect-metadata/Reflect');
|
||||||
|
|
||||||
global.angularDevMode = true;
|
|
||||||
|
|
||||||
var jrunner = new JasmineRunner();
|
var jrunner = new JasmineRunner();
|
||||||
|
|
||||||
// Tun on full stack traces in errors to help debugging
|
// Tun on full stack traces in errors to help debugging
|
||||||
|
|
Loading…
Reference in New Issue