refactor(core): Move LifeCycle functionality into ApplicationRef.
BREAKING CHANGE: Before: constructor(@Inject(LifeCycle) lifecycle) { lifecycle.tick(); } After: constructor(@Inject(ApplicationRef) appRef) { appRef.tick(); } Closes #5008
This commit is contained in:
30
modules/angular2/test/core/application_ref_spec.ts
Normal file
30
modules/angular2/test/core/application_ref_spec.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
el,
|
||||
AsyncTestCompleter,
|
||||
fakeAsync,
|
||||
tick,
|
||||
inject
|
||||
} from 'angular2/testing_internal';
|
||||
import {SpyChangeDetector} from './spies';
|
||||
import {ApplicationRef_} from "angular2/src/core/application_ref";
|
||||
import {ChangeDetectorRef_} from "angular2/src/core/change_detection/change_detector_ref";
|
||||
|
||||
export function main() {
|
||||
describe("ApplicationRef", () => {
|
||||
it("should throw when reentering tick", () => {
|
||||
var cd = <any>new SpyChangeDetector();
|
||||
var ref = new ApplicationRef_(null, null, null);
|
||||
ref.registerChangeDetector(new ChangeDetectorRef_(cd));
|
||||
cd.spy("detectChanges").andCallFake(() => ref.tick());
|
||||
expect(() => ref.tick()).toThrowError("ApplicationRef.tick is called recursively");
|
||||
});
|
||||
});
|
||||
}
|
@ -17,7 +17,7 @@ import {Component, Directive, View} from 'angular2/core';
|
||||
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
||||
import {DOCUMENT} from 'angular2/render';
|
||||
import {PromiseWrapper} from 'angular2/src/core/facade/async';
|
||||
import {provide, Inject, Injector, LifeCycle} from 'angular2/core';
|
||||
import {provide, Inject, Injector} from 'angular2/core';
|
||||
import {ExceptionHandler} from 'angular2/src/core/facade/exceptions';
|
||||
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||
import {IS_DART} from '../platform';
|
||||
@ -54,9 +54,9 @@ class HelloRootCmp3 {
|
||||
@Component({selector: 'hello-app'})
|
||||
@View({template: ''})
|
||||
class HelloRootCmp4 {
|
||||
lc;
|
||||
appRef;
|
||||
|
||||
constructor(@Inject(LifeCycle) lc) { this.lc = lc; }
|
||||
constructor(@Inject(ApplicationRef) appRef) { this.appRef = appRef; }
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app'})
|
||||
@ -179,7 +179,7 @@ export function main() {
|
||||
var refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.hostComponent.lc).toBe((<ComponentRef_>ref).injector.get(LifeCycle));
|
||||
expect(ref.hostComponent.appRef).toBe((<ComponentRef_>ref).injector.get(ApplicationRef));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
@ -1,29 +0,0 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
el,
|
||||
AsyncTestCompleter,
|
||||
fakeAsync,
|
||||
tick,
|
||||
inject
|
||||
} from 'angular2/testing_internal';
|
||||
import {SpyChangeDetector} from '../spies';
|
||||
import {LifeCycle_} from "angular2/src/core/life_cycle/life_cycle";
|
||||
|
||||
export function main() {
|
||||
describe("LifeCycle", () => {
|
||||
it("should throw when reentering tick", () => {
|
||||
var cd = <any>new SpyChangeDetector();
|
||||
var lc = new LifeCycle_(cd, false);
|
||||
|
||||
cd.spy("detectChanges").andCallFake(() => lc.tick());
|
||||
expect(() => lc.tick()).toThrowError("LifeCycle.tick is called recursively");
|
||||
});
|
||||
});
|
||||
}
|
@ -102,6 +102,7 @@ var NG_API = [
|
||||
'ApplicationRef.dispose()',
|
||||
'ApplicationRef.registerBootstrapListener()',
|
||||
'ApplicationRef.registerDisposeListener()',
|
||||
'ApplicationRef.tick()',
|
||||
*/
|
||||
'AsyncPipe',
|
||||
'AsyncPipe.onDestroy()',
|
||||
@ -610,12 +611,6 @@ var NG_API = [
|
||||
'KeyValueDiffers',
|
||||
'KeyValueDiffers.factories',
|
||||
'KeyValueDiffers.find()',
|
||||
'LifeCycle', // TODO: replace with ApplicationRef
|
||||
/*
|
||||
Abstract methods
|
||||
'LifeCycle.registerWith()',
|
||||
'LifeCycle.tick()',
|
||||
*/
|
||||
'LowerCasePipe',
|
||||
'LowerCasePipe.transform()',
|
||||
'NG_VALIDATORS',
|
||||
|
@ -1,11 +1,13 @@
|
||||
import 'package:angular2/testing_internal.dart' show SpyObject;
|
||||
import 'package:angular2/core.dart' show LifeCycle, Injector, bind;
|
||||
import 'package:angular2/core.dart' show Injector, bind;
|
||||
import 'package:angular2/src/core/application_ref.dart' show ApplicationRef;
|
||||
import 'package:angular2/src/core/linker/dynamic_component_loader.dart'
|
||||
show ComponentRef_;
|
||||
import 'dart:js';
|
||||
|
||||
@proxy
|
||||
class SpyLifeCycle extends SpyObject implements LifeCycle {
|
||||
class SpyApplicationRef extends SpyObject implements ApplicationRef {
|
||||
tick() {}
|
||||
noSuchMethod(m) => super.noSuchMethod(m);
|
||||
}
|
||||
|
||||
@ -15,7 +17,7 @@ class SpyComponentRef extends SpyObject implements ComponentRef_ {
|
||||
|
||||
SpyComponentRef() {
|
||||
this.injector =
|
||||
Injector.resolveAndCreate([bind(LifeCycle).toClass(SpyLifeCycle)]);
|
||||
Injector.resolveAndCreate([bind(ApplicationRef).toClass(SpyApplicationRef)]);
|
||||
}
|
||||
|
||||
noSuchMethod(m) => super.noSuchMethod(m);
|
||||
|
@ -1,13 +1,19 @@
|
||||
import {SpyObject} from 'angular2/testing_internal';
|
||||
import {LifeCycle, Injector, provide} from 'angular2/angular2';
|
||||
import {Injector, provide} from 'angular2/angular2';
|
||||
import {ComponentRef} from 'angular2/src/core/linker/dynamic_component_loader';
|
||||
import {global} from 'angular2/src/core/facade/lang';
|
||||
import {ApplicationRef, ApplicationRef_} from 'angular2/src/core/application_ref';
|
||||
|
||||
export class SpyApplicationRef extends SpyObject {
|
||||
constructor() { super(ApplicationRef_); }
|
||||
}
|
||||
|
||||
export class SpyComponentRef extends SpyObject {
|
||||
injector;
|
||||
constructor() {
|
||||
super();
|
||||
this.injector = Injector.resolveAndCreate([provide(LifeCycle, {useValue: {tick: () => {}}})]);
|
||||
this.injector =
|
||||
Injector.resolveAndCreate([provide(ApplicationRef, {useClass: SpyApplicationRef})]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user