angular-cn/modules/angular2/src/mock/mock_application_ref.ts
Tobias Bosch 9092ac79d4 refactor(core): support non reflective bootstrap.
This changes Angular so that it can be used without reflection (assuming a codegen for injectors).

BREAKIKNG CHANGE:
- Drops `APP_COMPONENT` provider. Instead, inject
  `ApplicationRef` and read its `componentTypes` property.
- long form bootstrap has changed into the following:
  ```
  var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
  var appInjector =
    ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, appProviders], platform.injector);
  coreLoadAndBootstrap(appInjector, MyApp);
  ```
2016-04-20 11:34:11 -07:00

33 lines
1010 B
TypeScript

import {ApplicationRef} from 'angular2/src/core/application_ref';
import {Injectable} from 'angular2/src/core/di';
import {Type} from 'angular2/src/facade/lang';
import {ComponentRef, ComponentFactory} from 'angular2/src/core/linker/component_factory';
import {Injector} from 'angular2/src/core/di';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
/**
* A no-op implementation of {@link ApplicationRef}, useful for testing.
*/
@Injectable()
export class MockApplicationRef extends ApplicationRef {
registerBootstrapListener(listener: (ref: ComponentRef) => void): void {}
registerDisposeListener(dispose: () => void): void {}
bootstrap(componentFactory: ComponentFactory): ComponentRef { return null; }
get injector(): Injector { return null; };
get zone(): NgZone { return null; };
run(callback: Function): any { return null; }
waitForAsyncInitializers(): Promise<any> { return null; }
dispose(): void {}
tick(): void {}
get componentTypes(): Type[] { return null; };
}