refactor(ivy): rename objectLiteral to pureFn to prep for pipes (#22214)
PR Close #22214
This commit is contained in:
parent
e1bf067090
commit
a73d5308e0
|
@ -21,6 +21,7 @@ export {
|
|||
PublicFeature as ɵPublicFeature,
|
||||
NgOnChangesFeature as ɵNgOnChangesFeature,
|
||||
CssSelector as ɵCssSelector,
|
||||
NC as ɵNC,
|
||||
C as ɵC,
|
||||
E as ɵE,
|
||||
L as ɵL,
|
||||
|
@ -43,15 +44,15 @@ export {
|
|||
pb3 as ɵpb3,
|
||||
pb4 as ɵpb4,
|
||||
pbV as ɵpbV,
|
||||
o1 as ɵo1,
|
||||
o2 as ɵo2,
|
||||
o3 as ɵo3,
|
||||
o4 as ɵo4,
|
||||
o5 as ɵo5,
|
||||
o6 as ɵo6,
|
||||
o7 as ɵo7,
|
||||
o8 as ɵo8,
|
||||
oV as ɵoV,
|
||||
f1 as ɵf1,
|
||||
f2 as ɵf2,
|
||||
f3 as ɵf3,
|
||||
f4 as ɵf4,
|
||||
f5 as ɵf5,
|
||||
f6 as ɵf6,
|
||||
f7 as ɵf7,
|
||||
f8 as ɵf8,
|
||||
fV as ɵfV,
|
||||
cR as ɵcR,
|
||||
cr as ɵcr,
|
||||
qR as ɵqR,
|
||||
|
|
|
@ -79,16 +79,16 @@ export {
|
|||
queryRefresh as qR,
|
||||
} from './query';
|
||||
export {
|
||||
objectLiteral1 as o1,
|
||||
objectLiteral2 as o2,
|
||||
objectLiteral3 as o3,
|
||||
objectLiteral4 as o4,
|
||||
objectLiteral5 as o5,
|
||||
objectLiteral6 as o6,
|
||||
objectLiteral7 as o7,
|
||||
objectLiteral8 as o8,
|
||||
objectLiteralV as oV,
|
||||
} from './object_literal';
|
||||
pureFunction1 as f1,
|
||||
pureFunction2 as f2,
|
||||
pureFunction3 as f3,
|
||||
pureFunction4 as f4,
|
||||
pureFunction5 as f5,
|
||||
pureFunction6 as f6,
|
||||
pureFunction7 as f7,
|
||||
pureFunction8 as f8,
|
||||
pureFunctionV as fV,
|
||||
} from './pure_function';
|
||||
|
||||
|
||||
// clang-format on
|
||||
|
|
|
@ -9,31 +9,31 @@
|
|||
import {NO_CHANGE, bind, peekBinding} from './instructions';
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with the updated expression.
|
||||
* Or if the expression hasn't changed, returns NO_CHANGE.
|
||||
* If the value of the provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if the value has not changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn Function that returns an updated instance of the object/array
|
||||
* @param pureFn Function that returns an updated value
|
||||
* @param exp Updated expression value
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral1(factoryFn: (v: any) => any, exp: any): any {
|
||||
export function pureFunction1(pureFn: (v: any) => any, exp: any): any {
|
||||
let different = false;
|
||||
const latestValue = exp === NO_CHANGE ? peekBinding() : exp;
|
||||
if (bind(exp) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(latestValue) : NO_CHANGE;
|
||||
return different ? pureFn(latestValue) : NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral2(factoryFn: (v1: any, v2: any) => any, exp1: any, exp2: any): any {
|
||||
export function pureFunction2(pureFn: (v1: any, v2: any) => any, exp1: any, exp2: any): any {
|
||||
let different = false;
|
||||
|
||||
const latestVal1 = exp1 === NO_CHANGE ? peekBinding() : exp1;
|
||||
|
@ -42,21 +42,21 @@ export function objectLiteral2(factoryFn: (v1: any, v2: any) => any, exp1: any,
|
|||
const latestVal2 = exp2 === NO_CHANGE ? peekBinding() : exp2;
|
||||
if (bind(exp2) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(latestVal1, latestVal2) : NO_CHANGE;
|
||||
return different ? pureFn(latestVal1, latestVal2) : NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral3(
|
||||
factoryFn: (v1: any, v2: any, v3: any) => any, exp1: any, exp2: any, exp3: any): any {
|
||||
export function pureFunction3(
|
||||
pureFn: (v1: any, v2: any, v3: any) => any, exp1: any, exp2: any, exp3: any): any {
|
||||
let different = false;
|
||||
|
||||
const latestVal1 = exp1 === NO_CHANGE ? peekBinding() : exp1;
|
||||
|
@ -68,22 +68,22 @@ export function objectLiteral3(
|
|||
const latestVal3 = exp3 === NO_CHANGE ? peekBinding() : exp3;
|
||||
if (bind(exp3) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(latestVal1, latestVal2, latestVal3) : NO_CHANGE;
|
||||
return different ? pureFn(latestVal1, latestVal2, latestVal3) : NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
* @param exp4
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral4(
|
||||
factoryFn: (v1: any, v2: any, v3: any, v4: any) => any, exp1: any, exp2: any, exp3: any,
|
||||
export function pureFunction4(
|
||||
pureFn: (v1: any, v2: any, v3: any, v4: any) => any, exp1: any, exp2: any, exp3: any,
|
||||
exp4: any): any {
|
||||
let different = false;
|
||||
|
||||
|
@ -99,24 +99,24 @@ export function objectLiteral4(
|
|||
const latestVal4 = exp4 === NO_CHANGE ? peekBinding() : exp4;
|
||||
if (bind(exp4) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(latestVal1, latestVal2, latestVal3, latestVal4) : NO_CHANGE;
|
||||
return different ? pureFn(latestVal1, latestVal2, latestVal3, latestVal4) : NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
* @param exp4
|
||||
* @param exp5
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral5(
|
||||
factoryFn: (v1: any, v2: any, v3: any, v4: any, v5: any) => any, exp1: any, exp2: any,
|
||||
exp3: any, exp4: any, exp5: any): any {
|
||||
export function pureFunction5(
|
||||
pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any) => any, exp1: any, exp2: any, exp3: any,
|
||||
exp4: any, exp5: any): any {
|
||||
let different = false;
|
||||
|
||||
const latestVal1 = exp1 === NO_CHANGE ? peekBinding() : exp1;
|
||||
|
@ -134,25 +134,24 @@ export function objectLiteral5(
|
|||
const latestVal5 = exp5 === NO_CHANGE ? peekBinding() : exp5;
|
||||
if (bind(exp5) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(latestVal1, latestVal2, latestVal3, latestVal4, latestVal5) :
|
||||
NO_CHANGE;
|
||||
return different ? pureFn(latestVal1, latestVal2, latestVal3, latestVal4, latestVal5) : NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
* @param exp4
|
||||
* @param exp5
|
||||
* @param exp6
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral6(
|
||||
factoryFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any) => any, exp1: any, exp2: any,
|
||||
export function pureFunction6(
|
||||
pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any) => any, exp1: any, exp2: any,
|
||||
exp3: any, exp4: any, exp5: any, exp6: any): any {
|
||||
let different = false;
|
||||
|
||||
|
@ -175,15 +174,15 @@ export function objectLiteral6(
|
|||
if (bind(exp6) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ?
|
||||
factoryFn(latestVal1, latestVal2, latestVal3, latestVal4, latestVal5, latestVal6) :
|
||||
pureFn(latestVal1, latestVal2, latestVal3, latestVal4, latestVal5, latestVal6) :
|
||||
NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
|
@ -191,10 +190,10 @@ export function objectLiteral6(
|
|||
* @param exp5
|
||||
* @param exp6
|
||||
* @param exp7
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral7(
|
||||
factoryFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any) => any, exp1: any,
|
||||
export function pureFunction7(
|
||||
pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any) => any, exp1: any,
|
||||
exp2: any, exp3: any, exp4: any, exp5: any, exp6: any, exp7: any): any {
|
||||
let different = false;
|
||||
|
||||
|
@ -220,16 +219,15 @@ export function objectLiteral7(
|
|||
if (bind(exp7) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ?
|
||||
factoryFn(
|
||||
latestVal1, latestVal2, latestVal3, latestVal4, latestVal5, latestVal6, latestVal7) :
|
||||
pureFn(latestVal1, latestVal2, latestVal3, latestVal4, latestVal5, latestVal6, latestVal7) :
|
||||
NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn
|
||||
* @param pureFn
|
||||
* @param exp1
|
||||
* @param exp2
|
||||
* @param exp3
|
||||
|
@ -238,10 +236,10 @@ export function objectLiteral7(
|
|||
* @param exp6
|
||||
* @param exp7
|
||||
* @param exp8
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteral8(
|
||||
factoryFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any, v8: any) => any,
|
||||
export function pureFunction8(
|
||||
pureFn: (v1: any, v2: any, v3: any, v4: any, v5: any, v6: any, v7: any, v8: any) => any,
|
||||
exp1: any, exp2: any, exp3: any, exp4: any, exp5: any, exp6: any, exp7: any, exp8: any): any {
|
||||
let different = false;
|
||||
|
||||
|
@ -269,24 +267,24 @@ export function objectLiteral8(
|
|||
const latestVal8 = exp8 === NO_CHANGE ? peekBinding() : exp8;
|
||||
if (bind(exp8) !== NO_CHANGE) different = true;
|
||||
|
||||
return different ? factoryFn(
|
||||
return different ? pureFn(
|
||||
latestVal1, latestVal2, latestVal3, latestVal4, latestVal5, latestVal6,
|
||||
latestVal7, latestVal8) :
|
||||
NO_CHANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* objectLiteral instruction that can support any number of bindings.
|
||||
* pureFunction instruction that can support any number of bindings.
|
||||
*
|
||||
* If the object or array has changed, returns a copy with all updated expressions.
|
||||
* Or if no expressions have changed, returns NO_CHANGE.
|
||||
* If the value of any provided exp has changed, calls the pure function to
|
||||
* return an updated value. Or if no values have changed, returns NO_CHANGE.
|
||||
*
|
||||
* @param factoryFn A factory function that takes binding values and builds an object or array
|
||||
* @param pureFn A pure function that takes binding values and builds an object or array
|
||||
* containing those values.
|
||||
* @param exp An array of binding values
|
||||
* @returns A copy of the object/array or NO_CHANGE
|
||||
* @returns Updated value or NO_CHANGE
|
||||
*/
|
||||
export function objectLiteralV(factoryFn: (v: any[]) => any, exps: any[]): any {
|
||||
export function pureFunctionV(pureFn: (v: any[]) => any, exps: any[]): any {
|
||||
let different = false;
|
||||
|
||||
for (let i = 0; i < exps.length; i++) {
|
||||
|
@ -295,5 +293,5 @@ export function objectLiteralV(factoryFn: (v: any[]) => any, exps: any[]): any {
|
|||
if (bind(exp) !== NO_CHANGE) different = true;
|
||||
}
|
||||
|
||||
return different ? factoryFn(exps) : NO_CHANGE;
|
||||
return different ? pureFn(exps) : NO_CHANGE;
|
||||
}
|
|
@ -190,41 +190,69 @@ describe('compiler specification', () => {
|
|||
});
|
||||
|
||||
describe('value composition', () => {
|
||||
|
||||
it('should support array literals', () => {
|
||||
type $MyComp$ = MyComp;
|
||||
type $MyApp$ = MyApp;
|
||||
type $MyArrayComp$ = MyArrayComp;
|
||||
|
||||
@Component({
|
||||
selector: 'my-comp',
|
||||
selector: 'my-array-comp',
|
||||
template: `
|
||||
<p>{{ names[0] }}</p>
|
||||
<p>{{ names[1] }}</p>
|
||||
{{ names[0] }} {{ names[1] }}
|
||||
`
|
||||
})
|
||||
class MyComp {
|
||||
class MyArrayComp {
|
||||
@Input() names: string[];
|
||||
|
||||
static ngComponentDef = $r3$.ɵdefineComponent({
|
||||
type: MyComp,
|
||||
tag: 'my-comp',
|
||||
factory: function MyComp_Factory() { return new MyComp(); },
|
||||
template: function MyComp_Template(ctx: $MyComp$, cm: $boolean$) {
|
||||
type: MyArrayComp,
|
||||
tag: 'my-array-comp',
|
||||
factory: function MyArrayComp_Factory() { return new MyArrayComp(); },
|
||||
template: function MyArrayComp_Template(ctx: $MyArrayComp$, cm: $boolean$) {
|
||||
if (cm) {
|
||||
$r3$.ɵE(0, 'p');
|
||||
$r3$.ɵT(1);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵE(2, 'p');
|
||||
$r3$.ɵT(3);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵT(0);
|
||||
}
|
||||
$r3$.ɵt(1, $r3$.ɵb(ctx.names[0]));
|
||||
$r3$.ɵt(3, $r3$.ɵb(ctx.names[1]));
|
||||
$r3$.ɵt(0, $r3$.ɵb2('', ctx.names[0], ' ', ctx.names[1], ''));
|
||||
},
|
||||
inputs: {names: 'names'}
|
||||
});
|
||||
}
|
||||
|
||||
it('should support array literals of constants', () => {
|
||||
type $MyApp$ = MyApp;
|
||||
|
||||
// NORMATIVE
|
||||
const $e0_arr$ = ['Nancy', 'Bess'];
|
||||
// /NORMATIVE
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<my-array-comp [names]="['Nancy', 'Bess']"></my-array-comp>
|
||||
`
|
||||
})
|
||||
class MyApp {
|
||||
// NORMATIVE
|
||||
static ngComponentDef = $r3$.ɵdefineComponent({
|
||||
type: MyApp,
|
||||
tag: 'my-app',
|
||||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(ctx: $MyApp$, cm: $boolean$) {
|
||||
if (cm) {
|
||||
$r3$.ɵE(0, MyArrayComp);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
$r3$.ɵp(0, 'names', $r3$.ɵb0($e0_arr$));
|
||||
MyArrayComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵr(1, 0);
|
||||
}
|
||||
});
|
||||
// /NORMATIVE
|
||||
}
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
|
||||
});
|
||||
|
||||
it('should support array literals', () => {
|
||||
type $MyApp$ = MyApp;
|
||||
|
||||
// NORMATIVE
|
||||
const $e0_ff$ = (v: any) => ['Nancy', v];
|
||||
// /NORMATIVE
|
||||
|
@ -232,7 +260,7 @@ describe('compiler specification', () => {
|
|||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<my-comp [names]="['Nancy', customName]"></my-comp>
|
||||
<my-array-comp [names]="['Nancy', customName]"></my-array-comp>
|
||||
`
|
||||
})
|
||||
class MyApp {
|
||||
|
@ -245,18 +273,18 @@ describe('compiler specification', () => {
|
|||
factory: function MyApp_Factory() { return new MyApp(); },
|
||||
template: function MyApp_Template(ctx: $MyApp$, cm: $boolean$) {
|
||||
if (cm) {
|
||||
$r3$.ɵE(0, MyComp);
|
||||
$r3$.ɵE(0, MyArrayComp);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
$r3$.ɵp(0, 'names', $r3$.ɵo1($e0_ff$, ctx.customName));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵp(0, 'names', $r3$.ɵf1($e0_ff$, ctx.customName));
|
||||
MyArrayComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵr(1, 0);
|
||||
}
|
||||
});
|
||||
// /NORMATIVE
|
||||
}
|
||||
|
||||
expect(renderComp(MyApp)).toEqual(`<my-comp><p>Nancy</p><p>Bess</p></my-comp>`);
|
||||
expect(renderComp(MyApp)).toEqual(`<my-array-comp>Nancy Bess</my-array-comp>`);
|
||||
});
|
||||
|
||||
it('should support 9+ bindings in array literals', () => {
|
||||
|
@ -352,7 +380,7 @@ describe('compiler specification', () => {
|
|||
}
|
||||
$r3$.ɵp(
|
||||
0, 'names',
|
||||
$r3$.ɵoV($e0_ff$, [c.n0, c.n1, c.n2, c.n3, c.n4, c.n5, c.n6, c.n7, c.n8]));
|
||||
$r3$.ɵfV($e0_ff$, [c.n0, c.n1, c.n2, c.n3, c.n4, c.n5, c.n6, c.n7, c.n8]));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵr(1, 0);
|
||||
}
|
||||
|
@ -420,7 +448,7 @@ describe('compiler specification', () => {
|
|||
$r3$.ɵE(0, ObjectComp);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
$r3$.ɵp(0, 'config', $r3$.ɵo1($e0_ff$, ctx.name));
|
||||
$r3$.ɵp(0, 'config', $r3$.ɵf1($e0_ff$, ctx.name));
|
||||
ObjectComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵr(1, 0);
|
||||
}
|
||||
|
@ -500,8 +528,8 @@ describe('compiler specification', () => {
|
|||
}
|
||||
$r3$.ɵp(
|
||||
0, 'config',
|
||||
$r3$.ɵo2(
|
||||
$e0_ff_2$, ctx.name, $r3$.ɵo1($e0_ff_1$, $r3$.ɵo1($e0_ff$, ctx.duration))));
|
||||
$r3$.ɵf2(
|
||||
$e0_ff_2$, ctx.name, $r3$.ɵf1($e0_ff_1$, $r3$.ɵf1($e0_ff$, ctx.duration))));
|
||||
NestedComp.ngComponentDef.h(1, 0);
|
||||
$r3$.ɵr(1, 0);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ describe('render3 integration test', () => {
|
|||
if (cm) {
|
||||
text(0);
|
||||
}
|
||||
textBinding(0, cm ? value : NO_CHANGE);
|
||||
textBinding(0, bind0(value));
|
||||
}
|
||||
expect(renderToHtml(Template, 'once')).toEqual('once');
|
||||
expect(renderToHtml(Template, 'twice')).toEqual('once');
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
import {defineComponent} from '../../src/render3/index';
|
||||
import {componentRefresh, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, memory} from '../../src/render3/instructions';
|
||||
import {objectLiteral1, objectLiteral2, objectLiteral3, objectLiteral4, objectLiteral5, objectLiteral6, objectLiteral7, objectLiteral8, objectLiteralV} from '../../src/render3/object_literal';
|
||||
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction5, pureFunction6, pureFunction7, pureFunction8, pureFunctionV} from '../../src/render3/pure_function';
|
||||
import {renderToHtml} from '../../test/render3/render_util';
|
||||
|
||||
describe('array literals', () => {
|
||||
|
@ -32,7 +32,7 @@ describe('array literals', () => {
|
|||
elementStart(0, MyComp);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'names', objectLiteral1(e0_ff, ctx.customName));
|
||||
elementProperty(0, 'names', pureFunction1(e0_ff, ctx.customName));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ describe('array literals', () => {
|
|||
elementStart(0, ManyPropComp);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'names1', objectLiteral1(e0_ff, ctx.customName));
|
||||
elementProperty(0, 'names2', objectLiteral1(e0_ff_1, ctx.customName2));
|
||||
elementProperty(0, 'names1', pureFunction1(e0_ff, ctx.customName));
|
||||
elementProperty(0, 'names2', pureFunction1(e0_ff_1, ctx.customName2));
|
||||
ManyPropComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ describe('array literals', () => {
|
|||
elementStart(0, MyComp);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'names', objectLiteral2(e0_ff, ctx.customName, ctx.customName2));
|
||||
elementProperty(0, 'names', pureFunction2(e0_ff, ctx.customName, ctx.customName2));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
|
@ -129,41 +129,41 @@ describe('array literals', () => {
|
|||
});
|
||||
|
||||
it('should work up to 8 bindings', () => {
|
||||
let o3Comp: MyComp;
|
||||
let o4Comp: MyComp;
|
||||
let o5Comp: MyComp;
|
||||
let o6Comp: MyComp;
|
||||
let o7Comp: MyComp;
|
||||
let o8Comp: MyComp;
|
||||
let f3Comp: MyComp;
|
||||
let f4Comp: MyComp;
|
||||
let f5Comp: MyComp;
|
||||
let f6Comp: MyComp;
|
||||
let f7Comp: MyComp;
|
||||
let f8Comp: MyComp;
|
||||
|
||||
function Template(c: any, cm: boolean) {
|
||||
if (cm) {
|
||||
elementStart(0, MyComp);
|
||||
o3Comp = memory(1);
|
||||
f3Comp = memory(1);
|
||||
elementEnd();
|
||||
elementStart(2, MyComp);
|
||||
o4Comp = memory(3);
|
||||
f4Comp = memory(3);
|
||||
elementEnd();
|
||||
elementStart(4, MyComp);
|
||||
o5Comp = memory(5);
|
||||
f5Comp = memory(5);
|
||||
elementEnd();
|
||||
elementStart(6, MyComp);
|
||||
o6Comp = memory(7);
|
||||
f6Comp = memory(7);
|
||||
elementEnd();
|
||||
elementStart(8, MyComp);
|
||||
o7Comp = memory(9);
|
||||
f7Comp = memory(9);
|
||||
elementEnd();
|
||||
elementStart(10, MyComp);
|
||||
o8Comp = memory(11);
|
||||
f8Comp = memory(11);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'names', objectLiteral3(e0_ff, c[5], c[6], c[7]));
|
||||
elementProperty(2, 'names', objectLiteral4(e2_ff, c[4], c[5], c[6], c[7]));
|
||||
elementProperty(4, 'names', objectLiteral5(e4_ff, c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(6, 'names', objectLiteral6(e6_ff, c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(8, 'names', objectLiteral7(e8_ff, c[1], c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(0, 'names', pureFunction3(e0_ff, c[5], c[6], c[7]));
|
||||
elementProperty(2, 'names', pureFunction4(e2_ff, c[4], c[5], c[6], c[7]));
|
||||
elementProperty(4, 'names', pureFunction5(e4_ff, c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(6, 'names', pureFunction6(e6_ff, c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(8, 'names', pureFunction7(e8_ff, c[1], c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
elementProperty(
|
||||
10, 'names', objectLiteral8(e10_ff, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
10, 'names', pureFunction8(e10_ff, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
MyComp.ngComponentDef.h(3, 2);
|
||||
MyComp.ngComponentDef.h(5, 4);
|
||||
|
@ -193,23 +193,23 @@ describe('array literals', () => {
|
|||
v8: any) => [v1, v2, v3, v4, v5, v6, v7, v8];
|
||||
|
||||
renderToHtml(Template, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']);
|
||||
expect(o3Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(o4Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(o5Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(o6Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(o7Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(o8Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f3Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f4Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f5Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f6Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f7Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
expect(f8Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||
|
||||
renderToHtml(Template, ['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1', 'i1']);
|
||||
expect(o3Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f1', 'g1', 'h1']);
|
||||
expect(o4Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(o5Comp !.names).toEqual(['a', 'b', 'c', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(o6Comp !.names).toEqual(['a', 'b', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(o7Comp !.names).toEqual(['a', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(o8Comp !.names).toEqual(['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(f3Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e', 'f1', 'g1', 'h1']);
|
||||
expect(f4Comp !.names).toEqual(['a', 'b', 'c', 'd', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(f5Comp !.names).toEqual(['a', 'b', 'c', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(f6Comp !.names).toEqual(['a', 'b', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(f7Comp !.names).toEqual(['a', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
expect(f8Comp !.names).toEqual(['a1', 'b1', 'c1', 'd1', 'e1', 'f1', 'g1', 'h1']);
|
||||
});
|
||||
|
||||
it('should work with objectLiteralV for 9+ bindings', () => {
|
||||
it('should work with pureFunctionV for 9+ bindings', () => {
|
||||
/**
|
||||
* <my-comp [names]="['start', v0, v1, v2, v3, {name: v4}, v5, v6, v7, v8, 'end']">
|
||||
* </my-comp>
|
||||
|
@ -219,9 +219,8 @@ describe('array literals', () => {
|
|||
elementStart(0, MyComp);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(
|
||||
0, 'names', objectLiteralV(e0_ff, [
|
||||
c[0], c[1], c[2], c[3], objectLiteral1(e0_ff_1, c[4]), c[5], c[6], c[7], c[8]
|
||||
elementProperty(0, 'names', pureFunctionV(e0_ff, [
|
||||
c[0], c[1], c[2], c[3], pureFunction1(e0_ff_1, c[4]), c[5], c[6], c[7], c[8]
|
||||
]));
|
||||
MyComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
|
@ -271,7 +270,7 @@ describe('object literals', () => {
|
|||
elementStart(0, ObjectComp);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'config', objectLiteral1(e0_ff, ctx.name));
|
||||
elementProperty(0, 'config', pureFunction1(e0_ff, ctx.name));
|
||||
ObjectComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
|
@ -306,8 +305,8 @@ describe('object literals', () => {
|
|||
}
|
||||
elementProperty(
|
||||
0, 'config',
|
||||
objectLiteral2(
|
||||
e0_ff, ctx.name, objectLiteral1(e0_ff_1, objectLiteral1(e0_ff_2, ctx.duration))));
|
||||
pureFunction2(
|
||||
e0_ff, ctx.name, pureFunction1(e0_ff_1, pureFunction1(e0_ff_2, ctx.duration))));
|
||||
ObjectComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
}
|
||||
|
@ -372,7 +371,7 @@ describe('object literals', () => {
|
|||
elementEnd();
|
||||
}
|
||||
elementProperty(
|
||||
0, 'config', objectLiteral2(e0_ff, ctx.configs[i].opacity, ctx.configs[i].duration));
|
||||
0, 'config', pureFunction2(e0_ff, ctx.configs[i].opacity, ctx.configs[i].duration));
|
||||
ObjectComp.ngComponentDef.h(1, 0);
|
||||
componentRefresh(1, 0);
|
||||
embeddedViewEnd();
|
Loading…
Reference in New Issue