Skip to content

Commit 811679a

Browse files
karamhevery
authored andcommitted
refactor(ivy): remove unnecessary Comp.r function (angular#21650)
PR Close angular#21650
1 parent 2c33d17 commit 811679a

16 files changed

Lines changed: 179 additions & 209 deletions

modules/benchmarks/src/tree/render3/tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ɵC as C, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵb1 as b1, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵp as p, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
9+
import {ɵC as C, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵb1 as b1, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵp as p, ɵr as r, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
1010
import {ComponentDef} from '@angular/core/src/render3/interfaces/definition';
1111

1212
import {TreeNode, buildTree, emptyTree} from '../util';
@@ -59,7 +59,7 @@ export class TreeComponent {
5959
}
6060
p(0, 'data', b(ctx.data.left));
6161
TreeComponent.ngComponentDef.h(1, 0);
62-
TreeComponent.ngComponentDef.r(1, 0);
62+
r(1, 0);
6363
}
6464
v();
6565
}
@@ -76,7 +76,7 @@ export class TreeComponent {
7676
}
7777
p(0, 'data', b(ctx.data.right));
7878
TreeComponent.ngComponentDef.h(1, 0);
79-
TreeComponent.ngComponentDef.r(1, 0);
79+
r(1, 0);
8080
}
8181
v();
8282
}

