File tree Expand file tree Collapse file tree 9 files changed +53
-1
lines changed
examples/core/ts/dev_mode Expand file tree Collapse file tree 9 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -20,3 +20,4 @@ export * from './src/common/forms';
2020export * from './src/core/debug' ;
2121export * from './src/core/change_detection' ;
2222export * from './src/core/ambient' ;
23+ export * from './src/core/dev_mode' ;
Original file line number Diff line number Diff line change 1+ // #docregion enableDevMode
2+ import { bootstrap , enableDevMode } from 'angular2/core' ;
3+ import { MyComponent } from 'my_component' ;
4+
5+ enableDevMode ( ) ;
6+ bootstrap ( MyComponent ) ;
7+ // #enddocregion
Original file line number Diff line number Diff line change 1+ import { Component } from 'angular2/core' ;
2+
3+ @Component ( { selector : 'my-component' , template : '<h1>My Component</h1>' } )
4+ export class MyComponent {
5+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ interface BrowserNodeGlobal {
2424 zone : Zone ;
2525 getAngularTestability : Function ;
2626 getAllAngularTestabilities : Function ;
27+ angularDevMode : boolean ;
2728 setTimeout : Function ;
2829 clearTimeout : Function ;
2930 setInterval : Function ;
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ import {Compiler_} from "./linker/compiler";
4848import { wtfLeave , wtfCreateScope , WtfScopeFn } from './profile/profile' ;
4949import { ChangeDetectorRef } from 'angular2/src/core/change_detection/change_detector_ref' ;
5050import { AMBIENT_DIRECTIVES , AMBIENT_PIPES } from "angular2/src/core/ambient" ;
51+ import { lockDevMode } from 'angular2/src/core/facade/lang' ;
5152import { COMMON_DIRECTIVES , COMMON_PIPES } from "angular2/common" ;
5253
5354/**
@@ -126,6 +127,7 @@ var _platform: PlatformRef;
126127
127128export function platformCommon ( providers ?: Array < Type | Provider | any [ ] > ,
128129 initializer ?: ( ) => void ) : PlatformRef {
130+ lockDevMode ( ) ;
129131 if ( isPresent ( _platform ) ) {
130132 if ( isBlank ( providers ) ) {
131133 return _platform ;
Original file line number Diff line number Diff line change 1+ // Dart development mode is determined by checked mode.
Original file line number Diff line number Diff line change 1+ export { enableDevMode } from 'angular2/src/core/facade/lang' ;
Original file line number Diff line number Diff line change @@ -241,6 +241,14 @@ bool isJsObject(o) {
241241 return false ;
242242}
243243
244+ void lockDevMode () {
245+ // lockDevMode() has no effect in Dart.
246+ }
247+
248+ void enableDevMode () {
249+ // enableDevMode() has no effect in Dart.
250+ }
251+
244252bool assertionsEnabled () {
245253 var k = false ;
246254 assert ((k = true ));
Original file line number Diff line number Diff line change @@ -39,8 +39,34 @@ export function getTypeNameForDebugging(type: Type): string {
3939export var Math = _global . Math ;
4040export var Date = _global . Date ;
4141
42+ var _devMode : boolean = ! ! _global . angularDevMode ;
43+ var _devModeLocked : boolean = false ;
44+
45+ export function lockDevMode ( ) {
46+ _devModeLocked = true ;
47+ }
48+
49+ /**
50+ * Enable Angular's development mode, which turns on assertions and other
51+ * checks within the framework.
52+ *
53+ * One important assertion this enables verifies that a change detection pass
54+ * does not result in additional changes to any bindings (also known as
55+ * unidirectional data flow).
56+ *
57+ * {@example core/ts/dev_mode/dev_mode_example.ts region='enableDevMode'}
58+ */
59+ export function enableDevMode ( ) {
60+ // TODO(alxhub): Refactor out of facade/lang as per issue #5157.
61+ if ( _devModeLocked ) {
62+ // Cannot use BaseException as that ends up importing from facade/lang.
63+ throw 'Cannot enable dev mode after platform setup.' ;
64+ }
65+ _devMode = true ;
66+ }
67+
4268export function assertionsEnabled ( ) : boolean {
43- return false ;
69+ return _devMode ;
4470}
4571
4672// TODO: remove calls to assert in production environment
You can’t perform that action at this time.
0 commit comments