From 06d6c76192bd323e6e95deb4b9ef6a957d62f9eb Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Mon, 29 Jan 2018 09:11:04 -0800 Subject: [PATCH] fix(ivy): compiler should emit new refresh pattern (#21862) Change compiler to reflect changes made in #21650 PR Close #21862 --- packages/compiler/src/render3/r3_identifiers.ts | 1 - .../compiler/src/render3/r3_view_compiler.ts | 9 ++++----- .../test/render3/r3_view_compiler_spec.ts | 16 +++++++--------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/compiler/src/render3/r3_identifiers.ts b/packages/compiler/src/render3/r3_identifiers.ts index b3f6f6c221..320742d23b 100644 --- a/packages/compiler/src/render3/r3_identifiers.ts +++ b/packages/compiler/src/render3/r3_identifiers.ts @@ -21,7 +21,6 @@ export class Identifiers { /* Methods */ static NEW_METHOD = 'n'; static HOST_BINDING_METHOD = 'h'; - static REFRESH_METHOD = 'r'; /* Instructions */ static createElement: o.ExternalReference = {name: 'ɵE', moduleName: CORE}; diff --git a/packages/compiler/src/render3/r3_view_compiler.ts b/packages/compiler/src/render3/r3_view_compiler.ts index ac221ca507..4b60e9048f 100644 --- a/packages/compiler/src/render3/r3_view_compiler.ts +++ b/packages/compiler/src/render3/r3_view_compiler.ts @@ -464,11 +464,10 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver { o.importExpr(R3.bind).callFn([convertedBinding.currValExpr])); } - // e.g. TodoComponentDef.r(0, 0); - this._refreshMode.push( - this.definitionOf(directiveType, kind) - .callMethod(R3.REFRESH_METHOD, [o.literal(directiveIndex), o.literal(nodeIndex)]) - .toStmt()); + // e.g. r(0, 0); + this.instruction( + this._refreshMode, directive.sourceSpan, R3.refreshComponent, o.literal(directiveIndex), + o.literal(nodeIndex)); } } diff --git a/packages/compiler/test/render3/r3_view_compiler_spec.ts b/packages/compiler/test/render3/r3_view_compiler_spec.ts index 85a16df230..478bb86145 100644 --- a/packages/compiler/test/render3/r3_view_compiler_spec.ts +++ b/packages/compiler/test/render3/r3_view_compiler_spec.ts @@ -208,8 +208,8 @@ describe('r3_view_compiler', () => { IDENT.ɵe(); IDENT.ɵT(3, '!'); } - ChildComponent.ngComponentDef.r(1, 0); - SomeDirective.ngDirectiveDef.r(2, 0); + IDENT.ɵr(1, 0); + IDENT.ɵr(2, 0); } }); `; @@ -272,7 +272,7 @@ describe('r3_view_compiler', () => { } const IDENT = IDENT.ɵm(1); IDENT.ɵcR(2); - IfDirective.ngDirectiveDef.r(3,2); + IDENT.ɵr(3,2); IDENT.ɵcr(); function MyComponent_IfDirective_Template_2(ctx0: IDENT, cm: IDENT) { @@ -495,13 +495,11 @@ describe('r3_view_compiler', () => { // TODO(chuckj): Enforce this when the directives are specified const ForDirectiveDefinition = ` static ngDirectiveDef = IDENT.ɵdefineDirective({ + type: ForOfDirective, factory: function ForOfDirective_Factory() { return new ForOfDirective(IDENT.ɵinjectViewContainerRef(), IDENT.ɵinjectTemplateRef()); }, features: [IDENT.ɵNgOnChangesFeature(NgForOf)], - refresh: function ForOfDirective_Refresh(directiveIndex: IDENT, elementIndex: IDENT) { - IDENT.ɵm(directiveIndex).ngDoCheck(); - }, inputs: {forOf: 'forOf'} }); `; @@ -519,7 +517,7 @@ describe('r3_view_compiler', () => { } IDENT.ɵp(1, 'forOf', IDENT.ɵb(ctx.items)); IDENT.ɵcR(1); - ForOfDirective.ngDirectiveDef.r(2, 1); + IDENT.ɵr(2, 1); IDENT.ɵcr(); function MyComponent_ForOfDirective_Template_1(ctx0: IDENT, cm: IDENT) { @@ -593,7 +591,7 @@ describe('r3_view_compiler', () => { } IDENT.ɵp(1, 'forOf', IDENT.ɵb(ctx.items)); IDENT.ɵcR(1); - IDENT.r(2, 1); + IDENT.ɵr(2, 1); IDENT.ɵcr(); function MyComponent_ForOfDirective_Template_1(ctx0: IDENT, cm: IDENT) { @@ -611,7 +609,7 @@ describe('r3_view_compiler', () => { IDENT.ɵp(4, 'forOf', IDENT.ɵb(IDENT.infos)); IDENT.ɵt(2, IDENT.ɵb1('', IDENT.name, '')); IDENT.ɵcR(4); - IDENT.r(5, 4); + IDENT.ɵr(5, 4); IDENT.ɵcr(); function MyComponent_ForOfDirective_ForOfDirective_Template_4(