feat(core): added afterContentInit, afterViewInit, and afterViewChecked hooks

Closes #3897
This commit is contained in:
vsavkin
2015-08-28 18:11:04 -07:00
committed by Victor Savkin
parent f93cd9ced7
commit d49bc438e8
36 changed files with 974 additions and 253 deletions

View File

@ -26,7 +26,10 @@ main() {
callOnChanges: true,
callDoCheck: true,
callOnInit: true,
callAfterContentInit: true,
callAfterContentChecked: true,
callAfterViewInit: true,
callAfterViewChecked: true,
events: ["onFoo", "onBar"],
changeDetection: ChangeDetectionStrategy.CheckOnce);
var map = directiveMetadataToMap(someComponent);
@ -46,7 +49,10 @@ main() {
expect(map["callDoCheck"]).toEqual(true);
expect(map["callOnChanges"]).toEqual(true);
expect(map["callOnInit"]).toEqual(true);
expect(map["callAfterContentInit"]).toEqual(true);
expect(map["callAfterContentChecked"]).toEqual(true);
expect(map["callAfterViewInit"]).toEqual(true);
expect(map["callAfterViewChecked"]).toEqual(true);
expect(map["exportAs"]).toEqual("aaa");
expect(map["events"]).toEqual(["onFoo", "onBar"]);
expect(map["changeDetection"]).toEqual(ChangeDetectionStrategy.CheckOnce.index);
@ -67,7 +73,10 @@ main() {
["callDoCheck", true],
["callOnInit", true],
["callOnChanges", true],
["callAfterContentInit", true],
["callAfterContentChecked", true],
["callAfterViewInit", true],
["callAfterViewChecked", true],
["events", ["onFoo", "onBar"]],
["changeDetection", ChangeDetectionStrategy.CheckOnce.index]
]);
@ -89,7 +98,10 @@ main() {
expect(meta.callDoCheck).toEqual(true);
expect(meta.callOnInit).toEqual(true);
expect(meta.callOnChanges).toEqual(true);
expect(meta.callAfterContentInit).toEqual(true);
expect(meta.callAfterContentChecked).toEqual(true);
expect(meta.callAfterViewInit).toEqual(true);
expect(meta.callAfterViewChecked).toEqual(true);
expect(meta.events).toEqual(["onFoo", "onBar"]);
expect(meta.changeDetection).toEqual(ChangeDetectionStrategy.CheckOnce);
});

View File

@ -106,7 +106,10 @@ void allTests() {
expect(metadata.callOnChanges).toBe(true);
expect(metadata.callDoCheck).toBe(true);
expect(metadata.callOnInit).toBe(true);
expect(metadata.callAfterContentInit).toBe(true);
expect(metadata.callAfterContentChecked).toBe(true);
expect(metadata.callAfterViewInit).toBe(true);
expect(metadata.callAfterViewChecked).toBe(true);
});
it('should parse events.', () async {

View File

@ -17,7 +17,10 @@ void initReflector(reflector) {
LifecycleEvent.OnDestroy,
LifecycleEvent.OnInit,
LifecycleEvent.DoCheck,
LifecycleEvent.AfterContentChecked
LifecycleEvent.AfterContentInit,
LifecycleEvent.AfterContentChecked,
LifecycleEvent.AfterViewInit,
LifecycleEvent.AfterViewChecked
])
], const [
const []

View File

@ -52,6 +52,17 @@ void initReflector() {
const [],
() => new OnInitSoupComponent(),
const [OnInit]))
..registerType(
AfterContentInitSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.AfterContentInit])
],
const [],
() => new AfterContentInitSoupComponent(),
const [AfterContentInit]))
..registerType(
AfterContentCheckedSoupComponent,
new _ngRef.ReflectionInfo(
@ -62,5 +73,27 @@ void initReflector() {
],
const [],
() => new AfterContentCheckedSoupComponent(),
const [AfterContentChecked]));
const [AfterContentChecked]))
..registerType(
AfterViewInitSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.AfterViewInit])
],
const [],
() => new AfterViewInitSoupComponent(),
const [AfterViewInit]))
..registerType(
AfterViewCheckedSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.AfterViewChecked])
],
const [],
() => new AfterViewCheckedSoupComponent(),
const [AfterViewChecked]));
}

View File

@ -14,5 +14,14 @@ class OnCheckSoupComponent implements DoCheck {}
@Component(selector: '[soup]')
class OnInitSoupComponent implements OnInit {}
@Component(selector: '[soup]')
class AfterContentInitSoupComponent implements AfterContentInit {}
@Component(selector: '[soup]')
class AfterContentCheckedSoupComponent implements AfterContentChecked {}
@Component(selector: '[soup]')
class AfterViewInitSoupComponent implements AfterViewInit {}
@Component(selector: '[soup]')
class AfterViewCheckedSoupComponent implements AfterViewChecked {}

View File

@ -16,7 +16,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1

View File

@ -66,8 +66,6 @@ class _MyComponent_ChangeDetector0
changes = null;
isChanged = false;
this.alreadyChecked = true;
}
void checkNoChanges() {

View File

@ -16,7 +16,10 @@
"callDoCheck": null,
"callOnInit": null,
"callOnChanges": null,
"callAfterContentInit": null,
"callAfterContentChecked": null,
"callAfterViewInit": null,
"callAfterViewChecked": null,
"events": ["dependencyEventName"],
"changeDetection": null,
"version": 1
@ -39,7 +42,10 @@
"callDoCheck": null,
"callOnInit": null,
"callOnChanges": null,
"callAfterContentInit": null,
"callAfterContentChecked": null,
"callAfterViewInit": null,
"callAfterViewChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -62,7 +68,10 @@
"callDoCheck": null,
"callOnInit": null,
"callOnChanges": null,
"callAfterContentInit": null,
"callAfterContentChecked": null,
"callAfterViewInit": null,
"callAfterViewChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -85,7 +94,10 @@
"callDoCheck": true,
"callOnInit": null,
"callOnChanges": null,
"callAfterContentInit": null,
"callAfterContentChecked": null,
"callAfterViewInit": null,
"callAfterViewChecked": null,
"events": null,
"changeDetection": null,
"version": 1

View File

@ -16,7 +16,10 @@
"callDoCheck": null,
"callOnInit": null,
"callOnChanges": null,
"callAfterContentInit": null,
"callAfterContentChecked": null,
"callAfterViewInit": null,
"callAfterViewChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -39,7 +42,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -62,7 +68,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": ["eventName"],
"changeDetection": null,
"version": 1
@ -85,7 +94,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -108,7 +120,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -131,7 +146,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -154,7 +172,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -177,7 +198,10 @@
"callDoCheck": false,
"callOnInit": false,
"callOnChanges": false,
"callAfterContentInit": false,
"callAfterContentChecked": false,
"callAfterViewInit": false,
"callAfterViewChecked": false,
"events": [],
"changeDetection": null,
"version": 1