refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371)

Ivy definition looks something like this:

```
class MyService {
  static ngInjectableDef = defineInjectable({
    …
  });
}
```

Here the argument to `defineInjectable` is well known public contract which needs
to be honored in backward compatible way between versions. The type of the
return value of `defineInjectable` on the other hand is private and can change
shape drastically between versions without effecting backwards compatibility of
libraries publish to NPM. To our users it is effectively an `OpaqueToken`.

By prefixing the type with `ɵ` we are communicating the the outside world that
the value is not public API and is subject to change without backward compatibility.

PR Close #23371
This commit is contained in:
Miško Hevery
2018-04-13 13:34:39 -07:00
committed by Igor Minar
parent f4017ce5e3
commit 2c09b707ce
32 changed files with 179 additions and 172 deletions

View File

@ -15,7 +15,7 @@ import {ComponentRef as viewEngine_ComponentRef} from '../linker/component_facto
import {assertComponentType, assertNotNull} from './assert';
import {queueInitHooks, queueLifecycleHooks} from './hooks';
import {CLEAN_PROMISE, ROOT_DIRECTIVE_INDICES, _getComponentHostLElementNode, baseDirectiveCreate, createLView, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, setHostBindings} from './instructions';
import {ComponentDef, ComponentType} from './interfaces/definition';
import {ComponentType, ɵComponentDef} from './interfaces/definition';
import {LElementNode, TNodeFlags} from './interfaces/node';
import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer';
import {LView, LViewFlags, RootContext} from './interfaces/view';
@ -51,7 +51,7 @@ export interface CreateComponentOptions {
* features list because there's no way of knowing when the component will be used as
* a root component.
*/
hostFeatures?: (<T>(component: T, componentDef: ComponentDef<T>) => void)[];
hostFeatures?: (<T>(component: T, componentDef: ɵComponentDef<T>) => void)[];
/**
* A function which is used to schedule change detection work in the future.
@ -120,7 +120,7 @@ export function renderComponent<T>(
opts: CreateComponentOptions = {}): T {
ngDevMode && assertComponentType(componentType);
const rendererFactory = opts.rendererFactory || domRendererFactory3;
const componentDef = (componentType as ComponentType<T>).ngComponentDef as ComponentDef<T>;
const componentDef = (componentType as ComponentType<T>).ngComponentDef as ɵComponentDef<T>;
if (componentDef.type != componentType) componentDef.type = componentType;
let component: T;
// The first index of the first selector is the tag name.
@ -177,7 +177,7 @@ export function renderComponent<T>(
* renderComponent(AppComponent, {features: [RootLifecycleHooks]});
* ```
*/
export function LifecycleHooksFeature(component: any, def: ComponentDef<any>): void {
export function LifecycleHooksFeature(component: any, def: ɵComponentDef<any>): void {
const elementNode = _getComponentHostLElementNode(component);
// Root component is always created at dir index 0

View File

@ -16,7 +16,7 @@ import {Type} from '../type';
import {resolveRendererType2} from '../view/util';
import {diPublic} from './di';
import {ComponentDef, ComponentDefFeature, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFeature, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {ComponentDefFeature, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeType, PipeTypesOrFactory, ɵComponentDef, ɵDirectiveDef, ɵPipeDef} from './interfaces/definition';
import {CssSelectorList, SelectorFlags} from './interfaces/projection';
@ -150,8 +150,8 @@ export function defineComponent<T>(componentDefinition: {
/**
* Registry of directives and components that may be found in this component's view.
*
* The property is either an array of `DirectiveDef`s or a function which returns the array of
* `DirectiveDef`s. The function is necessary to be able to support forward declarations.
* The property is either an array of `ɵDirectiveDef`s or a function which returns the array of
* `ɵDirectiveDef`s. The function is necessary to be able to support forward declarations.
*/
directives?: DirectiveTypesOrFactory | null;
@ -162,11 +162,11 @@ export function defineComponent<T>(componentDefinition: {
* `PipeDefs`s. The function is necessary to be able to support forward declarations.
*/
pipes?: PipeTypesOrFactory | null;
}): ComponentDef<T> {
}): ɵComponentDef<T> {
const type = componentDefinition.type;
const pipeTypes = componentDefinition.pipes !;
const directiveTypes = componentDefinition.directives !;
const def = <ComponentDef<any>>{
const def = <ɵComponentDef<any>>{
type: type,
diPublic: null,
factory: componentDefinition.factory,
@ -200,7 +200,7 @@ export function defineComponent<T>(componentDefinition: {
}
export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>):
DirectiveDef<any>|ComponentDef<any> {
ɵDirectiveDef<any>|ɵComponentDef<any> {
const def = type.ngComponentDef || type.ngDirectiveDef;
if (ngDevMode && !def) {
throw new Error(`'${type.name}' is neither 'ComponentType' or 'DirectiveType'.`);
@ -208,7 +208,7 @@ export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>
return def;
}
export function extractPipeDef(type: PipeType<any>): PipeDef<any> {
export function extractPipeDef(type: PipeType<any>): ɵPipeDef<any> {
const def = type.ngPipeDef;
if (ngDevMode && !def) {
throw new Error(`'${type.name}' is not a 'PipeType'.`);
@ -250,7 +250,7 @@ type OnChangesExpando = OnChanges & {
*/
export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string}):
DirectiveDefFeature {
return function(definition: DirectiveDef<any>): void {
return function(definition: ɵDirectiveDef<any>): void {
const inputs = definition.inputs;
const proto = definition.type.prototype;
// Place where we will store SimpleChanges if there is a change
@ -306,7 +306,7 @@ export function NgOnChangesFeature(inputPropertyNames?: {[key: string]: string})
}
export function PublicFeature<T>(definition: DirectiveDef<T>) {
export function PublicFeature<T>(definition: ɵDirectiveDef<T>) {
definition.diPublic = diPublic;
}
@ -400,7 +400,7 @@ export const defineDirective = defineComponent as any as<T>(directiveDefinition:
* See: {@link Directive.exportAs}
*/
exportAs?: string;
}) => DirectiveDef<T>;
}) => ɵDirectiveDef<T>;
/**
* Create a pipe definition object.
@ -428,8 +428,8 @@ export function definePipe<T>(pipeDef: {
/** Whether the pipe is pure. */
pure?: boolean
}): PipeDef<T> {
return <PipeDef<T>>{
}): ɵPipeDef<T> {
return <ɵPipeDef<T>>{
name: pipeDef.name,
n: pipeDef.factory,
pure: pipeDef.pure !== false,

View File

@ -20,7 +20,7 @@ import {Type} from '../type';
import {assertGreaterThan, assertLessThan, assertNotNull} from './assert';
import {addToViewTree, assertPreviousIsParent, createLContainer, createLNodeObject, getDirectiveInstance, getPreviousOrParentNode, getRenderer, isComponent, renderEmbeddedTemplate, resolveDirective} from './instructions';
import {ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDefList} from './interfaces/definition';
import {ComponentTemplate, DirectiveDefList, PipeDefList, ɵDirectiveDef} from './interfaces/definition';
import {LInjector} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, LNodeType, LViewNode, TNodeFlags} from './interfaces/node';
import {QueryReadType} from './interfaces/query';
@ -139,7 +139,7 @@ export function getOrCreateNodeInjectorForNode(node: LElementNode | LContainerNo
* @param di The node injector in which a directive will be added
* @param def The definition of the directive to be made public
*/
export function diPublicInInjector(di: LInjector, def: DirectiveDef<any>): void {
export function diPublicInInjector(di: LInjector, def: ɵDirectiveDef<any>): void {
bloomAdd(di, def.type);
}
@ -148,7 +148,7 @@ export function diPublicInInjector(di: LInjector, def: DirectiveDef<any>): void
*
* @param def The definition of the directive to be made public
*/
export function diPublic(def: DirectiveDef<any>): void {
export function diPublic(def: ɵDirectiveDef<any>): void {
diPublicInInjector(getOrCreateNodeInjector(), def);
}
@ -371,7 +371,7 @@ export function getOrCreateInjectable<T>(di: LInjector, token: Type<T>, flags?:
for (let i = start; i < end; i++) {
// Get the definition for the directive at this index and, if it is injectable (diPublic),
// and matches the given token, return the directive instance.
const directiveDef = defs[i] as DirectiveDef<any>;
const directiveDef = defs[i] as ɵDirectiveDef<any>;
if (directiveDef.type === token && directiveDef.diPublic) {
return getDirectiveInstance(node.view.directives ![i]);
}
@ -400,7 +400,7 @@ function searchMatchesQueuedForCreation<T>(node: LNode, token: any): T|null {
const matches = node.view.tView.currentMatches;
if (matches) {
for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as DirectiveDef<any>;
const def = matches[i] as ɵDirectiveDef<any>;
if (def.type === token) {
return resolveDirective(def, i + 1, matches, node.view.tView);
}

View File

@ -7,7 +7,7 @@
*/
import {assertEqual} from './assert';
import {DirectiveDef} from './interfaces/definition';
import {ɵDirectiveDef} from './interfaces/definition';
import {TNodeFlags} from './interfaces/node';
import {HookData, LView, LifecycleStage, TView} from './interfaces/view';
@ -52,7 +52,7 @@ export function queueLifecycleHooks(flags: number, currentView: LView): void {
// directiveCreate) so we can preserve the current hook order. Content, view, and destroy
// hooks for projected components and directives must be called *before* their hosts.
for (let i = start; i < end; i++) {
const def: DirectiveDef<any> = tView.directives ![i];
const def: ɵDirectiveDef<any> = tView.directives ![i];
queueContentHooks(def, tView, i);
queueViewHooks(def, tView, i);
queueDestroyHooks(def, tView, i);
@ -61,7 +61,7 @@ export function queueLifecycleHooks(flags: number, currentView: LView): void {
}
/** Queues afterContentInit and afterContentChecked hooks on TView */
function queueContentHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
function queueContentHooks(def: ɵDirectiveDef<any>, tView: TView, i: number): void {
if (def.afterContentInit) {
(tView.contentHooks || (tView.contentHooks = [])).push(i, def.afterContentInit);
}
@ -73,7 +73,7 @@ function queueContentHooks(def: DirectiveDef<any>, tView: TView, i: number): voi
}
/** Queues afterViewInit and afterViewChecked hooks on TView */
function queueViewHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
function queueViewHooks(def: ɵDirectiveDef<any>, tView: TView, i: number): void {
if (def.afterViewInit) {
(tView.viewHooks || (tView.viewHooks = [])).push(i, def.afterViewInit);
}
@ -85,7 +85,7 @@ function queueViewHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
}
/** Queues onDestroy hooks on TView */
function queueDestroyHooks(def: DirectiveDef<any>, tView: TView, i: number): void {
function queueDestroyHooks(def: ɵDirectiveDef<any>, tView: TView, i: number): void {
if (def.onDestroy != null) {
(tView.destroyHooks || (tView.destroyHooks = [])).push(i, def.onDestroy);
}

View File

@ -8,7 +8,7 @@
import {LifecycleHooksFeature, createComponentRef, getHostElement, getRenderedText, renderComponent, whenRendered} from './component';
import {NgOnChangesFeature, PublicFeature, defineComponent, defineDirective, definePipe} from './definition';
import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefFlags, DirectiveType, PipeDef} from './interfaces/definition';
import {ComponentTemplate, ComponentType, DirectiveDefFlags, DirectiveType, ɵComponentDef, ɵDirectiveDef, ɵPipeDef} from './interfaces/definition';
export {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF, directiveInject, injectAttribute, injectChangeDetectorRef, injectElementRef, injectTemplateRef, injectViewContainerRef} from './di';
export {RenderFlags} from './interfaces/definition';
@ -103,15 +103,15 @@ export {
// clang-format on
export {
ComponentDef,
ɵComponentDef,
ComponentTemplate,
ComponentType,
DirectiveDef,
ɵDirectiveDef,
DirectiveDefFlags,
DirectiveType,
NgOnChangesFeature,
PublicFeature,
PipeDef,
ɵPipeDef,
LifecycleHooksFeature,
defineComponent,
defineDirective,

View File

@ -19,7 +19,7 @@ import {LContainerNode, LElementNode, LNode, LNodeType, TNodeFlags, LProjectionN
import {assertNodeType} from './node_assert';
import {appendChild, insertChild, insertView, appendProjectedNode, removeView, canInsertNativeNode, createTextNode} from './node_manipulation';
import {isNodeMatchingSelectorList, matchingSelectorIndex} from './node_selector_matcher';
import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveDefList, DirectiveDefListOrFactory, DirectiveType, PipeDef, PipeDefList, PipeDefListOrFactory, RenderFlags} from './interfaces/definition';
import {ɵComponentDef, ComponentTemplate, ComponentType, ɵDirectiveDef, DirectiveDefList, DirectiveDefListOrFactory, DirectiveType, ɵPipeDef, PipeDefList, PipeDefListOrFactory, RenderFlags} from './interfaces/definition';
import {RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, ObjectOrientedRenderer3, RendererStyleFlags3, isProceduralRenderer} from './interfaces/renderer';
import {isDifferent, stringify} from './util';
import {executeHooks, queueLifecycleHooks, queueInitHooks, executeInitHooks} from './hooks';
@ -255,7 +255,7 @@ export function setHostBindings(bindings: number[] | null): void {
const defs = currentView.tView.directives !;
for (let i = 0; i < bindings.length; i += 2) {
const dirIndex = bindings[i];
const def = defs[dirIndex] as DirectiveDef<any>;
const def = defs[dirIndex] as ɵDirectiveDef<any>;
def.hostBindings && def.hostBindings(dirIndex, bindings[i + 1]);
}
}
@ -578,7 +578,7 @@ function cacheMatchingDirectivesForNode(
const matches = tView.currentMatches = findDirectiveMatches(tNode);
if (matches) {
for (let i = 0; i < matches.length; i += 2) {
const def = matches[i] as DirectiveDef<any>;
const def = matches[i] as ɵDirectiveDef<any>;
const valueIndex = i + 1;
resolveDirective(def, valueIndex, matches, tView);
saveNameToExportMap(matches[valueIndex] as number, def, exportsMap);
@ -595,7 +595,7 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
for (let i = 0; i < registry.length; i++) {
const def = registry[i];
if (isNodeMatchingSelectorList(tNode, def.selectors !)) {
if ((def as ComponentDef<any>).template) {
if ((def as ɵComponentDef<any>).template) {
if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);
tNode.flags = TNodeFlags.isComponent;
}
@ -608,7 +608,7 @@ function findDirectiveMatches(tNode: TNode): CurrentMatchesList|null {
}
export function resolveDirective(
def: DirectiveDef<any>, valueIndex: number, matches: CurrentMatchesList, tView: TView): any {
def: ɵDirectiveDef<any>, valueIndex: number, matches: CurrentMatchesList, tView: TView): any {
if (matches[valueIndex] === null) {
matches[valueIndex] = CIRCULAR;
const instance = def.factory();
@ -663,7 +663,7 @@ function instantiateDirectivesDirectly() {
const tDirectives = currentView.tView.directives !;
for (let i = start; i < end; i++) {
const def: DirectiveDef<any> = tDirectives[i];
const def: ɵDirectiveDef<any> = tDirectives[i];
directiveCreate(i, def.factory(), def);
}
}
@ -691,11 +691,11 @@ function cacheMatchingLocalNames(
* to their directive instances.
*/
function saveNameToExportMap(
index: number, def: DirectiveDef<any>| ComponentDef<any>,
index: number, def: ɵDirectiveDef<any>| ɵComponentDef<any>,
exportsMap: {[key: string]: number} | null) {
if (exportsMap) {
if (def.exportAs) exportsMap[def.exportAs] = index;
if ((def as ComponentDef<any>).template) exportsMap[''] = index;
if ((def as ɵComponentDef<any>).template) exportsMap[''] = index;
}
}
@ -801,12 +801,12 @@ export function locateHostElement(
* Creates the host LNode.
*
* @param rNode Render host element.
* @param def ComponentDef
* @param def ɵComponentDef
*
* @returns LElementNode created
*/
export function hostElement(
tag: string, rNode: RElement | null, def: ComponentDef<any>): LElementNode {
tag: string, rNode: RElement | null, def: ɵComponentDef<any>): LElementNode {
resetApplicationState();
const node = createLNode(
0, LNodeType.Element, rNode,
@ -1013,7 +1013,7 @@ function generatePropertyAliases(
const defs = currentView.tView.directives !;
for (let i = start; i < end; i++) {
const directiveDef = defs[i] as DirectiveDef<any>;
const directiveDef = defs[i] as ɵDirectiveDef<any>;
const propertyAliasMap: {[publicName: string]: string} =
isInput ? directiveDef.inputs : directiveDef.outputs;
for (let publicName in propertyAliasMap) {
@ -1203,18 +1203,18 @@ export function textBinding<T>(index: number, value: T | NO_CHANGE): void {
* be retrieved before they are created in which case the value will be null.
*
* @param directive The directive instance.
* @param directiveDef DirectiveDef object which contains information about the template.
* @param directiveDef ɵDirectiveDef object which contains information about the template.
*/
export function directiveCreate<T>(
index: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>): T {
index: number, directive: T, directiveDef: ɵDirectiveDef<T>| ɵComponentDef<T>): T {
const instance = baseDirectiveCreate(index, directive, directiveDef);
ngDevMode && assertNotNull(previousOrParentNode.tNode, 'previousOrParentNode.tNode');
const tNode = previousOrParentNode.tNode;
const isComponent = (directiveDef as ComponentDef<T>).template;
const isComponent = (directiveDef as ɵComponentDef<T>).template;
if (isComponent) {
addComponentLogic(index, directive, directiveDef as ComponentDef<T>);
addComponentLogic(index, directive, directiveDef as ɵComponentDef<T>);
}
if (firstTemplatePass) {
@ -1232,7 +1232,7 @@ export function directiveCreate<T>(
return instance;
}
function addComponentLogic<T>(index: number, instance: T, def: ComponentDef<T>): void {
function addComponentLogic<T>(index: number, instance: T, def: ɵComponentDef<T>): void {
const tView = getOrCreateTView(def.template, def.directiveDefs, def.pipeDefs);
// Only component views should be added to the view tree directly. Embedded views are
@ -1258,7 +1258,7 @@ function addComponentLogic<T>(index: number, instance: T, def: ComponentDef<T>):
* current Angular. Example: local refs and inputs on root component.
*/
export function baseDirectiveCreate<T>(
index: number, directive: T, directiveDef: DirectiveDef<T>| ComponentDef<T>): T {
index: number, directive: T, directiveDef: ɵDirectiveDef<T>| ɵComponentDef<T>): T {
ngDevMode &&
assertEqual(
currentView.bindingStartIndex, -1, 'directives should be created before any bindings');
@ -1631,7 +1631,7 @@ export function componentRefresh<T>(directiveIndex: number, elementIndex: number
// Only attached CheckAlways components or attached, dirty OnPush components should be checked
if (viewAttached(hostView) && hostView.flags & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
ngDevMode && assertDataInRange(directiveIndex, directives !);
const def = currentView.tView.directives ![directiveIndex] as ComponentDef<T>;
const def = currentView.tView.directives ![directiveIndex] as ɵComponentDef<T>;
detectChangesInternal(
hostView, element, def, getDirectiveInstance(directives ![directiveIndex]));
@ -1943,7 +1943,7 @@ export function detectChanges<T>(component: T): void {
const hostNode = _getComponentHostLElementNode(component);
ngDevMode && assertNotNull(hostNode.data, 'Component host node should be attached to an LView');
const componentIndex = hostNode.tNode !.flags >> TNodeFlags.DirectiveStartingIndexShift;
const def = hostNode.view.tView.directives ![componentIndex] as ComponentDef<T>;
const def = hostNode.view.tView.directives ![componentIndex] as ɵComponentDef<T>;
detectChangesInternal(hostNode.data as LView, hostNode, def, component);
}
@ -1965,7 +1965,7 @@ export function checkNoChanges<T>(component: T): void {
/** Checks the view of the component provided. Does not gate on dirty checks or execute doCheck. */
export function detectChangesInternal<T>(
hostView: LView, hostNode: LElementNode, def: ComponentDef<T>, component: T) {
hostView: LView, hostNode: LElementNode, def: ɵComponentDef<T>, component: T) {
const oldView = enterView(hostView, hostNode);
const template = def.template;

View File

@ -35,24 +35,24 @@ export const enum RenderFlags {
}
/**
* A subclass of `Type` which has a static `ngComponentDef`:`ComponentDef` field making it
* A subclass of `Type` which has a static `ngComponentDef`:`ɵComponentDef` field making it
* consumable for rendering.
*/
export interface ComponentType<T> extends Type<T> { ngComponentDef: ComponentDef<T>; }
export interface ComponentType<T> extends Type<T> { ngComponentDef: ɵComponentDef<T>; }
/**
* A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
* A subclass of `Type` which has a static `ngDirectiveDef`:`ɵDirectiveDef` field making it
* consumable for rendering.
*/
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: DirectiveDef<T>; }
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: ɵDirectiveDef<T>; }
export const enum DirectiveDefFlags {ContentQuery = 0b10}
/**
* A subclass of `Type` which has a static `ngPipeDef`:`PipeDef` field making it
* A subclass of `Type` which has a static `ngPipeDef`:`ɵPipeDef` field making it
* consumable for rendering.
*/
export interface PipeType<T> extends Type<T> { ngPipeDef: PipeDef<T>; }
export interface PipeType<T> extends Type<T> { ngPipeDef: ɵPipeDef<T>; }
/**
* Runtime link information for Directives.
@ -65,13 +65,18 @@ export interface PipeType<T> extends Type<T> { ngPipeDef: PipeDef<T>; }
* can change between versions.
*
* See: {@link defineDirective}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/
export interface DirectiveDef<T> {
export interface ɵDirectiveDef<T> {
/** Token representing the directive. Used by DI. */
type: Type<T>;
/** Function that makes a directive public to the DI system. */
diPublic: ((def: DirectiveDef<any>) => void)|null;
diPublic: ((def: ɵDirectiveDef<any>) => void)|null;
/** The selectors that will be used to match nodes to this directive. */
selectors: CssSelectorList;
@ -135,8 +140,13 @@ export interface DirectiveDef<T> {
* can change between versions.
*
* See: {@link defineComponent}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/
export interface ComponentDef<T> extends DirectiveDef<T> {
export interface ɵComponentDef<T> extends ɵDirectiveDef<T> {
/**
* The View template of the component.
*
@ -169,8 +179,8 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
/**
* Registry of directives and components that may be found in this view.
*
* The property is either an array of `DirectiveDef`s or a function which returns the array of
* `DirectiveDef`s. The function is necessary to be able to support forward declarations.
* The property is either an array of `ɵDirectiveDef`s or a function which returns the array of
* `ɵDirectiveDef`s. The function is necessary to be able to support forward declarations.
*/
directiveDefs: DirectiveDefListOrFactory|null;
@ -194,8 +204,13 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
* can change between versions.
*
* See: {@link definePipe}
*
* NOTE: This is a semi public API, and there are no guaranties that the shape of this API will
* remain consistent between version. Use with caution.
*
* @experimental
*/
export interface PipeDef<T> {
export interface ɵPipeDef<T> {
/**
* Pipe name.
*
@ -223,8 +238,8 @@ export interface PipeDef<T> {
onDestroy: (() => void)|null;
}
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
export type DirectiveDefFeature = <T>(directiveDef: ɵDirectiveDef<T>) => void;
export type ComponentDefFeature = <T>(componentDef: ɵComponentDef<T>) => void;
/**
* Type used for directiveDefs on component definition.
@ -233,12 +248,12 @@ export type ComponentDefFeature = <T>(componentDef: ComponentDef<T>) => void;
*/
export type DirectiveDefListOrFactory = (() => DirectiveDefList) | DirectiveDefList;
export type DirectiveDefList = (DirectiveDef<any>| ComponentDef<any>)[];
export type DirectiveDefList = (ɵDirectiveDef<any>| ɵComponentDef<any>)[];
export type DirectiveTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type DirectiveTypeList =
(DirectiveDef<any>| ComponentDef<any>|
(ɵDirectiveDef<any>| ɵComponentDef<any>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
/**
@ -248,12 +263,12 @@ export type DirectiveTypeList =
*/
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
export type PipeDefList = PipeDef<any>[];
export type PipeDefList = ɵPipeDef<any>[];
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type PipeTypeList =
(PipeDef<any>| Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
(ɵPipeDef<any>| Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
// Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -8,7 +8,7 @@
import {Injector} from '../../di/injector';
import {LContainer} from './container';
import {ComponentTemplate, DirectiveDef, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {ComponentTemplate, DirectiveDefList, PipeDefList, ɵDirectiveDef, ɵPipeDef} from './definition';
import {LElementNode, LViewNode, TNode} from './node';
import {LQueries} from './query';
import {Renderer3} from './renderer';
@ -428,10 +428,10 @@ export const enum LifecycleStage {
* as its pipe instance in the data array. Any nodes that do not have static
* data store a null value in tData to avoid a sparse array.
*/
export type TData = (TNode | PipeDef<any>| null)[];
export type TData = (TNode | ɵPipeDef<any>| null)[];
/** Type for TView.currentMatches */
export type CurrentMatchesList = [DirectiveDef<any>, (string | number | null)];
export type CurrentMatchesList = [ɵDirectiveDef<any>, (string | number | null)];
// Note: This hack is necessary so we don't erroneously get a circular dependency
// failure based on types.

View File

@ -9,9 +9,10 @@
import {PipeTransform} from '../change_detection/pipe_transform';
import {getTView, load, store} from './instructions';
import {PipeDef, PipeDefList} from './interfaces/definition';
import {PipeDefList, ɵPipeDef} from './interfaces/definition';
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunctionV} from './pure_function';
/**
* Create a pipe.
*
@ -21,7 +22,7 @@ import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction
*/
export function pipe(index: number, pipeName: string): any {
const tView = getTView();
let pipeDef: PipeDef<any>;
let pipeDef: ɵPipeDef<any>;
if (tView.firstTemplatePass) {
pipeDef = getPipeDef(pipeName, tView.pipeRegistry);
@ -30,7 +31,7 @@ export function pipe(index: number, pipeName: string): any {
(tView.pipeDestroyHooks || (tView.pipeDestroyHooks = [])).push(index, pipeDef.onDestroy);
}
} else {
pipeDef = tView.data[index] as PipeDef<any>;
pipeDef = tView.data[index] as ɵPipeDef<any>;
}
const pipeInstance = pipeDef.n();
@ -44,9 +45,9 @@ export function pipe(index: number, pipeName: string): any {
*
* @param name Name of pipe to resolve
* @param registry Full list of available pipes
* @returns Matching PipeDef
* @returns Matching ɵPipeDef
*/
function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> {
function getPipeDef(name: string, registry: PipeDefList | null): ɵPipeDef<any> {
if (registry) {
for (let i = 0; i < registry.length; i++) {
const pipeDef = registry[i];
@ -140,5 +141,5 @@ export function pipeBindV(index: number, values: any[]): any {
}
function isPure(index: number): boolean {
return (<PipeDef<any>>getTView().data[index]).pure;
return (<ɵPipeDef<any>>getTView().data[index]).pure;
}

View File

@ -18,7 +18,7 @@ import {getSymbolIterator} from '../util';
import {assertEqual, assertNotNull} from './assert';
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
import {assertPreviousIsParent, getCurrentQueries, store} from './instructions';
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {unusedValueExportToPlacateAjd as unused1, ɵDirectiveDef} from './interfaces/definition';
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {LContainerNode, LElementNode, LNode, TNode, TNodeFlags, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
import {LQueries, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
@ -200,7 +200,7 @@ function getIdxOfMatchingDirective(node: LNode, type: Type<any>): number|null {
const start = flags >> TNodeFlags.DirectiveStartingIndexShift;
const end = start + count;
for (let i = start; i < end; i++) {
const def = defs[i] as DirectiveDef<any>;
const def = defs[i] as ɵDirectiveDef<any>;
if (def.type === type && def.diPublic) {
return i;
}