diff --git a/modules/angular2/core.dart b/modules/angular2/core.dart index 187285742e..2e43211bd5 100644 --- a/modules/angular2/core.dart +++ b/modules/angular2/core.dart @@ -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; diff --git a/modules/angular2/core.ts b/modules/angular2/core.ts index 25d31ebb2e..08f3d19d54 100644 --- a/modules/angular2/core.ts +++ b/modules/angular2/core.ts @@ -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, diff --git a/modules/angular2/examples/core/ts/dev_mode/my_component.ts b/modules/angular2/examples/core/ts/prod_mode/my_component.ts similarity index 100% rename from modules/angular2/examples/core/ts/dev_mode/my_component.ts rename to modules/angular2/examples/core/ts/prod_mode/my_component.ts diff --git a/modules/angular2/examples/core/ts/dev_mode/dev_mode_example.ts b/modules/angular2/examples/core/ts/prod_mode/prod_mode_example.ts similarity index 58% rename from modules/angular2/examples/core/ts/dev_mode/dev_mode_example.ts rename to modules/angular2/examples/core/ts/prod_mode/prod_mode_example.ts index 0e973b98fd..76c3e15f4a 100644 --- a/modules/angular2/examples/core/ts/dev_mode/dev_mode_example.ts +++ b/modules/angular2/examples/core/ts/prod_mode/prod_mode_example.ts @@ -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 diff --git a/modules/angular2/manual_typings/globals-es6.d.ts b/modules/angular2/manual_typings/globals-es6.d.ts index 43d437ad64..b1292515c2 100644 --- a/modules/angular2/manual_typings/globals-es6.d.ts +++ b/modules/angular2/manual_typings/globals-es6.d.ts @@ -30,7 +30,6 @@ interface BrowserNodeGlobal { zone: Zone; getAngularTestability: Function; getAllAngularTestabilities: Function; - angularDevMode: boolean; setTimeout: Function; clearTimeout: Function; setInterval: Function; diff --git a/modules/angular2/src/core/application_ref.ts b/modules/angular2/src/core/application_ref.ts index bb01360f8a..426c56853f 100644 --- a/modules/angular2/src/core/application_ref.ts +++ b/modules/angular2/src/core/application_ref.ts @@ -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): 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 */ diff --git a/modules/angular2/src/core/console.ts b/modules/angular2/src/core/console.ts new file mode 100644 index 0000000000..dcd96fcce0 --- /dev/null +++ b/modules/angular2/src/core/console.ts @@ -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); } +} \ No newline at end of file diff --git a/modules/angular2/src/core/dev_mode.ts b/modules/angular2/src/core/dev_mode.ts deleted file mode 100644 index 925ced89b6..0000000000 --- a/modules/angular2/src/core/dev_mode.ts +++ /dev/null @@ -1 +0,0 @@ -export {enableDevMode} from 'angular2/src/facade/lang'; \ No newline at end of file diff --git a/modules/angular2/src/core/platform_common_providers.ts b/modules/angular2/src/core/platform_common_providers.ts index 14a84c1603..491b30e5b3 100644 --- a/modules/angular2/src/core/platform_common_providers.ts +++ b/modules/angular2/src/core/platform_common_providers.ts @@ -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 = - CONST_EXPR([new Provider(Reflector, {useFactory: _reflector, deps: []}), TestabilityRegistry]); +export const PLATFORM_COMMON_PROVIDERS: Array = CONST_EXPR( + [new Provider(Reflector, {useFactory: _reflector, deps: []}), TestabilityRegistry, Console]); diff --git a/modules/angular2/src/core/prod_mode.ts b/modules/angular2/src/core/prod_mode.ts new file mode 100644 index 0000000000..e44014dae6 --- /dev/null +++ b/modules/angular2/src/core/prod_mode.ts @@ -0,0 +1 @@ +export {enableProdMode} from 'angular2/src/facade/lang'; \ No newline at end of file diff --git a/modules/angular2/src/facade/lang.dart b/modules/angular2/src/facade/lang.dart index 26ed8ec7de..bebddc051d 100644 --- a/modules/angular2/src/facade/lang.dart +++ b/modules/angular2/src/facade/lang.dart @@ -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)); diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index 4c0042a984..3d741d1dc1 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -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 { diff --git a/modules/angular2/test/platform/browser/bootstrap_spec.ts b/modules/angular2/test/platform/browser/bootstrap_spec.ts index 1b6b1ce529..8b4fa34455 100644 --- a/modules/angular2/test/platform/browser/bootstrap_spec.ts +++ b/modules/angular2/test/platform/browser/bootstrap_spec.ts @@ -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); diff --git a/modules/angular2/test/public_api_spec.ts b/modules/angular2/test/public_api_spec.ts index 71fe8210ba..0943936538 100644 --- a/modules/angular2/test/public_api_spec.ts +++ b/modules/angular2/test/public_api_spec.ts @@ -1010,7 +1010,7 @@ var NG_CORE = [ 'EventEmitter.emit():js', 'OutputMetadata', 'OutputMetadata.bindingPropertyName', - 'enableDevMode():js', + 'enableProdMode():js', 'ExpressionChangedAfterItHasBeenCheckedException', 'ExpressionChangedAfterItHasBeenCheckedException.message', 'ExpressionChangedAfterItHasBeenCheckedException.stackTrace', diff --git a/modules/angular2/test/router/integration/bootstrap_spec.ts b/modules/angular2/test/router/integration/bootstrap_spec.ts index 362a82368a..45d75349f2 100644 --- a/modules/angular2/test/router/integration/bootstrap_spec.ts +++ b/modules/angular2/test/router/integration/bootstrap_spec.ts @@ -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; diff --git a/modules/angular2/test/router/route_config_spec.ts b/modules/angular2/test/router/route_config_spec.ts index c3040ef7fd..cfc97429b2 100644 --- a/modules/angular2/test/router/route_config_spec.ts +++ b/modules/angular2/test/router/route_config_spec.ts @@ -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}) ]; }); diff --git a/test-main.js b/test-main.js index d0d01a6131..0fa487d93f 100644 --- a/test-main.js +++ b/test-main.js @@ -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(); diff --git a/tools/broccoli/html-replace/SCRIPTS.html b/tools/broccoli/html-replace/SCRIPTS.html index 1d69764669..6f7bea55fb 100644 --- a/tools/broccoli/html-replace/SCRIPTS.html +++ b/tools/broccoli/html-replace/SCRIPTS.html @@ -22,7 +22,6 @@ diff --git a/tools/broccoli/js-replace/SCRIPTS.js b/tools/broccoli/js-replace/SCRIPTS.js index feb581a9e7..7ef18d10ad 100644 --- a/tools/broccoli/js-replace/SCRIPTS.js +++ b/tools/broccoli/js-replace/SCRIPTS.js @@ -1,3 +1,2 @@ -self.angularDevMode = true; importScripts("es6-shim.js", "zone-microtask.js", "long-stack-trace-zone.js", "system.src.js", "Reflect.js"); diff --git a/tools/cjs-jasmine/index.js b/tools/cjs-jasmine/index.js index 10fc759c0c..0e97d7fa61 100644 --- a/tools/cjs-jasmine/index.js +++ b/tools/cjs-jasmine/index.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