Skip to content

Commit b462f49

Browse files
karaIgorMinar
authored andcommitted
refactor(core): renamed and split out interfaces (angular#20855)
PR Close angular#20855
1 parent 1a9064b commit b462f49

File tree

13 files changed

+561
-498
lines changed

13 files changed

+561
-498
lines changed

packages/core/src/render3/component.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import {ComponentRef, EmbeddedViewRef, Injector} from '../core';
1010
import {assertNotNull} from './assert';
1111
import {NG_HOST_SYMBOL, createError, createViewState, directiveCreate, elementHost, enterView, leaveView} from './instructions';
12-
import {LElement} from './interfaces';
12+
import {LElement} from './l_node';
1313
import {ComponentDef, ComponentType} from './public_interfaces';
1414
import {RElement, Renderer3, RendererFactory3} from './renderer';
15-
import {stringify} from './util';
15+
import {stringify, notImplemented} from './util';
1616

1717

1818

@@ -71,27 +71,28 @@ export function createComponentRef<T>(
7171
function createViewRef<T>(detectChanges: () => void, context: T): EmbeddedViewRef<T> {
7272
return addDestroyable(
7373
{
74+
// TODO: rootNodes should be replaced when properly implemented
7475
rootNodes: null !,
7576
// inherited from core/ChangeDetectorRef
7677
markForCheck: () => {
7778
if (ngDevMode) {
78-
implement();
79+
throw notImplemented();
7980
}
8081
},
8182
detach: () => {
8283
if (ngDevMode) {
83-
implement();
84+
throw notImplemented();
8485
}
8586
},
8687
detectChanges: detectChanges,
8788
checkNoChanges: () => {
8889
if (ngDevMode) {
89-
implement();
90+
throw notImplemented();
9091
}
9192
},
9293
reattach: () => {
9394
if (ngDevMode) {
94-
implement();
95+
throw notImplemented();
9596
}
9697
},
9798
},
@@ -105,10 +106,6 @@ interface DestroyRef<T> {
105106
onDestroy(cb: Function): void;
106107
}
107108

108-
function implement() {
109-
throw new Error('NotImplemented');
110-
}
111-
112109
function addDestroyable<T, C>(obj: any, context: C): T&DestroyRef<C> {
113110
let destroyFn: Function[]|null = null;
114111
obj.destroyed = false;

packages/core/src/render3/di.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// correctly implementing its interfaces for backwards compatibility.
1111
import * as viewEngine from '../core';
1212
import {BLOOM_SIZE, NG_ELEMENT_ID, getOrCreateNodeInjector} from './instructions';
13-
import {LContainer, LNodeFlags, LNodeInjector} from './interfaces';
13+
import {LContainer, LNodeFlags, LNodeInjector} from './l_node';
1414
import {ComponentTemplate, DirectiveDef} from './public_interfaces';
1515
import {stringify, notImplemented} from './util';
1616

packages/core/src/render3/instructions.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import './ng_dev_mode';
1010

1111
import {Type} from '../core';
1212
import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert';
13-
import {
14-
CSSSelector, ContainerState, InitialInputData, InitialInputs, LContainer, LContainerStatic, LElement, LNode,
15-
LNodeFlags, LNodeInjector, LNodeStatic, LProjection, LText, LView, MinificationData, MinificationDataValue,
16-
ProjectionState, QueryState, ViewState, NgStaticData
17-
} from './interfaces';
13+
import {CssSelector, ContainerState, ProjectionState, QueryState, ViewState} from './interfaces';
14+
import {LText, LView, LElement, LNode, LNodeFlags, LNodeInjector, LContainer, LProjection} from './l_node';
15+
import {NgStaticData, LNodeStatic, LContainerStatic, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './l_node_static';
1816
import {assertNodeType} from './node_assert';
1917
import {appendChild, insertChild, insertView, processProjectedNode, removeView} from './node_manipulation';
2018
import {isNodeMatchingSelector} from './node_selector_matcher';
@@ -439,7 +437,7 @@ export function listenerCreate(
439437
// if we create LNodeStatic here, inputs must be undefined so we know they still need to be
440438
// checked
441439
mergeData.outputs = null;
442-
mergeData = generateMinifiedData(node.flags, mergeData);
440+
mergeData = generatePropertyAliases(node.flags, mergeData);
443441
}
444442

445443
const outputs = mergeData.outputs;
@@ -474,7 +472,7 @@ export function elementEnd() {
474472
}
475473
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Element);
476474
const query = previousOrParentNode.query;
477-
query && query.add(previousOrParentNode);
475+
query && query.addNode(previousOrParentNode);
478476
}
479477

480478
/**
@@ -525,11 +523,11 @@ export function elementProperty<T>(index: number, propName: string, value: T | N
525523
if (staticData.inputs === undefined) {
526524
// mark inputs as checked
527525
staticData.inputs = null;
528-
staticData = generateMinifiedData(node.flags, staticData, true);
526+
staticData = generatePropertyAliases(node.flags, staticData, true);
529527
}
530528

531529
const inputData = staticData.inputs;
532-
let dataValue: MinificationDataValue|null;
530+
let dataValue: PropertyAliasValue|null;
533531
if (inputData && (dataValue = inputData[propName])) {
534532
setInputsForProperty(dataValue, value);
535533
} else {
@@ -572,22 +570,22 @@ function setInputsForProperty(inputs: (number | string)[], value: any): void {
572570
*
573571
* @param index Index where data should be stored in ngStaticData
574572
*/
575-
function generateMinifiedData(flags: number, data: LNodeStatic, isInputData = false): LNodeStatic {
573+
function generatePropertyAliases(flags: number, data: LNodeStatic, isInputData = false): LNodeStatic {
576574
const start = flags >> LNodeFlags.INDX_SHIFT;
577575
const size = (flags & LNodeFlags.SIZE_MASK) >> LNodeFlags.SIZE_SHIFT;
578576

579577
for (let i = start, ii = start + size; i < ii; i++) {
580578
const directiveDef: DirectiveDef<any> = ngStaticData ![i] as DirectiveDef<any>;
581-
const minifiedPropertyMap: {[minifiedKey: string]: string} =
579+
const propertyAliasMap: {[publicName: string]: string} =
582580
isInputData ? directiveDef.inputs : directiveDef.outputs;
583-
for (let unminifiedKey in minifiedPropertyMap) {
584-
if (minifiedPropertyMap.hasOwnProperty(unminifiedKey)) {
585-
const minifiedKey = minifiedPropertyMap[unminifiedKey];
586-
const staticDirData: MinificationData = isInputData ? (data.inputs || (data.inputs = {})) :
581+
for (let publicName in propertyAliasMap) {
582+
if (propertyAliasMap.hasOwnProperty(publicName)) {
583+
const internalName = propertyAliasMap[publicName];
584+
const staticDirData: PropertyAliases = isInputData ? (data.inputs || (data.inputs = {})) :
587585
(data.outputs || (data.outputs = {}));
588-
const hasProperty: boolean = staticDirData.hasOwnProperty(unminifiedKey);
589-
hasProperty ? staticDirData[unminifiedKey].push(i, minifiedKey) :
590-
(staticDirData[unminifiedKey] = [i, minifiedKey]);
586+
const hasProperty: boolean = staticDirData.hasOwnProperty(publicName);
587+
hasProperty ? staticDirData[publicName].push(i, internalName) :
588+
(staticDirData[publicName] = [i, internalName]);
591589
}
592590
}
593591
}
@@ -851,9 +849,9 @@ export function containerCreate(
851849
index: number, template?: ComponentTemplate<any>, tagName?: string, attrs?: string[]): void {
852850
ngDevMode && assertEqual(currentView.bindingStartIndex, null, 'bindingStartIndex');
853851

854-
// If the direct parent of the container is a view, its children (including its comment)
852+
// If the direct parent of the container is a view, its views (including its comment)
855853
// will need to be added through insertView() when its parent view is being inserted.
856-
// For now, it is marked "headless" so we know to append its children later.
854+
// For now, it is marked "headless" so we know to append its views later.
857855
let comment = renderer.createComment(ngDevMode ? 'container' : '');
858856
let renderParent: LElement|null = null;
859857
const currentParent = isParent ? previousOrParentNode : previousOrParentNode.parent !;
@@ -866,7 +864,7 @@ export function containerCreate(
866864
}
867865

868866
const node = createLNode(index, LNodeFlags.Container, comment, <ContainerState>{
869-
children: [],
867+
views: [],
870868
nextIndex: 0, renderParent,
871869
template: template == null ? null : template,
872870
next: null,
@@ -922,7 +920,7 @@ export function refreshContainerEnd(): void {
922920
const container = previousOrParentNode as LContainer;
923921
ngDevMode && assertNodeType(container, LNodeFlags.Container);
924922
const nextIndex = container.data.nextIndex;
925-
while (nextIndex < container.data.children.length) {
923+
while (nextIndex < container.data.views.length) {
926924
// remove extra view.
927925
removeView(container, nextIndex);
928926
}
@@ -938,14 +936,14 @@ export function viewCreate(viewBlockId: number): boolean {
938936
const container = (isParent ? previousOrParentNode : previousOrParentNode.parent !) as LContainer;
939937
ngDevMode && assertNodeType(container, LNodeFlags.Container);
940938
const containerState = container.data;
941-
const children = containerState.children;
939+
const views = containerState.views;
942940

943-
const existingView: LView|false = !creationMode && containerState.nextIndex < children.length &&
944-
children[containerState.nextIndex];
941+
const existingView: LView|false = !creationMode && containerState.nextIndex < views.length &&
942+
views[containerState.nextIndex];
945943
let viewUpdateMode = existingView && viewBlockId === (existingView as LView).data.id;
946944

947945
if (viewUpdateMode) {
948-
previousOrParentNode = children[containerState.nextIndex++];
946+
previousOrParentNode = views[containerState.nextIndex++];
949947
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.View);
950948
isParent = true;
951949
enterView((existingView as LView).data, previousOrParentNode as LView);
@@ -990,8 +988,8 @@ export function viewEnd(): void {
990988
ngDevMode && assertNodeType(viewNode, LNodeFlags.View);
991989
ngDevMode && assertNodeType(container, LNodeFlags.Container);
992990
const containerState = container.data;
993-
const previousView = containerState.nextIndex <= containerState.children.length ?
994-
containerState.children[containerState.nextIndex - 1] as LView :
991+
const previousView = containerState.nextIndex <= containerState.views.length ?
992+
containerState.views[containerState.nextIndex - 1] as LView :
995993
null;
996994
const viewIdChanged = previousView == null ? true : previousView.data.id !== viewNode.data.id;
997995

@@ -1033,9 +1031,9 @@ export const refreshComponent:
10331031
* each projected node belongs (it re-distributes nodes among "buckets" where each "bucket" is
10341032
* backed by a selector).
10351033
*
1036-
* @param {CSSSelector[]} selectors
1034+
* @param {CssSelector[]} selectors
10371035
*/
1038-
export function distributeProjectedNodes(selectors?: CSSSelector[]): LNode[][] {
1036+
export function distributeProjectedNodes(selectors?: CssSelector[]): LNode[][] {
10391037
const noOfNodeBuckets = selectors ? selectors.length + 1 : 1;
10401038
const distributedNodes = new Array<LNode[]>(noOfNodeBuckets);
10411039
for (let i = 0; i < noOfNodeBuckets; i++) {

0 commit comments

Comments
 (0)