refactor(ivy): generate pipe names instead of defs (#23104)

PR Close #23104
This commit is contained in:
Kara Erickson
2018-03-30 16:07:37 -07:00
committed by Alex Rickabaugh
parent 43d62029f0
commit 85d3b591b6
6 changed files with 59 additions and 76 deletions

View File

@ -16,11 +16,10 @@ import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction
* Create a pipe.
*
* @param index Pipe index where the pipe will be stored.
* @param pipeDef Pipe definition object for registering life cycle hooks.
* @param firstInstance (optional) The first instance of the pipe that can be reused for pure pipes.
* @param pipeName The name of the pipe
* @returns T the instance of the pipe.
*/
export function pipe(index: number, pipeName: string, firstInstance?: any): any {
export function pipe(index: number, pipeName: string): any {
const tView = getTView();
let pipeDef: PipeDef<any>;
@ -34,7 +33,7 @@ export function pipe(index: number, pipeName: string, firstInstance?: any): any
pipeDef = tView.data[index] as PipeDef<any>;
}
const pipeInstance = pipeDef.pure && firstInstance ? firstInstance : pipeDef.n();
const pipeInstance = pipeDef.n();
store(index, pipeInstance);
return pipeInstance;
}

View File

@ -155,12 +155,11 @@ describe('pipes', () => {
selectors: [['my-app']],
factory: function MyApp_Factory() { return new MyApp(); },
template: function MyApp_Template(ctx: $MyApp$, cm: $boolean$) {
let $pi$: $any$;
if (cm) {
$r3$.ɵT(0);
$pi$ = $r3$.ɵPp(1, 'myPurePipe');
$r3$.ɵPp(1, 'myPurePipe');
$r3$.ɵT(2);
$r3$.ɵPp(3, 'myPurePipe', $pi$);
$r3$.ɵPp(3, 'myPurePipe');
$r3$.ɵC(4, C4, '', ['oneTimeIf', '']);
}
$r3$.ɵt(0, $r3$.ɵi1('', $r3$.ɵpb2(1, ctx.name, ctx.size), ''));
@ -173,7 +172,7 @@ describe('pipes', () => {
if (cm) {
$r3$.ɵE(0, 'div');
$r3$.ɵT(1);
$r3$.ɵPp(2, 'myPurePipe', $pi$);
$r3$.ɵPp(2, 'myPurePipe');
$r3$.ɵe();
}
$r3$.ɵt(1, $r3$.ɵi1('', $r3$.ɵpb2(2, ctx.name, ctx.size), ''));

View File

@ -183,49 +183,6 @@ describe('pipe', () => {
expect(renderToHtml(Template, person, null, defs)).toEqual('bart state:2');
expect(renderToHtml(Template, person, null, defs)).toEqual('bart state:2');
});
it('should cache pure pipes', () => {
function Template(ctx: any, cm: boolean) {
let pipeInstance: any;
if (cm) {
elementStart(0, 'div');
pipeInstance = pipe(1, 'countingPipe');
elementEnd();
elementStart(2, 'div');
pipe(3, 'countingPipe', pipeInstance);
elementEnd();
container(4);
}
elementProperty(0, 'someProp', bind(pipeBind1(1, true)));
elementProperty(2, 'someProp', bind(pipeBind1(3, true)));
pipeInstances.push(load<CountingPipe>(1), load(3));
containerRefreshStart(4);
{
for (let i of [1, 2]) {
let cm1 = embeddedViewStart(1);
{
if (cm1) {
elementStart(0, 'div');
pipe(1, 'countingPipe', pipeInstance);
elementEnd();
}
elementProperty(0, 'someProp', bind(pipeBind1(1, true)));
pipeInstances.push(load<CountingPipe>(1));
}
embeddedViewEnd();
}
}
containerRefreshEnd();
}
const pipeInstances: CountingPipe[] = [];
renderToHtml(Template, {}, null, defs, rendererFactory2);
expect(pipeInstances.length).toEqual(4);
expect(pipeInstances[0]).toBeAnInstanceOf(CountingPipe);
expect(pipeInstances[1]).toBe(pipeInstances[0]);
expect(pipeInstances[2]).toBe(pipeInstances[0]);
expect(pipeInstances[3]).toBe(pipeInstances[0]);
});
});
describe('impure', () => {