packages/compiler/test/render3/r3_view_compiler_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ describe('r3_view_compiler', () => {
205205
IDENT.ɵe();
206206
IDENT.ɵT(3, '!');
207207
}
208-
ChildComponent.ngComponentDef.r(1, 0);
209-
SomeDirective.ngDirectiveDef.r(2, 0);
208+
r(1, 0);
209+
r(2, 0);
210210
}
211211
});
212212
`;
@@ -267,7 +267,7 @@ describe('r3_view_compiler', () => {
267267
}
268268
const IDENT = IDENT.ɵm(1);
269269
IDENT.ɵcR(2);
270-
IfDirective.ngDirectiveDef.r(3,2);
270+
r(3,2);
271271
IDENT.ɵcr();
272272
273273
function MyComponent_IfDirective_Template_2(ctx0: IDENT, cm: IDENT) {

packages/core/src/core_render3_private_export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ export {
3434
s as ɵs,
3535
t as ɵt,
3636
v as ɵv,
37+
r as ɵr,
3738
} from './render3/index';
3839
// clang-format on

packages/core/src/render3/definition.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): Co
4040
n: componentDefinition.factory,
4141
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
4242
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
43-
r: componentDefinition.refresh || (componentDefinition.template ?
44-
function(d: number, e: number) {
45-
componentRefresh(d, e, componentDefinition.template);
46-
} :
47-
noop),
4843
h: componentDefinition.hostBindings || noop,
4944
inputs: invertObject(componentDefinition.inputs),
5045
outputs: invertObject(componentDefinition.outputs),

packages/core/src/render3/instructions.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ export function renderComponentOrTemplate<T>(
337337
template(componentOrContext !, creationMode);
338338
} else {
339339
// Element was stored at 0 and directive was stored at 1 in renderComponent
340-
// so to refresh the component, r() needs to be called with (1, 0)
341-
(componentOrContext.constructor as ComponentType<T>).ngComponentDef.r(1, 0);
340+
// so to refresh the component, refresh() needs to be called with (1, 0)
341+
componentRefresh(1, 0);
342342
}
343343
} finally {
344344
if (rendererFactory.end) {
@@ -1161,28 +1161,27 @@ export function viewEnd(): void {
11611161
*
11621162
* @param directiveIndex
11631163
* @param elementIndex
1164-
* @param template
11651164
*/
1166-
export const componentRefresh:
1167-
<T>(directiveIndex: number, elementIndex: number, template: ComponentTemplate<T>) =>
1168-
void = function<T>(
1169-
directiveIndex: number, elementIndex: number, template: ComponentTemplate<T>) {
1170-
ngDevMode && assertDataInRange(elementIndex);
1171-
const element = data ![elementIndex] as LElementNode;
1172-
ngDevMode && assertNodeOfPossibleTypes(element, LNodeFlags.Element, LNodeFlags.Container);
1173-
ngDevMode && assertNotEqual(element.data, null, 'isComponent');
1174-
ngDevMode && assertDataInRange(directiveIndex);
1175-
const hostView = element.data !;
1176-
ngDevMode && assertNotEqual(hostView, null, 'hostView');
1165+
export function componentRefresh<T>(directiveIndex: number, elementIndex: number): void {
11771166
executeInitHooks(currentView);
11781167
executeContentHooks(currentView);
1179-
const directive = data[directiveIndex];
1180-
const oldView = enterView(hostView, element);
1181-
try {
1182-
template(directive, creationMode);
1183-
} finally {
1184-
refreshDynamicChildren();
1185-
leaveView(oldView);
1168+
const template = (tData[directiveIndex] as ComponentDef<T>).template;
1169+
if (template != null) {
1170+
ngDevMode && assertDataInRange(elementIndex);
1171+
const element = data ![elementIndex] as LElementNode;
1172+
ngDevMode && assertNodeType(element, LNodeFlags.Element);
1173+
ngDevMode && assertNotEqual(element.data, null, 'isComponent');
1174+
ngDevMode && assertDataInRange(directiveIndex);
1175+
const directive = data[directiveIndex];
1176+
const hostView = element.data !;
1177+
ngDevMode && assertNotEqual(hostView, null, 'hostView');
1178+
const oldView = enterView(hostView, element);
1179+
try {
1180+
template(directive, creationMode);
1181+
} finally {
1182+
refreshDynamicChildren();
1183+
leaveView(oldView);
1184+
}
11861185
}
11871186
};
11881187

packages/core/src/render3/interfaces/definition.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ export interface DirectiveDef<T> {
6767
*/
6868
n(): T;
6969

70-
/**
71-
* Refreshes the view of the component. Also calls lifecycle hooks like
72-
* ngAfterViewInit, if they are defined on the component.
73-
*
74-
* NOTE: this property is short (1 char) because it is used in component
75-
* templates which is sensitive to size.
76-
*
77-
* @param directiveIndex index of the directive in the containing template
78-
* @param elementIndex index of an host element for a given directive.
79-
*/
80-
r(directiveIndex: number, elementIndex: number): void;
81-
8270
/**
8371
* Refreshes host bindings on the associated directive. Also calls lifecycle hooks
8472
* like ngOnInit and ngDoCheck, if they are defined on the directive.
@@ -94,18 +82,6 @@ export interface DirectiveDef<T> {
9482
}
9583

9684
export interface ComponentDef<T> extends DirectiveDef<T> {
97-
/**
98-
* Refreshes the view of the component. Also calls lifecycle hooks like
99-
* ngAfterViewInit, if they are defined on the component.
100-
*
101-
* NOTE: this property is short (1 char) because it is used in
102-
* component templates which is sensitive to size.
103-
*
104-
* @param directiveIndex index of the directive in the containing template
105-
* @param elementIndex index of an host element for a given component.
106-
*/
107-
r(directiveIndex: number, elementIndex: number): void;
108-
10985
/**
11086
* The tag name which should be used by the component.
11187
*
@@ -142,19 +118,17 @@ export interface LifecycleHooksMap {
142118
export interface DirectiveDefArgs<T> {
143119
type: Type<T>;
144120
factory: () => T;
145-
refresh?: (directiveIndex: number, elementIndex: number) => void;
146121
inputs?: {[P in keyof T]?: string};
147122
outputs?: {[P in keyof T]?: string};
148123
methods?: {[P in keyof T]?: string};
149124
features?: DirectiveDefFeature[];
125+
hostBindings?: (directiveIndex: number, elementIndex: number) => void;
150126
exportAs?: string;
151127
}
152128

153129
export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
154130
tag: string;
155131
template: ComponentTemplate<T>;
156-
refresh?: (directiveIndex: number, elementIndex: number) => void;
157-
hostBindings?: (directiveIndex: number, elementIndex: number) => void;
158132
features?: ComponentDefFeature[];
159133
rendererType?: RendererType2;
160134
}

packages/core/test/render3/compiler_canonical_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ describe('compiler specification', () => {
9898
r3.e();
9999
r3.T(3, '!');
100100
}
101-
ChildComponent.ngComponentDef.r(1, 0);
102-
SomeDirective.ngDirectiveDef.r(2, 0);
101+
r3.r(1, 0);
102+
r3.r(2, 0);
103103
}
104104
});
105105
// /NORMATIVE
@@ -146,7 +146,7 @@ describe('compiler specification', () => {
146146
}
147147
let foo = r3.m<any>(1);
148148
r3.cR(2);
149-
IfDirective.ngDirectiveDef.r(3, 2);
149+
r3.r(3, 2);
150150
r3.cr();
151151

152152
function C1(ctx1: any, cm: boolean) {

packages/core/test/render3/component_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {ViewEncapsulation} from '../../src/core';
10-
import {E, T, b, defineComponent, e, markDirty, t} from '../../src/render3/index';
10+
import {E, T, b, defineComponent, e, markDirty, r, t} from '../../src/render3/index';
1111
import {createRendererType2} from '../../src/view/index';
1212

1313
import {getRendererFactory2} from './imported_renderer2';
@@ -72,7 +72,7 @@ describe('encapsulation', () => {
7272
e();
7373
}
7474
EncapsulatedComponent.ngComponentDef.h(1, 0);
75-
EncapsulatedComponent.ngComponentDef.r(1, 0);
75+
r(1, 0);
7676
},
7777
factory: () => new WrapperComponent,
7878
});
@@ -89,7 +89,7 @@ describe('encapsulation', () => {
8989
e();
9090
}
9191
LeafComponent.ngComponentDef.h(2, 1);
92-
LeafComponent.ngComponentDef.r(2, 1);
92+
r(2, 1);
9393
},
9494
factory: () => new EncapsulatedComponent,
9595
rendererType:
@@ -137,7 +137,7 @@ describe('encapsulation', () => {
137137
e();
138138
}
139139
LeafComponentwith.ngComponentDef.h(1, 0);
140-
LeafComponentwith.ngComponentDef.r(1, 0);
140+
r(1, 0);
141141
},
142142
factory: () => new WrapperComponentWith,
143143
rendererType:

0 commit comments

Comments
 (0)