Skip to content

Commit

Permalink
feat(core): implement enableProdMode functionality (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Apr 18, 2016
1 parent 361f509 commit 59cd7d2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export {
} from './src/core/directives';
export { Pipe, PipeTransform } from './src/core/pipes';
export * from './src/core/linker';
export * from './src/core/change_detection'
export * from './src/core/change_detection';
export { enableProdMode } from './src/facade/lang';
39 changes: 38 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Angular 1 bootstrap:
`ng-metadata/platform`
- [bootstrap](#bootstrap)

`ng-metadata/core`
- [enableProdMode](#enableprodmode)

Angular 1 container registration helper Methods:

`ng-metadata/core`
`ng-metadata/core`
- [provide](#provide)
- [getInjectableName](#getinjectablename)
- [forwardRef](#forwardref)
Expand Down Expand Up @@ -110,6 +113,40 @@ returns `undefined`
`angular.bootstrap` is called on the page element that matches the element parameter or by default on `document`.
This action is invoked inside `angular.element( document ).ready` function.


## enableProdMode

> **module:** `ng-metadata/core`
Disable Angular's development mode, which turns off debug data information and optimizes $http calls execution.

Behind the scenes we are setting :
- [`$compileProvider.debugInfoEnabled(false);`](https://docs.angularjs.org/guide/production#disabling-debug-data)
- [`$httpProvider.useApplyAsync(true)`](https://docs.angularjs.org/api/ng/provider/$httpProvider#useApplyAsync)


*example:*
```typescript
// app.ts
export const AppModule = angular
.module('myApp',[])
.name;

// main.ts
import {bootstrap} from 'ng-metadata/platform';
import {enableProdMode} from 'ng-metadata/core';
import {AppModule} from './app';

enableProdMode();

bootstrap( AppModule );
```

###### Parameters
none

returns `undefined`

---

**Angular 1 container registration helper Methods:**
Expand Down
5 changes: 4 additions & 1 deletion playground/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//main entry point
import {bootstrap} from 'ng-metadata/platform';
import {enableProdMode} from 'ng-metadata/core';
import {AppModule} from './app';

bootstrap(AppModule);
// enableProdMode();

bootstrap( AppModule );
10 changes: 10 additions & 0 deletions playground/ng-metadata.legacy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,16 @@ declare module ngMetadataCore{
isFirstChange(): boolean
}});
}

/**
* Disable Angular's development mode, which turns off assertions and other
* checks within the framework.
*
* 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).
*/
export function enableProdMode(): void;
}

declare module ngMetadataCommon {
Expand Down
18 changes: 18 additions & 0 deletions src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ const reIsUint = /^\d+$/;
*/
const MAX_SAFE_INTEGER = 9007199254740991;


let _devMode: boolean = true;
/**
* Disable Angular's development mode, which turns off assertions and other
* checks within the framework.
*
* 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).
*/
export function enableProdMode() {
_devMode = false;
}

export function assertionsEnabled(): boolean {
return _devMode;
}

export function CONST(): ClassDecorator & PropertyDecorator {
return ( target ) => target;
}
Expand Down
15 changes: 15 additions & 0 deletions src/platform/browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertionsEnabled } from '../facade/lang';
export type AppRoot = string | Element | Document;

/**
Expand All @@ -14,6 +15,14 @@ export function bootstrap(
}={}
) {

if ( assertionsEnabled() ) {
console.info(
'Angular is running in the development mode. Call enableProdMode() to enable the production mode.'
);
} else {
angular.module( ngModuleName ).config( prodModeConfig );
}

const appRoot = _getAppRoot( element );

angular.element( document ).ready( ()=> {
Expand All @@ -32,3 +41,9 @@ function _getAppRoot( element: AppRoot ): Element {
return element as Element;

}

prodModeConfig.$inject = [ '$compileProvider', '$httpProvider' ];
function prodModeConfig( $compileProvider: ng.ICompileProvider, $httpProvider: ng.IHttpProvider ) {
$compileProvider.debugInfoEnabled( false );
$httpProvider.useApplyAsync( true );
}

0 comments on commit 59cd7d2

Please sign in to comment.