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/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/facade/facade.dart';
|
||||
export './src/core/application_ref.dart' show platform, createNgZone, PlatformRef, ApplicationRef;
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
*/
|
||||
export * from './src/core/metadata';
|
||||
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/facade/facade';
|
||||
export {enableProdMode} from 'angular2/src/facade/lang';
|
||||
export {platform, createNgZone, PlatformRef, ApplicationRef} from './src/core/application_ref';
|
||||
export {
|
||||
APP_ID,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// #docregion enableDevMode
|
||||
import {enableDevMode} from 'angular2/core';
|
||||
// #docregion enableProdMode
|
||||
import {enableProdMode} from 'angular2/core';
|
||||
import {bootstrap} from 'angular2/bootstrap';
|
||||
import {MyComponent} from 'my_component';
|
||||
|
||||
enableDevMode();
|
||||
enableProdMode();
|
||||
bootstrap(MyComponent);
|
||||
// #enddocregion
|
|
@ -30,7 +30,6 @@ interface BrowserNodeGlobal {
|
|||
zone: Zone;
|
||||
getAngularTestability: Function;
|
||||
getAllAngularTestabilities: Function;
|
||||
angularDevMode: boolean;
|
||||
setTimeout: Function;
|
||||
clearTimeout: Function;
|
||||
setInterval: Function;
|
||||
|
|
|
@ -34,9 +34,10 @@ import {
|
|||
unimplemented
|
||||
} from 'angular2/src/facade/exceptions';
|
||||
import {internalView} from 'angular2/src/core/linker/view_ref';
|
||||
import {Console} from 'angular2/src/core/console';
|
||||
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
||||
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.
|
||||
|
@ -98,7 +99,7 @@ var _platformProviders: any[];
|
|||
* provides, Angular will throw an exception.
|
||||
*/
|
||||
export function platform(providers?: Array<Type | Provider | any[]>): PlatformRef {
|
||||
lockDevMode();
|
||||
lockMode();
|
||||
if (isPresent(_platform)) {
|
||||
if (ListWrapper.equals(_platformProviders, providers)) {
|
||||
return _platform;
|
||||
|
@ -425,7 +426,15 @@ export class ApplicationRef_ extends ApplicationRef {
|
|||
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 */
|
||||
|
|
|
@ -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 {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
|
||||
import {Console} from 'angular2/src/core/console';
|
||||
import {Reflector, reflector} from './reflection/reflection';
|
||||
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.
|
||||
*/
|
||||
export const PLATFORM_COMMON_PROVIDERS: Array<Type | Provider | any[]> =
|
||||
CONST_EXPR([new Provider(Reflector, {useFactory: _reflector, deps: []}), TestabilityRegistry]);
|
||||
export const PLATFORM_COMMON_PROVIDERS: Array<Type | Provider | any[]> = CONST_EXPR(
|
||||
[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;
|
||||
}
|
||||
|
||||
bool _forceDevMode = false;
|
||||
bool _devModeLocked = false;
|
||||
bool _forceDevMode = true;
|
||||
bool _modeLocked = false;
|
||||
|
||||
void lockDevMode() {
|
||||
_devModeLocked = true;
|
||||
void lockMode() {
|
||||
_modeLocked = true;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
void enableDevMode() {
|
||||
if (_forceDevMode) {
|
||||
return;
|
||||
}
|
||||
if (_devModeLocked) {
|
||||
if (_modeLocked) {
|
||||
throw new Exception("Cannot enable dev mode after platform setup.");
|
||||
}
|
||||
_forceDevMode = true;
|
||||
}
|
||||
|
||||
void enableProdMode() {
|
||||
if (_forceDevMode) {
|
||||
return;
|
||||
}
|
||||
if (_modeLocked) {
|
||||
throw new Exception("Cannot enable prod mode after platform setup.");
|
||||
}
|
||||
_forceDevMode = false;
|
||||
}
|
||||
|
||||
bool assertionsEnabled() {
|
||||
var k = false;
|
||||
assert((k = true));
|
||||
|
|
|
@ -43,30 +43,27 @@ export function getTypeNameForDebugging(type: Type): string {
|
|||
export var Math = _global.Math;
|
||||
export var Date = _global.Date;
|
||||
|
||||
var _devMode: boolean = !!_global.angularDevMode;
|
||||
var _devModeLocked: boolean = false;
|
||||
var _devMode: boolean = true;
|
||||
var _modeLocked: boolean = false;
|
||||
|
||||
export function lockDevMode() {
|
||||
_devModeLocked = true;
|
||||
export function lockMode() {
|
||||
_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.
|
||||
*
|
||||
* 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
|
||||
* unidirectional data flow).
|
||||
*
|
||||
* {@example core/ts/dev_mode/dev_mode_example.ts region='enableDevMode'}
|
||||
*/
|
||||
export function enableDevMode() {
|
||||
// TODO(alxhub): Refactor out of facade/lang as per issue #5157.
|
||||
if (_devModeLocked) {
|
||||
export function enableProdMode() {
|
||||
if (_modeLocked) {
|
||||
// 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 {
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
import {IS_DART, isPresent, stringify} from 'angular2/src/facade/lang';
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
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 {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
|
@ -88,6 +89,10 @@ class _ArrayLogger {
|
|||
}
|
||||
|
||||
|
||||
class DummyConsole implements Console {
|
||||
log(message) {}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
var fakeDoc, el, el2, testProviders, lightDom;
|
||||
|
||||
|
@ -101,7 +106,8 @@ export function main() {
|
|||
DOM.appendChild(fakeDoc.body, el2);
|
||||
DOM.appendChild(el, lightDom);
|
||||
DOM.setText(lightDom, 'loading');
|
||||
testProviders = [provide(DOCUMENT, {useValue: fakeDoc})];
|
||||
testProviders =
|
||||
[provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})];
|
||||
});
|
||||
|
||||
afterEach(disposePlatform);
|
||||
|
|
|
@ -1010,7 +1010,7 @@ var NG_CORE = [
|
|||
'EventEmitter.emit():js',
|
||||
'OutputMetadata',
|
||||
'OutputMetadata.bindingPropertyName',
|
||||
'enableDevMode():js',
|
||||
'enableProdMode():js',
|
||||
'ExpressionChangedAfterItHasBeenCheckedException',
|
||||
'ExpressionChangedAfterItHasBeenCheckedException.message',
|
||||
'ExpressionChangedAfterItHasBeenCheckedException.stackTrace',
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
import {Console} from 'angular2/src/core/console';
|
||||
import {provide, ViewChild, AfterViewInit} from 'angular2/core';
|
||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||
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 {MockApplicationRef} from 'angular2/src/mock/mock_application_ref';
|
||||
|
||||
class DummyConsole implements Console {
|
||||
log(message) {}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('router bootstrap', () => {
|
||||
beforeEachProviders(() => [
|
||||
|
@ -56,7 +61,8 @@ export function main() {
|
|||
ROUTER_PROVIDERS,
|
||||
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
|
||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||
provide(DOCUMENT, {useValue: fakeDoc})
|
||||
provide(DOCUMENT, {useValue: fakeDoc}),
|
||||
provide(Console, {useClass: DummyConsole})
|
||||
])
|
||||
.then((applicationRef) => {
|
||||
var router = applicationRef.hostComponent.router;
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {Component, Directive, View} from 'angular2/src/core/metadata';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
import {Console} from 'angular2/src/core/console';
|
||||
import {provide} from 'angular2/core';
|
||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||
import {Type, IS_DART} from 'angular2/src/facade/lang';
|
||||
|
@ -38,6 +39,10 @@ class _ArrayLogger {
|
|||
logGroupEnd(){};
|
||||
}
|
||||
|
||||
class DummyConsole implements Console {
|
||||
log(message) {}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('RouteConfig with POJO arguments', () => {
|
||||
var fakeDoc, el, testBindings;
|
||||
|
@ -51,7 +56,8 @@ export function main() {
|
|||
ROUTER_PROVIDERS,
|
||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||
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).
|
||||
System.import('angular2/src/platform/browser/browser_adapter').then(function(browser_adapter) {
|
||||
browser_adapter.BrowserDomAdapter.makeCurrent();
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
<script src="/bundle/router.dev.js"></script>
|
||||
<script src="/rxjs/bundles/Rx.js"></script>
|
||||
<script>
|
||||
window.angularDevMode = true;
|
||||
var filename = '@@PATH/@@FILENAME';
|
||||
System.import(filename).then(function(m) { m.main(); }, console.error.bind(console));
|
||||
</script>
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
self.angularDevMode = true;
|
||||
importScripts("es6-shim.js", "zone-microtask.js", "long-stack-trace-zone.js", "system.src.js",
|
||||
"Reflect.js");
|
||||
|
|
|
@ -6,8 +6,6 @@ var path = require('path');
|
|||
require('es6-shim/es6-shim.js');
|
||||
require('reflect-metadata/Reflect');
|
||||
|
||||
global.angularDevMode = true;
|
||||
|
||||
var jrunner = new JasmineRunner();
|
||||
|
||||
// Tun on full stack traces in errors to help debugging
|
||||
|
|
Loading…
Reference in New Issue