import {Injectable} from 'angular2/di';
import {ChangeDetector} from 'angular2/change_detection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {isPresent} from 'angular2/src/facade/lang';

/**
 * @exportedAs angular2/change_detection
 */
@Injectable()
export class LifeCycle {
  _errorHandler;
  _changeDetector:ChangeDetector;
  _enforceNoNewChanges:boolean;

  constructor(exceptionHandler:ExceptionHandler, changeDetector:ChangeDetector = null, enforceNoNewChanges:boolean = false) {
    this._errorHandler = (exception, stackTrace) => {
      exceptionHandler.call(exception, stackTrace);
      throw exception;
    };
    this._changeDetector = changeDetector; // may be null when instantiated from application bootstrap
    this._enforceNoNewChanges = enforceNoNewChanges;
  }

  registerWith(zone:VmTurnZone, changeDetector:ChangeDetector = null) {
    if (isPresent(changeDetector)) {
      this._changeDetector=changeDetector;
    }

    zone.initCallbacks({
      onErrorHandler: this._errorHandler,
      onTurnDone: () => this.tick()
    });
  }

  tick() {
    this._changeDetector.detectChanges();
    if (this._enforceNoNewChanges) {
      this._changeDetector.checkNoChanges();
    }
  }
}

@@ -282,16 +282,781 @@
 ';%0A%0A/**%0A
+ * Provides access to explicitly trigger change detection in an application.%0A *%0A * By default, %5BZone%5D triggers change detection in Angular on each virtual machine (VM) turn. When testing, or in some%0A * limited application use cases, a developer can also trigger change detection with the %60lifecycle.tick()%60 method.%0A *%0A * Each Angular application has a single %60LifeCycle%60 instance.%0A *%0A * # Example%0A *%0A * This is a contrived example, since the bootstrap automatically runs inside of the %5BZone%5D, which invokes%0A * %60lifecycle.tick()%60 on your behalf.%0A *%0A * %60%60%60javascript%0A * bootstrap(MyApp).then((ref:ComponentRef) =%3E %7B%0A *   var lifeCycle = ref.injector.get(LifeCycle);%0A *   var myApp = ref.instance;%0A *%0A *   ref.doSomething();%0A *   lifecycle.tick();%0A * %7D);%0A * %60%60%60%0A *%0A *%0A
  * @expo
@@ -1913,16 +1913,594 @@
 );%0A  %7D%0A%0A
+  /**%0A   *  Invoke this method to explicitly process change detection and its side-effects.%0A   *%0A   *  In development mode, %60tick()%60 also performs a second change detection cycle to ensure that no further%0A   *  changes are detected. If additional changes are picked up during this second cycle, bindings in the app have%0A   *  side-effects that cannot be resolved in a single change detection pass. In this case, Angular throws an error,%0A   *  since an Angular application can only have one change detection pass during which all change detection must%0A   *  complete.%0A   *%0A   */%0A
   tick()

document LifeCycle