fix(core): Provide setDevMode() to enable/disable development mode in Javascript.
This commit is contained in:
parent
7343ef04ae
commit
4bb9c46cf1
|
@ -20,3 +20,4 @@ export * from './src/common/forms';
|
|||
export * from './src/core/debug';
|
||||
export * from './src/core/change_detection';
|
||||
export * from './src/core/ambient';
|
||||
export * from './src/core/dev_mode';
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// #docregion enableDevMode
|
||||
import {bootstrap, enableDevMode} from 'angular2/core';
|
||||
import {MyComponent} from 'my_component';
|
||||
|
||||
enableDevMode();
|
||||
bootstrap(MyComponent);
|
||||
// #enddocregion
|
|
@ -0,0 +1,5 @@
|
|||
import {Component} from 'angular2/core';
|
||||
|
||||
@Component({selector: 'my-component', template: '<h1>My Component</h1>'})
|
||||
export class MyComponent {
|
||||
}
|
|
@ -24,6 +24,7 @@ interface BrowserNodeGlobal {
|
|||
zone: Zone;
|
||||
getAngularTestability: Function;
|
||||
getAllAngularTestabilities: Function;
|
||||
angularDevMode: boolean;
|
||||
setTimeout: Function;
|
||||
clearTimeout: Function;
|
||||
setInterval: Function;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
// Dart development mode is determined by checked mode.
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue