perf(change_detection): do not generate onAllChangesDone when not needed
This commit is contained in:
parent
dd06a871b7
commit
adc27398fd
|
@ -135,7 +135,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
|
||||||
|
|
||||||
hydrated(): boolean { return this.context !== null; }
|
hydrated(): boolean { return this.context !== null; }
|
||||||
|
|
||||||
callOnAllChangesDone(): void {}
|
callOnAllChangesDone(): void { this.dispatcher.notifyOnAllChangesDone(); }
|
||||||
|
|
||||||
_detectChangesInLightDomChildren(throwOnChange: boolean): void {
|
_detectChangesInLightDomChildren(throwOnChange: boolean): void {
|
||||||
var c = this.lightDomChildren;
|
var c = this.lightDomChildren;
|
||||||
|
|
|
@ -57,9 +57,7 @@ export class ChangeDetectorJITGenerator {
|
||||||
|
|
||||||
${this._genCheckNoChanges()}
|
${this._genCheckNoChanges()}
|
||||||
|
|
||||||
${this._typeName}.prototype.callOnAllChangesDone = function() {
|
${this._maybeGenCallOnAllChangesDone()}
|
||||||
${this._genCallOnAllChangesDoneBody()}
|
|
||||||
}
|
|
||||||
|
|
||||||
${this._maybeGenHydrateDirectives()}
|
${this._maybeGenHydrateDirectives()}
|
||||||
|
|
||||||
|
@ -117,7 +115,7 @@ export class ChangeDetectorJITGenerator {
|
||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
_genCallOnAllChangesDoneBody(): string {
|
_maybeGenCallOnAllChangesDone(): string {
|
||||||
var notifications = [];
|
var notifications = [];
|
||||||
var dirs = this.directiveRecords;
|
var dirs = this.directiveRecords;
|
||||||
|
|
||||||
|
@ -129,13 +127,17 @@ export class ChangeDetectorJITGenerator {
|
||||||
`${this._names.getDirectiveName(dir.directiveIndex)}.onAllChangesDone();`);
|
`${this._names.getDirectiveName(dir.directiveIndex)}.onAllChangesDone();`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (notifications.length > 0) {
|
||||||
var directiveNotifications = notifications.join("\n");
|
var directiveNotifications = notifications.join("\n");
|
||||||
|
|
||||||
return `
|
return `
|
||||||
${this._names.getDispatcherName()}.notifyOnAllChangesDone();
|
${this._typeName}.prototype.callOnAllChangesDone = function() {
|
||||||
|
${ABSTRACT_CHANGE_DETECTOR}.prototype.callOnAllChangesDone.call(this);
|
||||||
${directiveNotifications}
|
${directiveNotifications}
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_genRecord(r: ProtoRecord): string {
|
_genRecord(r: ProtoRecord): string {
|
||||||
|
|
|
@ -106,7 +106,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
callOnAllChangesDone() {
|
callOnAllChangesDone() {
|
||||||
this.dispatcher.notifyOnAllChangesDone();
|
super.callOnAllChangesDone();
|
||||||
var dirs = this.directiveRecords;
|
var dirs = this.directiveRecords;
|
||||||
for (var i = dirs.length - 1; i >= 0; --i) {
|
for (var i = dirs.length - 1; i >= 0; --i) {
|
||||||
var dir = dirs[i];
|
var dir = dirs[i];
|
||||||
|
|
|
@ -120,9 +120,7 @@ class _CodegenState {
|
||||||
|
|
||||||
${_genCheckNoChanges()}
|
${_genCheckNoChanges()}
|
||||||
|
|
||||||
void callOnAllChangesDone() {
|
${_maybeGenCallOnAllChangesDone()}
|
||||||
${_getCallOnAllChangesDoneBody()}
|
|
||||||
}
|
|
||||||
|
|
||||||
${_maybeGenHydrateDirectives()}
|
${_maybeGenHydrateDirectives()}
|
||||||
|
|
||||||
|
@ -190,17 +188,23 @@ class _CodegenState {
|
||||||
|
|
||||||
/// Generates calls to `onAllChangesDone` for all `Directive`s that request
|
/// Generates calls to `onAllChangesDone` for all `Directive`s that request
|
||||||
/// them.
|
/// them.
|
||||||
String _getCallOnAllChangesDoneBody() {
|
String _maybeGenCallOnAllChangesDone() {
|
||||||
// NOTE(kegluneq): Order is important!
|
// NOTE(kegluneq): Order is important!
|
||||||
var directiveNotifications = _directiveRecords.reversed
|
var directiveNotifications = _directiveRecords.reversed
|
||||||
.where((rec) => rec.callOnAllChangesDone)
|
.where((rec) => rec.callOnAllChangesDone)
|
||||||
.map((rec) =>
|
.map((rec) =>
|
||||||
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();')
|
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();');
|
||||||
.join('');
|
|
||||||
|
if (directiveNotifications.isNotEmpty) {
|
||||||
return '''
|
return '''
|
||||||
|
void callOnAllChangesDone() {
|
||||||
${_names.getDispatcherName()}.notifyOnAllChangesDone();
|
${_names.getDispatcherName()}.notifyOnAllChangesDone();
|
||||||
${directiveNotifications}
|
${directiveNotifications.join('')}
|
||||||
|
}
|
||||||
''';
|
''';
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _genDeclareFields() {
|
String _genDeclareFields() {
|
||||||
|
|
|
@ -73,10 +73,6 @@ class _MyComponent_ChangeDetector0
|
||||||
runDetectChanges(true);
|
runDetectChanges(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void callOnAllChangesDone() {
|
|
||||||
this.dispatcher.notifyOnAllChangesDone();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dehydrateDirectives(destroyPipes) {
|
void dehydrateDirectives(destroyPipes) {
|
||||||
this.myNum0 = this.interpolate1 = _gen.ChangeDetectionUtil.uninitialized;
|
this.myNum0 = this.interpolate1 = _gen.ChangeDetectionUtil.uninitialized;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue