Skip to content

Commit

Permalink
feat(core): enable dev mode by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vsavkin committed Dec 15, 2015
1 parent de996ec commit 3dca9d5
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 40 deletions.
2 changes: 1 addition & 1 deletion modules/angular2/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion modules/angular2/manual_typings/globals-es6.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ interface BrowserNodeGlobal {
zone: Zone;
getAngularTestability: Function;
getAllAngularTestabilities: Function;
angularDevMode: boolean;
setTimeout: Function;
clearTimeout: Function;
setInterval: Function;
Expand Down
15 changes: 12 additions & 3 deletions modules/angular2/src/core/application_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions modules/angular2/src/core/console.ts
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion modules/angular2/src/core/dev_mode.ts

This file was deleted.

5 changes: 3 additions & 2 deletions modules/angular2/src/core/platform_common_providers.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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]);
1 change: 1 addition & 0 deletions modules/angular2/src/core/prod_mode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {enableProdMode} from 'angular2/src/facade/lang';
21 changes: 16 additions & 5 deletions modules/angular2/src/facade/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
23 changes: 10 additions & 13 deletions modules/angular2/src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion modules/angular2/test/platform/browser/bootstrap_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,6 +89,10 @@ class _ArrayLogger {
}


class DummyConsole implements Console {
log(message) {}
}

export function main() {
var fakeDoc, el, el2, testProviders, lightDom;

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ var NG_CORE = [
'EventEmitter.emit():js',
'OutputMetadata',
'OutputMetadata.bindingPropertyName',
'enableDevMode():js',
'enableProdMode():js',
'ExpressionChangedAfterItHasBeenCheckedException',
'ExpressionChangedAfterItHasBeenCheckedException.message',
'ExpressionChangedAfterItHasBeenCheckedException.stackTrace',
Expand Down
8 changes: 7 additions & 1 deletion modules/angular2/test/router/integration/bootstrap_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(() => [
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion modules/angular2/test/router/route_config_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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})
];
});

Expand Down
2 changes: 0 additions & 2 deletions test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion tools/broccoli/html-replace/SCRIPTS.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 0 additions & 1 deletion tools/broccoli/js-replace/SCRIPTS.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
self.angularDevMode = true;
importScripts("es6-shim.js", "zone-microtask.js", "long-stack-trace-zone.js", "system.src.js",
"Reflect.js");
2 changes: 0 additions & 2 deletions tools/cjs-jasmine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3dca9d5

Please sign in to comment.