refactor(ivy): remove unnecessary Comp.r function (#21650)
PR Close #21650
This commit is contained in:

committed by
Misko Hevery

parent
2c33d17609
commit
811679a583
@ -34,5 +34,6 @@ export {
|
||||
s as ɵs,
|
||||
t as ɵt,
|
||||
v as ɵv,
|
||||
r as ɵr,
|
||||
} from './render3/index';
|
||||
// clang-format on
|
||||
|
@ -40,11 +40,6 @@ export function defineComponent<T>(componentDefinition: ComponentDefArgs<T>): Co
|
||||
n: componentDefinition.factory,
|
||||
tag: (componentDefinition as ComponentDefArgs<T>).tag || null !,
|
||||
template: (componentDefinition as ComponentDefArgs<T>).template || null !,
|
||||
r: componentDefinition.refresh || (componentDefinition.template ?
|
||||
function(d: number, e: number) {
|
||||
componentRefresh(d, e, componentDefinition.template);
|
||||
} :
|
||||
noop),
|
||||
h: componentDefinition.hostBindings || noop,
|
||||
inputs: invertObject(componentDefinition.inputs),
|
||||
outputs: invertObject(componentDefinition.outputs),
|
||||
|
@ -337,8 +337,8 @@ export function renderComponentOrTemplate<T>(
|
||||
template(componentOrContext !, creationMode);
|
||||
} else {
|
||||
// Element was stored at 0 and directive was stored at 1 in renderComponent
|
||||
// so to refresh the component, r() needs to be called with (1, 0)
|
||||
(componentOrContext.constructor as ComponentType<T>).ngComponentDef.r(1, 0);
|
||||
// so to refresh the component, refresh() needs to be called with (1, 0)
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
} finally {
|
||||
if (rendererFactory.end) {
|
||||
@ -1161,28 +1161,27 @@ export function viewEnd(): void {
|
||||
*
|
||||
* @param directiveIndex
|
||||
* @param elementIndex
|
||||
* @param template
|
||||
*/
|
||||
export const componentRefresh:
|
||||
<T>(directiveIndex: number, elementIndex: number, template: ComponentTemplate<T>) =>
|
||||
void = function<T>(
|
||||
directiveIndex: number, elementIndex: number, template: ComponentTemplate<T>) {
|
||||
ngDevMode && assertDataInRange(elementIndex);
|
||||
const element = data ![elementIndex] as LElementNode;
|
||||
ngDevMode && assertNodeOfPossibleTypes(element, LNodeFlags.Element, LNodeFlags.Container);
|
||||
ngDevMode && assertNotEqual(element.data, null, 'isComponent');
|
||||
ngDevMode && assertDataInRange(directiveIndex);
|
||||
const hostView = element.data !;
|
||||
ngDevMode && assertNotEqual(hostView, null, 'hostView');
|
||||
export function componentRefresh<T>(directiveIndex: number, elementIndex: number): void {
|
||||
executeInitHooks(currentView);
|
||||
executeContentHooks(currentView);
|
||||
const directive = data[directiveIndex];
|
||||
const oldView = enterView(hostView, element);
|
||||
try {
|
||||
template(directive, creationMode);
|
||||
} finally {
|
||||
refreshDynamicChildren();
|
||||
leaveView(oldView);
|
||||
const template = (tData[directiveIndex] as ComponentDef<T>).template;
|
||||
if (template != null) {
|
||||
ngDevMode && assertDataInRange(elementIndex);
|
||||
const element = data ![elementIndex] as LElementNode;
|
||||
ngDevMode && assertNodeType(element, LNodeFlags.Element);
|
||||
ngDevMode && assertNotEqual(element.data, null, 'isComponent');
|
||||
ngDevMode && assertDataInRange(directiveIndex);
|
||||
const directive = data[directiveIndex];
|
||||
const hostView = element.data !;
|
||||
ngDevMode && assertNotEqual(hostView, null, 'hostView');
|
||||
const oldView = enterView(hostView, element);
|
||||
try {
|
||||
template(directive, creationMode);
|
||||
} finally {
|
||||
refreshDynamicChildren();
|
||||
leaveView(oldView);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -67,18 +67,6 @@ export interface DirectiveDef<T> {
|
||||
*/
|
||||
n(): T;
|
||||
|
||||
/**
|
||||
* Refreshes the view of the component. Also calls lifecycle hooks like
|
||||
* ngAfterViewInit, if they are defined on the component.
|
||||
*
|
||||
* NOTE: this property is short (1 char) because it is used in component
|
||||
* templates which is sensitive to size.
|
||||
*
|
||||
* @param directiveIndex index of the directive in the containing template
|
||||
* @param elementIndex index of an host element for a given directive.
|
||||
*/
|
||||
r(directiveIndex: number, elementIndex: number): void;
|
||||
|
||||
/**
|
||||
* Refreshes host bindings on the associated directive. Also calls lifecycle hooks
|
||||
* like ngOnInit and ngDoCheck, if they are defined on the directive.
|
||||
@ -94,18 +82,6 @@ export interface DirectiveDef<T> {
|
||||
}
|
||||
|
||||
export interface ComponentDef<T> extends DirectiveDef<T> {
|
||||
/**
|
||||
* Refreshes the view of the component. Also calls lifecycle hooks like
|
||||
* ngAfterViewInit, if they are defined on the component.
|
||||
*
|
||||
* NOTE: this property is short (1 char) because it is used in
|
||||
* component templates which is sensitive to size.
|
||||
*
|
||||
* @param directiveIndex index of the directive in the containing template
|
||||
* @param elementIndex index of an host element for a given component.
|
||||
*/
|
||||
r(directiveIndex: number, elementIndex: number): void;
|
||||
|
||||
/**
|
||||
* The tag name which should be used by the component.
|
||||
*
|
||||
@ -142,19 +118,17 @@ export interface LifecycleHooksMap {
|
||||
export interface DirectiveDefArgs<T> {
|
||||
type: Type<T>;
|
||||
factory: () => T;
|
||||
refresh?: (directiveIndex: number, elementIndex: number) => void;
|
||||
inputs?: {[P in keyof T]?: string};
|
||||
outputs?: {[P in keyof T]?: string};
|
||||
methods?: {[P in keyof T]?: string};
|
||||
features?: DirectiveDefFeature[];
|
||||
hostBindings?: (directiveIndex: number, elementIndex: number) => void;
|
||||
exportAs?: string;
|
||||
}
|
||||
|
||||
export interface ComponentDefArgs<T> extends DirectiveDefArgs<T> {
|
||||
tag: string;
|
||||
template: ComponentTemplate<T>;
|
||||
refresh?: (directiveIndex: number, elementIndex: number) => void;
|
||||
hostBindings?: (directiveIndex: number, elementIndex: number) => void;
|
||||
features?: ComponentDefFeature[];
|
||||
rendererType?: RendererType2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user