Miško Hevery 2961bf06c6 refactor(ivy): move hostVars/hostAttrs from instruction to DirectiveDef (#34683)
This change moves information from instructions to declarative position:
- `ɵɵallocHostVars(vars)` => `DirectiveDef.hostVars`
- `ɵɵelementHostAttrs(attrs)` => `DirectiveDef.hostAttrs`

When merging directives it is necessary to know about `hostVars` and `hostAttrs`. Before this change the information was stored in the `hostBindings` function. This was problematic, because in order to get to the information the `hostBindings` would have to be executed. In order for `hostBindings` to be executed the directives would have to be instantiated. This means that the directive instantiation would happen before we had knowledge about the `hostAttrs` and as a result the directive could observe in the constructor that not all of the `hostAttrs` have been applied. This further complicates the runtime as we have to apply `hostAttrs` in parts over many invocations.

`ɵɵallocHostVars` was unnecessarily complicated because it would have to update the `LView` (and Blueprint) while existing directives are already executing. By moving it out of `hostBindings` function we can access it statically and we can create correct `LView` (and Blueprint) in a single pass.

This change only changes how the instructions are generated, but does not change the runtime much. (We cheat by emulating the old behavior by calling `ɵɵallocHostVars` and `ɵɵelementHostAttrs`) Subsequent change will refactor the runtime to take advantage of the static information.

PR Close #34683
2020-01-24 12:22:10 -08:00

232 lines
5.3 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {LifecycleHooksFeature, renderComponent, whenRendered} from './component';
import {ɵɵdefineComponent, ɵɵdefineDirective, ɵɵdefineNgModule, ɵɵdefinePipe, ɵɵsetComponentScope, ɵɵsetNgModuleScope} from './definition';
import {ɵɵCopyDefinitionFeature} from './features/copy_definition_feature';
import {ɵɵInheritDefinitionFeature} from './features/inherit_definition_feature';
import {ɵɵNgOnChangesFeature} from './features/ng_onchanges_feature';
import {ɵɵProvidersFeature} from './features/providers_feature';
import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveType, PipeDef, ɵɵComponentDefWithMeta, ɵɵDirectiveDefWithMeta, ɵɵFactoryDef, ɵɵPipeDefWithMeta} from './interfaces/definition';
import {getComponent, getDirectives, getHostElement, getRenderedText} from './util/discovery_utils';
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, injectComponentFactoryResolver} from './component_ref';
export {ɵɵgetFactoryOf, ɵɵgetInheritedFactory} from './di';
// clang-format off
export {
detectChanges,
markDirty,
store,
tick,
ɵɵattribute,
ɵɵattributeInterpolate1,
ɵɵattributeInterpolate2,
ɵɵattributeInterpolate3,
ɵɵattributeInterpolate4,
ɵɵattributeInterpolate5,
ɵɵattributeInterpolate6,
ɵɵattributeInterpolate7,
ɵɵattributeInterpolate8,
ɵɵattributeInterpolateV,
ɵɵclassMap,
ɵɵclassMapInterpolate1,
ɵɵclassMapInterpolate2,
ɵɵclassMapInterpolate3,
ɵɵclassMapInterpolate4,
ɵɵclassMapInterpolate5,
ɵɵclassMapInterpolate6,
ɵɵclassMapInterpolate7,
ɵɵclassMapInterpolate8,
ɵɵclassMapInterpolateV,
ɵɵclassProp,
ɵɵcomponentHostSyntheticListener,
ɵɵcontainer,
ɵɵcontainerRefreshEnd,
ɵɵcontainerRefreshStart,
ɵɵdirectiveInject,
ɵɵinvalidFactory,
ɵɵelement,
ɵɵelementContainer,
ɵɵelementContainerEnd,
ɵɵelementContainerStart,
ɵɵelementEnd,
ɵɵelementStart,
ɵɵembeddedViewEnd,
ɵɵembeddedViewStart,
ɵɵgetCurrentView,
ɵɵinjectAttribute,
ɵɵlistener,
ɵɵnamespaceHTML,
ɵɵnamespaceMathML,
ɵɵnamespaceSVG,
ɵɵnextContext,
ɵɵprojection,
ɵɵprojectionDef,
ɵɵhostProperty,
ɵɵproperty,
ɵɵpropertyInterpolate,
ɵɵpropertyInterpolate1,
ɵɵpropertyInterpolate2,
ɵɵpropertyInterpolate3,
ɵɵpropertyInterpolate4,
ɵɵpropertyInterpolate5,
ɵɵpropertyInterpolate6,
ɵɵpropertyInterpolate7,
ɵɵpropertyInterpolate8,
ɵɵpropertyInterpolateV,
ɵɵreference,
// TODO: remove `select` once we've refactored all of the tests not to use it.
ɵɵselect,
ɵɵadvance,
ɵɵstyleMap,
ɵɵstyleProp,
ɵɵstylePropInterpolate1,
ɵɵstylePropInterpolate2,
ɵɵstylePropInterpolate3,
ɵɵstylePropInterpolate4,
ɵɵstylePropInterpolate5,
ɵɵstylePropInterpolate6,
ɵɵstylePropInterpolate7,
ɵɵstylePropInterpolate8,
ɵɵstylePropInterpolateV,
ɵɵstyleSanitizer,
ɵɵtemplate,
ɵɵtext,
ɵɵtextInterpolate,
ɵɵtextInterpolate1,
ɵɵtextInterpolate2,
ɵɵtextInterpolate3,
ɵɵtextInterpolate4,
ɵɵtextInterpolate5,
ɵɵtextInterpolate6,
ɵɵtextInterpolate7,
ɵɵtextInterpolate8,
ɵɵtextInterpolateV,
ɵɵupdateSyntheticHostBinding,
} from './instructions/all';
export {RenderFlags} from './interfaces/definition';
export {CssSelectorList, ProjectionSlots} from './interfaces/projection';
export {
ɵɵrestoreView,
ɵɵenableBindings,
ɵɵdisableBindings,
} from './state';
export {
ɵɵi18n,
ɵɵi18nAttributes,
ɵɵi18nExp,
ɵɵi18nStart,
ɵɵi18nEnd,
ɵɵi18nApply,
ɵɵi18nPostprocess,
getLocaleId,
setLocaleId,
} from './i18n';
export {NgModuleFactory, NgModuleRef, NgModuleType} from './ng_module_ref';
export {
AttributeMarker
} from './interfaces/node';
export {
setClassMetadata,
} from './metadata';
export {
ɵɵpipe,
ɵɵpipeBind1,
ɵɵpipeBind2,
ɵɵpipeBind3,
ɵɵpipeBind4,
ɵɵpipeBindV,
} from './pipe';
export {
ɵɵqueryRefresh,
ɵɵviewQuery,
ɵɵstaticViewQuery,
ɵɵloadQuery,
ɵɵcontentQuery,
ɵɵstaticContentQuery
} from './query';
export {
ɵɵpureFunction0,
ɵɵpureFunction1,
ɵɵpureFunction2,
ɵɵpureFunction3,
ɵɵpureFunction4,
ɵɵpureFunction5,
ɵɵpureFunction6,
ɵɵpureFunction7,
ɵɵpureFunction8,
ɵɵpureFunctionV,
} from './pure_function';
export {ɵɵtemplateRefExtractor, ɵɵinjectPipeChangeDetectorRef} from './view_engine_compatibility_prebound';
export {ɵɵresolveWindow, ɵɵresolveDocument, ɵɵresolveBody} from './util/misc_utils';
// clang-format on
export {
ComponentDef,
ɵɵComponentDefWithMeta,
ɵɵFactoryDef,
ComponentTemplate,
ComponentType,
DirectiveDef,
ɵɵDirectiveDefWithMeta,
DirectiveType,
ɵɵNgOnChangesFeature,
ɵɵCopyDefinitionFeature,
ɵɵInheritDefinitionFeature,
ɵɵProvidersFeature,
PipeDef,
ɵɵPipeDefWithMeta,
LifecycleHooksFeature,
ɵɵdefineComponent,
ɵɵdefineDirective,
ɵɵdefineNgModule,
ɵɵdefinePipe,
getHostElement,
getComponent,
getDirectives,
getRenderedText,
renderComponent,
ɵɵsetComponentScope,
ɵɵsetNgModuleScope,
whenRendered,
};
export {NO_CHANGE} from './tokens';