fix(core): Provide setDevMode() to enable/disable development mode in Javascript.
This commit is contained in:
@ -48,6 +48,7 @@ import {Compiler_} from "./linker/compiler";
|
||||
import {wtfLeave, wtfCreateScope, WtfScopeFn} from './profile/profile';
|
||||
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref';
|
||||
import {AMBIENT_DIRECTIVES, AMBIENT_PIPES} from "angular2/src/core/ambient";
|
||||
import {lockDevMode} from 'angular2/src/core/facade/lang';
|
||||
import {COMMON_DIRECTIVES, COMMON_PIPES} from "angular2/common";
|
||||
|
||||
/**
|
||||
@ -126,6 +127,7 @@ var _platform: PlatformRef;
|
||||
|
||||
export function platformCommon(providers?: Array<Type | Provider | any[]>,
|
||||
initializer?: () => void): PlatformRef {
|
||||
lockDevMode();
|
||||
if (isPresent(_platform)) {
|
||||
if (isBlank(providers)) {
|
||||
return _platform;
|
||||
|
1
modules/angular2/src/core/dev_mode.dart
Normal file
1
modules/angular2/src/core/dev_mode.dart
Normal file
@ -0,0 +1 @@
|
||||
// Dart development mode is determined by checked mode.
|
1
modules/angular2/src/core/dev_mode.ts
Normal file
1
modules/angular2/src/core/dev_mode.ts
Normal file
@ -0,0 +1 @@
|
||||
export {enableDevMode} from 'angular2/src/core/facade/lang';
|
@ -241,6 +241,14 @@ bool isJsObject(o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void lockDevMode() {
|
||||
// lockDevMode() has no effect in Dart.
|
||||
}
|
||||
|
||||
void enableDevMode() {
|
||||
// enableDevMode() has no effect in Dart.
|
||||
}
|
||||
|
||||
bool assertionsEnabled() {
|
||||
var k = false;
|
||||
assert((k = true));
|
||||
|
@ -39,8 +39,34 @@ 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;
|
||||
|
||||
export function lockDevMode() {
|
||||
_devModeLocked = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable Angular's development mode, which turns on assertions and other
|
||||
* checks within the framework.
|
||||
*
|
||||
* One important assertion this enables 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) {
|
||||
// Cannot use BaseException as that ends up importing from facade/lang.
|
||||
throw 'Cannot enable dev mode after platform setup.';
|
||||
}
|
||||
_devMode = true;
|
||||
}
|
||||
|
||||
export function assertionsEnabled(): boolean {
|
||||
return false;
|
||||
return _devMode;
|
||||
}
|
||||
|
||||
// TODO: remove calls to assert in production environment
|
||||
|
Reference in New Issue
Block a user