Skip to content

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Oct 17, 2019
1 parent 349cafe commit 787bfa8
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 63 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/render3/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {SanitizerFn} from './interfaces/sanitization';
import {isLContainer} from './interfaces/type_checks';
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, TView, T_HOST} from './interfaces/view';
import {appendChild, applyProjection, createTextNode, nativeRemoveNode} from './node_manipulation';
import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from './state';
import {getBindingIndex, getIsParent, getLView, getPreviousOrParentTNode, nextBindingIndex, setIsNotParent, setPreviousOrParentTNode} from './state';
import {renderStringify} from './util/misc_utils';
import {getNativeByIndex, getNativeByTNode, getTNode, load} from './util/view_utils';

Expand Down Expand Up @@ -669,7 +669,7 @@ export function ɵɵi18nEnd(): void {
*/
function i18nEndFirstPass(lView: LView, tView: TView) {
ngDevMode && assertEqual(
lView[BINDING_INDEX], tView.bindingStartIndex,
getBindingIndex(lView), tView.bindingStartIndex,
'i18nEnd should be called before any binding');

const rootIndex = i18nIndexStack[i18nIndexStackPointer--];
Expand Down Expand Up @@ -1036,7 +1036,7 @@ let shiftsCounter = 0;
*/
export function ɵɵi18nExp<T>(value: T): TsickleIssue1009 {
const lView = getLView();
if (bindingUpdated(lView, lView[BINDING_INDEX]++, value)) {
if (bindingUpdated(lView, nextBindingIndex(lView), value)) {
changeMask = changeMask | (1 << shiftsCounter);
}
shiftsCounter++;
Expand Down Expand Up @@ -1065,7 +1065,7 @@ export function ɵɵi18nApply(index: number) {
updateOpCodes = (tI18n as TI18n).update;
icus = (tI18n as TI18n).icus;
}
const bindingsStartIndex = lView[BINDING_INDEX] - shiftsCounter - 1;
const bindingsStartIndex = getBindingIndex(lView) - shiftsCounter - 1;
readUpdateOpCodes(updateOpCodes, icus, bindingsStartIndex, changeMask, lView);

// Reset changeMask & maskBit to default for the next update cycle
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {bindingUpdated} from '../bindings';
import {SanitizerFn} from '../interfaces/sanitization';
import {BINDING_INDEX} from '../interfaces/view';
import {getLView, getSelectedIndex} from '../state';
import {getLView, getSelectedIndex, nextBindingIndex} from '../state';

import {TsickleIssue1009, elementAttributeInternal} from './shared';

Expand All @@ -31,7 +31,7 @@ export function ɵɵattribute(
name: string, value: any, sanitizer?: SanitizerFn | null,
namespace?: string): TsickleIssue1009 {
const lView = getLView();
if (bindingUpdated(lView, lView[BINDING_INDEX]++, value)) {
if (bindingUpdated(lView, nextBindingIndex(lView), value)) {
elementAttributeInternal(getSelectedIndex(), name, value, lView, sanitizer, namespace);
}
return ɵɵattribute;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {isDirectiveHost} from '../interfaces/type_checks';
import {BINDING_INDEX, FLAGS, HEADER_OFFSET, InitPhaseState, LView, LViewFlags, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {assertNodeType} from '../node_assert';
import {appendChild, removeView} from '../node_manipulation';
import {getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getBindingIndex, getCheckNoChangesMode, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getNativeByTNode, load} from '../util/view_utils';

import {addToViewTree, createDirectivesInstances, createLContainer, createTNode, createTView, getOrCreateTNode, resolveDirectives, saveResolvedLocalsInData} from './shared';
Expand Down Expand Up @@ -172,7 +172,7 @@ function containerInternal(
lView: LView, nodeIndex: number, tagName: string | null,
attrs: TAttributes | null): TContainerNode {
ngDevMode && assertEqual(
lView[BINDING_INDEX], lView[TVIEW].bindingStartIndex,
getBindingIndex(lView), lView[TVIEW].bindingStartIndex,
'container nodes should be created before any bindings');

const adjustedIndex = nodeIndex + HEADER_OFFSET;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {isContentQueryHost, isDirectiveHost} from '../interfaces/type_checks';
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {assertNodeType} from '../node_assert';
import {appendChild} from '../node_manipulation';
import {decreaseElementDepthCount, getElementDepthCount, getIsParent, getLView, getNamespace, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {decreaseElementDepthCount, getBindingIndex, getElementDepthCount, getIsParent, getLView, getNamespace, getPreviousOrParentTNode, getSelectedIndex, increaseElementDepthCount, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {setUpAttributes} from '../util/attrs_utils';
import {getInitialStylingValue, hasClassInput, hasStyleInput} from '../util/styling_utils';
import {getNativeByTNode, getTNode} from '../util/view_utils';
Expand Down Expand Up @@ -48,7 +48,7 @@ export function ɵɵelementStart(
const tViewConsts = tView.consts;
const consts = tViewConsts === null || constsIndex == null ? null : tViewConsts[constsIndex];
ngDevMode && assertEqual(
lView[BINDING_INDEX], tView.bindingStartIndex,
getBindingIndex(lView), tView.bindingStartIndex,
'elements should be created before any bindings');

ngDevMode && ngDevMode.rendererCreateElement++;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/element_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {isContentQueryHost, isDirectiveHost} from '../interfaces/type_checks';
import {BINDING_INDEX, HEADER_OFFSET, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {assertNodeType} from '../node_assert';
import {appendChild} from '../node_manipulation';
import {getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';
import {getBindingIndex, getIsParent, getLView, getPreviousOrParentTNode, setIsNotParent, setPreviousOrParentTNode} from '../state';

import {createDirectivesInstances, executeContentQueries, getOrCreateTNode, resolveDirectives, saveResolvedLocalsInData} from './shared';
import {registerInitialStylingOnTNode} from './styling';
Expand Down Expand Up @@ -44,7 +44,7 @@ export function ɵɵelementContainerStart(
const tViewConsts = tView.consts;
const consts = tViewConsts === null || constsIndex == null ? null : tViewConsts[constsIndex];
ngDevMode && assertEqual(
lView[BINDING_INDEX], tView.bindingStartIndex,
getBindingIndex(lView), tView.bindingStartIndex,
'element containers should be created before any bindings');

ngDevMode && ngDevMode.rendererCreateComment++;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/render3/instructions/host_property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {bindingUpdated} from '../bindings';
import {SanitizerFn} from '../interfaces/sanitization';
import {BINDING_INDEX, TVIEW} from '../interfaces/view';
import {getLView, getSelectedIndex} from '../state';
import {getLView, getSelectedIndex, nextBindingIndex} from '../state';
import {NO_CHANGE} from '../tokens';

import {TsickleIssue1009, elementPropertyInternal, loadComponentRenderer, storePropertyBindingMetadata} from './shared';
Expand All @@ -30,7 +30,7 @@ import {TsickleIssue1009, elementPropertyInternal, loadComponentRenderer, storeP
export function ɵɵhostProperty<T>(
propName: string, value: T, sanitizer?: SanitizerFn | null): TsickleIssue1009 {
const lView = getLView();
const bindingIndex = lView[BINDING_INDEX]++;
const bindingIndex = nextBindingIndex(lView);
if (bindingUpdated(lView, bindingIndex, value)) {
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, value, sanitizer, true);
Expand Down Expand Up @@ -64,7 +64,7 @@ export function ɵɵhostProperty<T>(
export function ɵɵupdateSyntheticHostBinding<T>(
propName: string, value: T | NO_CHANGE, sanitizer?: SanitizerFn | null): TsickleIssue1009 {
const lView = getLView();
const bindingIndex = lView[BINDING_INDEX]++;
const bindingIndex = nextBindingIndex(lView);
if (bindingUpdated(lView, bindingIndex, value)) {
const nodeIndex = getSelectedIndex();
elementPropertyInternal(
Expand Down
35 changes: 18 additions & 17 deletions packages/core/src/render3/instructions/interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {assertEqual, assertLessThan} from '../../util/assert';
import {bindingUpdated, bindingUpdated2, bindingUpdated3, bindingUpdated4} from '../bindings';
import {BINDING_INDEX, LView} from '../interfaces/view';
import {getBindingIndex, incrementBindingIndex, nextBindingIndex, setBindingIndex} from '../state';
import {NO_CHANGE} from '../tokens';
import {renderStringify} from '../util/misc_utils';

Expand All @@ -30,13 +31,13 @@ export function interpolationV(lView: LView, values: any[]): string|NO_CHANGE {
ngDevMode && assertLessThan(2, values.length, 'should have at least 3 values');
ngDevMode && assertEqual(values.length % 2, 1, 'should have an odd number of values');
let isBindingUpdated = false;
let bindingIndex = lView[BINDING_INDEX];
let bindingIndex = getBindingIndex(lView);

for (let i = 1; i < values.length; i += 2) {
// Check if bindings (odd indexes) have changed
isBindingUpdated = bindingUpdated(lView, bindingIndex++, values[i]) || isBindingUpdated;
}
lView[BINDING_INDEX] = bindingIndex;
setBindingIndex(lView, bindingIndex);

if (!isBindingUpdated) {
return NO_CHANGE;
Expand All @@ -60,7 +61,7 @@ export function interpolationV(lView: LView, values: any[]): string|NO_CHANGE {
*/
export function interpolation1(lView: LView, prefix: string, v0: any, suffix: string): string|
NO_CHANGE {
const different = bindingUpdated(lView, lView[BINDING_INDEX]++, v0);
const different = bindingUpdated(lView, nextBindingIndex(lView), v0);
return different ? prefix + renderStringify(v0) + suffix : NO_CHANGE;
}

Expand All @@ -69,9 +70,9 @@ export function interpolation1(lView: LView, prefix: string, v0: any, suffix: st
*/
export function interpolation2(
lView: LView, prefix: string, v0: any, i0: string, v1: any, suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
const different = bindingUpdated2(lView, bindingIndex, v0, v1);
lView[BINDING_INDEX] += 2;
incrementBindingIndex(lView, 2);

return different ? prefix + renderStringify(v0) + i0 + renderStringify(v1) + suffix : NO_CHANGE;
}
Expand All @@ -82,9 +83,9 @@ export function interpolation2(
export function interpolation3(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any,
suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
const different = bindingUpdated3(lView, bindingIndex, v0, v1, v2);
lView[BINDING_INDEX] += 3;
incrementBindingIndex(lView, 3);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + suffix :
Expand All @@ -97,9 +98,9 @@ export function interpolation3(
export function interpolation4(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
v3: any, suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
const different = bindingUpdated4(lView, bindingIndex, v0, v1, v2, v3);
lView[BINDING_INDEX] += 4;
incrementBindingIndex(lView, 4);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 +
Expand All @@ -113,10 +114,10 @@ export function interpolation4(
export function interpolation5(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
v3: any, i3: string, v4: any, suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
let different = bindingUpdated4(lView, bindingIndex, v0, v1, v2, v3);
different = bindingUpdated(lView, bindingIndex + 4, v4) || different;
lView[BINDING_INDEX] += 5;
incrementBindingIndex(lView, 5);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 +
Expand All @@ -130,10 +131,10 @@ export function interpolation5(
export function interpolation6(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
v3: any, i3: string, v4: any, i4: string, v5: any, suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
let different = bindingUpdated4(lView, bindingIndex, v0, v1, v2, v3);
different = bindingUpdated2(lView, bindingIndex + 4, v4, v5) || different;
lView[BINDING_INDEX] += 6;
incrementBindingIndex(lView, 6);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 +
Expand All @@ -148,10 +149,10 @@ export function interpolation7(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
v3: any, i3: string, v4: any, i4: string, v5: any, i5: string, v6: any, suffix: string): string|
NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
let different = bindingUpdated4(lView, bindingIndex, v0, v1, v2, v3);
different = bindingUpdated3(lView, bindingIndex + 4, v4, v5, v6) || different;
lView[BINDING_INDEX] += 7;
incrementBindingIndex(lView, 7);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 +
Expand All @@ -167,10 +168,10 @@ export function interpolation8(
lView: LView, prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string,
v3: any, i3: string, v4: any, i4: string, v5: any, i5: string, v6: any, i6: string, v7: any,
suffix: string): string|NO_CHANGE {
const bindingIndex = lView[BINDING_INDEX];
const bindingIndex = getBindingIndex(lView);
let different = bindingUpdated4(lView, bindingIndex, v0, v1, v2, v3);
different = bindingUpdated4(lView, bindingIndex + 4, v4, v5, v6, v7) || different;
lView[BINDING_INDEX] += 8;
incrementBindingIndex(lView, 8);

return different ?
prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 +
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {bindingUpdated} from '../bindings';
import {SanitizerFn} from '../interfaces/sanitization';
import {BINDING_INDEX, TVIEW} from '../interfaces/view';
import {getLView, getSelectedIndex} from '../state';
import {getLView, getSelectedIndex, nextBindingIndex} from '../state';

import {TsickleIssue1009, elementPropertyInternal, storePropertyBindingMetadata} from './shared';

Expand All @@ -34,7 +34,7 @@ import {TsickleIssue1009, elementPropertyInternal, storePropertyBindingMetadata}
export function ɵɵproperty<T>(
propName: string, value: T, sanitizer?: SanitizerFn | null): TsickleIssue1009 {
const lView = getLView();
const bindingIndex = lView[BINDING_INDEX]++;
const bindingIndex = nextBindingIndex(lView);
if (bindingUpdated(lView, bindingIndex, value)) {
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, value, sanitizer);
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/render3/instructions/property_interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import {SanitizerFn} from '../interfaces/sanitization';
import {BINDING_INDEX, TVIEW} from '../interfaces/view';
import {getLView, getSelectedIndex} from '../state';
import {getBindingIndex, getLView, getSelectedIndex} from '../state';
import {NO_CHANGE} from '../tokens';

import {interpolation1, interpolation2, interpolation3, interpolation4, interpolation5, interpolation6, interpolation7, interpolation8, interpolationV} from './interpolation';
Expand Down Expand Up @@ -87,7 +87,7 @@ export function ɵɵpropertyInterpolate1(
if (interpolatedValue !== NO_CHANGE) {
elementPropertyInternal(lView, getSelectedIndex(), propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, getSelectedIndex(), propName, lView[BINDING_INDEX] - 1,
lView[TVIEW].data, getSelectedIndex(), propName, getBindingIndex(lView) - 1,
prefix, suffix);
}
return ɵɵpropertyInterpolate1;
Expand Down Expand Up @@ -133,7 +133,7 @@ export function ɵɵpropertyInterpolate2(
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode &&
storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 2, prefix, i0, suffix);
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 2, prefix, i0, suffix);
}
return ɵɵpropertyInterpolate2;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export function ɵɵpropertyInterpolate3(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 3, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 3, prefix, i0,
i1, suffix);
}
return ɵɵpropertyInterpolate3;
Expand Down Expand Up @@ -230,7 +230,7 @@ export function ɵɵpropertyInterpolate4(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 4, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 4, prefix, i0,
i1, i2, suffix);
}
return ɵɵpropertyInterpolate4;
Expand Down Expand Up @@ -283,7 +283,7 @@ export function ɵɵpropertyInterpolate5(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 5, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 5, prefix, i0,
i1, i2, i3, suffix);
}
return ɵɵpropertyInterpolate5;
Expand Down Expand Up @@ -339,7 +339,7 @@ export function ɵɵpropertyInterpolate6(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 6, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 6, prefix, i0,
i1, i2, i3, i4, suffix);
}
return ɵɵpropertyInterpolate6;
Expand Down Expand Up @@ -397,7 +397,7 @@ export function ɵɵpropertyInterpolate7(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 7, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 7, prefix, i0,
i1, i2, i3, i4, i5, suffix);
}
return ɵɵpropertyInterpolate7;
Expand Down Expand Up @@ -457,7 +457,7 @@ export function ɵɵpropertyInterpolate8(
const nodeIndex = getSelectedIndex();
elementPropertyInternal(lView, nodeIndex, propName, interpolatedValue, sanitizer);
ngDevMode && storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName, lView[BINDING_INDEX] - 8, prefix, i0,
lView[TVIEW].data, nodeIndex, propName, getBindingIndex(lView) - 8, prefix, i0,
i1, i2, i3, i4, i5, i6, suffix);
}
return ɵɵpropertyInterpolate8;
Expand Down Expand Up @@ -507,7 +507,7 @@ export function ɵɵpropertyInterpolateV(
}
storePropertyBindingMetadata(
lView[TVIEW].data, nodeIndex, propName,
lView[BINDING_INDEX] - interpolationInBetween.length + 1, ...interpolationInBetween);
getBindingIndex(lView) - interpolationInBetween.length + 1, ...interpolationInBetween);
}
}
return ɵɵpropertyInterpolateV;
Expand Down

0 comments on commit 787bfa8

Please sign in to comment.