X Tutup
Skip to content

Commit adc2739

Browse files
committed
perf(change_detection): do not generate onAllChangesDone when not needed
1 parent dd06a87 commit adc2739

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

modules/angular2/src/change_detection/abstract_change_detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
135135

136136
hydrated(): boolean { return this.context !== null; }
137137

138-
callOnAllChangesDone(): void {}
138+
callOnAllChangesDone(): void { this.dispatcher.notifyOnAllChangesDone(); }
139139

140140
_detectChangesInLightDomChildren(throwOnChange: boolean): void {
141141
var c = this.lightDomChildren;

modules/angular2/src/change_detection/change_detection_jit_generator.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export class ChangeDetectorJITGenerator {
5757
5858
${this._genCheckNoChanges()}
5959
60-
${this._typeName}.prototype.callOnAllChangesDone = function() {
61-
${this._genCallOnAllChangesDoneBody()}
62-
}
60+
${this._maybeGenCallOnAllChangesDone()}
6361
6462
${this._maybeGenHydrateDirectives()}
6563
@@ -117,7 +115,7 @@ export class ChangeDetectorJITGenerator {
117115
return lines.join('\n');
118116
}
119117

120-
_genCallOnAllChangesDoneBody(): string {
118+
_maybeGenCallOnAllChangesDone(): string {
121119
var notifications = [];
122120
var dirs = this.directiveRecords;
123121

@@ -129,13 +127,17 @@ export class ChangeDetectorJITGenerator {
129127
`${this._names.getDirectiveName(dir.directiveIndex)}.onAllChangesDone();`);
130128
}
131129
}
132-
133-
var directiveNotifications = notifications.join("\n");
134-
135-
return `
136-
${this._names.getDispatcherName()}.notifyOnAllChangesDone();
137-
${directiveNotifications}
138-
`;
130+
if (notifications.length > 0) {
131+
var directiveNotifications = notifications.join("\n");
132+
return `
133+
${this._typeName}.prototype.callOnAllChangesDone = function() {
134+
${ABSTRACT_CHANGE_DETECTOR}.prototype.callOnAllChangesDone.call(this);
135+
${directiveNotifications}
136+
}
137+
`;
138+
} else {
139+
return '';
140+
}
139141
}
140142

141143
_genRecord(r: ProtoRecord): string {

modules/angular2/src/change_detection/dynamic_change_detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
106106
}
107107

108108
callOnAllChangesDone() {
109-
this.dispatcher.notifyOnAllChangesDone();
109+
super.callOnAllChangesDone();
110110
var dirs = this.directiveRecords;
111111
for (var i = dirs.length - 1; i >= 0; --i) {
112112
var dir = dirs[i];

modules/angular2/src/transform/template_compiler/change_detector_codegen.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ class _CodegenState {
120120
121121
${_genCheckNoChanges()}
122122
123-
void callOnAllChangesDone() {
124-
${_getCallOnAllChangesDoneBody()}
125-
}
123+
${_maybeGenCallOnAllChangesDone()}
126124
127125
${_maybeGenHydrateDirectives()}
128126
@@ -190,17 +188,23 @@ class _CodegenState {
190188

191189
/// Generates calls to `onAllChangesDone` for all `Directive`s that request
192190
/// them.
193-
String _getCallOnAllChangesDoneBody() {
191+
String _maybeGenCallOnAllChangesDone() {
194192
// NOTE(kegluneq): Order is important!
195193
var directiveNotifications = _directiveRecords.reversed
196194
.where((rec) => rec.callOnAllChangesDone)
197195
.map((rec) =>
198-
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();')
199-
.join('');
200-
return '''
201-
${_names.getDispatcherName()}.notifyOnAllChangesDone();
202-
${directiveNotifications}
203-
''';
196+
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();');
197+
198+
if (directiveNotifications.isNotEmpty) {
199+
return '''
200+
void callOnAllChangesDone() {
201+
${_names.getDispatcherName()}.notifyOnAllChangesDone();
202+
${directiveNotifications.join('')}
203+
}
204+
''';
205+
} else {
206+
return '';
207+
}
204208
}
205209

206210
String _genDeclareFields() {

modules/angular2/test/transform/integration/two_annotations_files/expected/bar.ng_deps.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ class _MyComponent_ChangeDetector0
7373
runDetectChanges(true);
7474
}
7575

76-
void callOnAllChangesDone() {
77-
this.dispatcher.notifyOnAllChangesDone();
78-
}
79-
8076
void dehydrateDirectives(destroyPipes) {
8177
this.myNum0 = this.interpolate1 = _gen.ChangeDetectionUtil.uninitialized;
8278
}

0 commit comments

Comments
 (0)
X Tutup