Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ivy): rename bindX() functions to interpolationX() #22229

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/benchmarks/src/tree/render3/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ɵC as C, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵb1 as b1, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵp as p, ɵr as r, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
import {ɵC as C, ɵE as E, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵi1 as i1, ɵp as p, ɵr as r, ɵs as s, ɵt as t, ɵv as v} from '@angular/core';
import {ComponentDef} from '@angular/core/src/render3/interfaces/definition';

import {TreeNode, buildTree, emptyTree} from '../util';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class TreeComponent {
C(3);
}
s(0, 'background-color', b(ctx.data.depth % 2 ? '' : 'grey'));
t(1, b1(' ', ctx.data.value, ' '));
t(1, i1(' ', ctx.data.value, ' '));
cR(2);
{
if (ctx.data.left != null) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export function TreeTpl(ctx: TreeNode, cm: boolean) {
e();
}
s(1, 'background-color', b(ctx.depth % 2 ? '' : 'grey'));
t(2, b1(' ', ctx.value, ' '));
t(2, i1(' ', ctx.value, ' '));
cR(3);
{
if (ctx.left != null) {
Expand Down
18 changes: 9 additions & 9 deletions packages/compiler/src/render3/r3_identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export class Identifiers {

static bind: o.ExternalReference = {name: 'ɵb', moduleName: CORE};

static bind1: o.ExternalReference = {name: 'ɵb1', moduleName: CORE};
static bind2: o.ExternalReference = {name: 'ɵb2', moduleName: CORE};
static bind3: o.ExternalReference = {name: 'ɵb3', moduleName: CORE};
static bind4: o.ExternalReference = {name: 'ɵb4', moduleName: CORE};
static bind5: o.ExternalReference = {name: 'ɵb5', moduleName: CORE};
static bind6: o.ExternalReference = {name: 'ɵb6', moduleName: CORE};
static bind7: o.ExternalReference = {name: 'ɵb7', moduleName: CORE};
static bind8: o.ExternalReference = {name: 'ɵb8', moduleName: CORE};
static bindV: o.ExternalReference = {name: 'ɵbV', moduleName: CORE};
static interpolation1: o.ExternalReference = {name: 'ɵi1', moduleName: CORE};
static interpolation2: o.ExternalReference = {name: 'ɵi2', moduleName: CORE};
static interpolation3: o.ExternalReference = {name: 'ɵi3', moduleName: CORE};
static interpolation4: o.ExternalReference = {name: 'ɵi4', moduleName: CORE};
static interpolation5: o.ExternalReference = {name: 'ɵi5', moduleName: CORE};
static interpolation6: o.ExternalReference = {name: 'ɵi6', moduleName: CORE};
static interpolation7: o.ExternalReference = {name: 'ɵi7', moduleName: CORE};
static interpolation8: o.ExternalReference = {name: 'ɵi8', moduleName: CORE};
static interpolationV: o.ExternalReference = {name: 'ɵiV', moduleName: CORE};

static memory: o.ExternalReference = {name: 'ɵm', moduleName: CORE};

Expand Down
18 changes: 9 additions & 9 deletions packages/compiler/src/render3/r3_view_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,25 @@ function interpolate(args: o.Expression[]): o.Expression {
args = args.slice(1); // Ignore the length prefix added for render2
switch (args.length) {
case 3:
return o.importExpr(R3.bind1).callFn(args);
return o.importExpr(R3.interpolation1).callFn(args);
case 5:
return o.importExpr(R3.bind2).callFn(args);
return o.importExpr(R3.interpolation2).callFn(args);
case 7:
return o.importExpr(R3.bind3).callFn(args);
return o.importExpr(R3.interpolation3).callFn(args);
case 9:
return o.importExpr(R3.bind4).callFn(args);
return o.importExpr(R3.interpolation4).callFn(args);
case 11:
return o.importExpr(R3.bind5).callFn(args);
return o.importExpr(R3.interpolation5).callFn(args);
case 13:
return o.importExpr(R3.bind6).callFn(args);
return o.importExpr(R3.interpolation6).callFn(args);
case 15:
return o.importExpr(R3.bind7).callFn(args);
return o.importExpr(R3.interpolation7).callFn(args);
case 17:
return o.importExpr(R3.bind8).callFn(args);
return o.importExpr(R3.interpolation8).callFn(args);
}
(args.length >= 19 && args.length % 2 == 1) ||
error(`Invalid interpolation argument length ${args.length}`);
return o.importExpr(R3.bindV).callFn([o.literalArr(args)]);
return o.importExpr(R3.interpolationV).callFn([o.literalArr(args)]);
}

class BindingScope {
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler/test/render3/r3_view_compiler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('r3_view_compiler', () => {
}
};

const bV_call = `$r3$.ɵbV([' ',ctx.list[0],' ',ctx.list[1],' ',ctx.list[2],' ',ctx.list[3],
const bV_call = `$r3$.ɵiV([' ',ctx.list[0],' ',ctx.list[1],' ',ctx.list[2],' ',ctx.list[3],
' ',ctx.list[4],' ',ctx.list[5],' ',ctx.list[6],' ',ctx.list[7],' ',ctx.list[8],
' '])`;
const result = compile(files, angularFiles);
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵT(1);
$r3$.ɵe();
}
$r3$.ɵt(1, $r3$.ɵb2('', ctx.salutation, ' ', $foo$, ''));
$r3$.ɵt(1, $r3$.ɵi2('', ctx.salutation, ' ', $foo$, ''));
}
}
});`;
Expand Down Expand Up @@ -421,7 +421,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵT(2);
}
const $user$ = $r3$.ɵm(1);
$r3$.ɵt(2, $r3$.ɵb1('Hello ', $user$.value, '!'));
$r3$.ɵt(2, $r3$.ɵi1('Hello ', $user$.value, '!'));
}
});
`;
Expand Down Expand Up @@ -634,7 +634,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵe();
}
const $item$ = ctx0.$implicit;
$r3$.ɵt(1, $r3$.ɵb1('', $item$.name, ''));
$r3$.ɵt(1, $r3$.ɵi1('', $item$.name, ''));
}
}
});
Expand Down Expand Up @@ -719,7 +719,7 @@ describe('r3_view_compiler', () => {
const $item$ = ctx0.$implicit;
$r3$.ɵp(4, 'forOf', $r3$.ɵb(IDENT.infos));
$c2$.h(5,4);
$r3$.ɵt(2, $r3$.ɵb1('', IDENT.name, ''));
$r3$.ɵt(2, $r3$.ɵi1('', IDENT.name, ''));
$r3$.ɵcR(4);
$r3$.ɵr(5, 4);
$r3$.ɵcr();
Expand All @@ -732,7 +732,7 @@ describe('r3_view_compiler', () => {
$r3$.ɵe();
}
const $info$ = ctx1.$implicit;
$r3$.ɵt(1, $r3$.ɵb2(' ', $item$.name, ': ', $info$.description, ' '));
$r3$.ɵt(1, $r3$.ɵi2(' ', $item$.name, ': ', $info$.description, ' '));
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/core_render3_private_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export {
Q as ɵQ,
P as ɵP,
b as ɵb,
b1 as ɵb1,
b2 as ɵb2,
b3 as ɵb3,
b4 as ɵb4,
b5 as ɵb5,
b6 as ɵb6,
b7 as ɵb7,
b8 as ɵb8,
bV as ɵbV,
i1 as ɵi1,
i2 as ɵi2,
i3 as ɵi3,
i4 as ɵi4,
i5 as ɵi5,
i6 as ɵi6,
i7 as ɵi7,
i8 as ɵi8,
iV as ɵiV,
pb1 as ɵpb1,
pb2 as ɵpb2,
pb3 as ɵpb3,
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/render3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export {
NO_CHANGE as NC,

bind as b,
bind1 as b1,
bind2 as b2,
bind3 as b3,
bind4 as b4,
bind5 as b5,
bind6 as b6,
bind7 as b7,
bind8 as b8,
bindV as bV,
interpolation1 as i1,
interpolation2 as i2,
interpolation3 as i3,
interpolation4 as i4,
interpolation5 as i5,
interpolation6 as i6,
interpolation7 as i7,
interpolation8 as i8,
interpolationV as iV,

componentRefresh as r,

Expand Down
117 changes: 61 additions & 56 deletions packages/core/src/render3/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, Objec
import {isDifferent, stringify} from './util';
import {executeHooks, executeContentHooks, queueLifecycleHooks, queueInitHooks, executeInitHooks} from './hooks';


/**
* Directive (D) sets a property on all component instances using this constant as a key and the
* component's host node (LElement) as the value. This is used in methods like detectChanges to
Expand Down Expand Up @@ -1347,9 +1346,9 @@ export function addToViewTree<T extends LView|LContainer>(state: T): T {
return state;
}

//////////////////////////
//// Bindings
//////////////////////////
///////////////////////////////
//// Bindings & interpolations
///////////////////////////////

export interface NO_CHANGE {
// This is a brand that ensures that this type can never match anything else
Expand All @@ -1360,16 +1359,53 @@ export interface NO_CHANGE {
export const NO_CHANGE = {} as NO_CHANGE;

/**
* Create interpolation bindings with variable number of arguments.
* Initializes the binding start index. Will get inlined.
*
* This function must be called before any binding related function is called
* (ie `bind()`, `interpolationX()`, `pureFunctionX()`)
*/
function initBindings() {
// `bindingIndex` is initialized when the view is first entered when not in creation mode
ngDevMode &&
assertEqual(
creationMode, true, 'should only be called in creationMode for performance reasons');
if (currentView.bindingStartIndex == null) {
bindingIndex = currentView.bindingStartIndex = data.length;
}
}

/**
* Creates a single value binding.
*
* @param value Value to diff
*/
export function bind<T>(value: T | NO_CHANGE): T|NO_CHANGE {
if (creationMode) {
initBindings();
return data[bindingIndex++] = value;
}

const changed: boolean = value !== NO_CHANGE && isDifferent(data[bindingIndex], value);
if (changed) {
data[bindingIndex] = value;
}
bindingIndex++;
return changed ? value : NO_CHANGE;
}

/**
* Create interpolation bindings with a variable number of expressions.
*
* If any of the arguments change, then the interpolation is concatenated
* and causes an update.
* If there are 1 to 7 expressions `interpolation1()` to `interpolation7` should be used instead.
* Those are faster because there is no need to create an array of expressions and loop over it.
*
* `values`:
* - has static text at even indexes,
* - has evaluated expressions at odd indexes (could be NO_CHANGE).
*
* Returns the concatenated string when any of the arguments changes, `NO_CHANGE` otherwise.
*/
export function bindV(values: any[]): string|NO_CHANGE {
export function interpolationV(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');

Expand Down Expand Up @@ -1405,51 +1441,20 @@ export function bindV(values: any[]): string|NO_CHANGE {
return NO_CHANGE;
}

// For bindings that have 0 - 7 dynamic values to watch, we can use a bind function that
// matches the number of interpolations. This is faster than using the bindV function above
// because we know ahead of time how many interpolations we'll have and don't need to
// accept the values as an array that will need to be copied and looped over.

// Initializes the binding start index. Will get inlined.
function initBindings() {
if (currentView.bindingStartIndex == null) {
bindingIndex = currentView.bindingStartIndex = data.length;
}
}

/**
* Creates a single value binding without interpolation.
*
* @param value Value to diff
*/
export function bind<T>(value: T | NO_CHANGE): T|NO_CHANGE {
if (creationMode) {
initBindings();
return data[bindingIndex++] = value;
}

const changed: boolean = value !== NO_CHANGE && isDifferent(data[bindingIndex], value);
if (changed) {
data[bindingIndex] = value;
}
bindingIndex++;
return changed ? value : NO_CHANGE;
}

/**
* Creates an interpolation bindings with 1 argument.
* Creates an interpolation binding with 1 expression.
*
* @param prefix static value used for concatenation only.
* @param value value checked for change.
* @param suffix static value used for concatenation only.
*/
export function bind1(prefix: string, value: any, suffix: string): string|NO_CHANGE {
export function interpolation1(prefix: string, value: any, suffix: string): string|NO_CHANGE {
return bind(value) === NO_CHANGE ? NO_CHANGE : prefix + stringify(value) + suffix;
}

/** Creates an interpolation bindings with 2 arguments. */
export function bind2(prefix: string, v0: any, i0: string, v1: any, suffix: string): string|
NO_CHANGE {
/** Creates an interpolation binding with 2 expressions. */
export function interpolation2(
prefix: string, v0: any, i0: string, v1: any, suffix: string): string|NO_CHANGE {
let different: boolean;
if (different = creationMode) {
initBindings();
Expand All @@ -1468,8 +1473,8 @@ export function bind2(prefix: string, v0: any, i0: string, v1: any, suffix: stri
return different ? prefix + stringify(v0) + i0 + stringify(v1) + suffix : NO_CHANGE;
}

/** Creates an interpolation bindings with 3 arguments. */
export function bind3(
/** Creates an interpolation bindings with 3 expressions. */
export function interpolation3(
prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, suffix: string): string|
NO_CHANGE {
let different: boolean;
Expand All @@ -1495,8 +1500,8 @@ export function bind3(
NO_CHANGE;
}

/** Create an interpolation binding with 4 arguments. */
export function bind4(
/** Create an interpolation binding with 4 expressions. */
export function interpolation4(
prefix: string, v0: any, i0: string, v1: any, i1: string, v2: any, i2: string, v3: any,
suffix: string): string|NO_CHANGE {
let different: boolean;
Expand Down Expand Up @@ -1530,8 +1535,8 @@ export function bind4(
NO_CHANGE;
}

/** Creates an interpolation binding with 5 arguments. */
export function bind5(
/** Creates an interpolation binding with 5 expressions. */
export function interpolation5(
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 {
let different: boolean;
Expand Down Expand Up @@ -1570,8 +1575,8 @@ export function bind5(
NO_CHANGE;
}

/** Creates an interpolation binding with 6 arguments. */
export function bind6(
/** Creates an interpolation binding with 6 expressions. */
export function interpolation6(
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 {
let different: boolean;
Expand Down Expand Up @@ -1614,8 +1619,8 @@ export function bind6(
NO_CHANGE;
}

/** Creates an interpolation binding with 7 arguments. */
export function bind7(
/** Creates an interpolation binding with 7 expressions. */
export function interpolation7(
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 {
Expand Down Expand Up @@ -1663,8 +1668,8 @@ export function bind7(
NO_CHANGE;
}

/** Creates an interpolation binding with 8 arguments. */
export function bind8(
/** Creates an interpolation binding with 8 expressions. */
export function interpolation8(
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 {
Expand Down