Skip to content

Commit

Permalink
fix(ivy): post-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkozlowski-opensource committed Aug 13, 2019
1 parent 420e14b commit 06ffc58
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/render3/i18n.ts
Expand Up @@ -705,7 +705,7 @@ function createDynamicNodeAtIndex(

// We are creating a dynamic node, the previous tNode might not be pointing at this node.
// We will link ourselves into the tree later with `appendI18nNode`.
if (previousOrParentTNode.next === tNode) {
if (previousOrParentTNode && previousOrParentTNode.next === tNode) {
previousOrParentTNode.next = null;
}

Expand Down
32 changes: 15 additions & 17 deletions packages/core/src/render3/instructions/shared.ts
Expand Up @@ -333,8 +333,9 @@ export function renderView<T>(lView: LView, tView: TView, context: T): void {
ngDevMode && assertEqual(isCreationMode(lView), true, 'Should be run in creation mode');
const oldView = enterView(lView, lView[T_HOST]);
try {
if (tView.viewQuery !== null) {
executeViewQueryFn(RenderFlags.Create, tView, context);
const viewQuery = tView.viewQuery;
if (viewQuery !== null) {
executeViewQueryFn(RenderFlags.Create, viewQuery, context);
}

// Execute a template associated with this view, if it exists. A template function might not be
Expand Down Expand Up @@ -364,7 +365,7 @@ export function renderView<T>(lView: LView, tView: TView, context: T): void {
// in case a child component has projected a container. The LContainer needs
// to exist so the embedded views are properly attached by the container.
if (tView.staticViewQueries) {
executeViewQueryFn(RenderFlags.Update, tView, context);
executeViewQueryFn(RenderFlags.Update, tView.viewQuery !, context);
}

// Render child component views.
Expand All @@ -380,8 +381,8 @@ export function renderView<T>(lView: LView, tView: TView, context: T): void {
}

/**
* Processes a view in the update mode. This includes a number of steps in a specific order:
* - executing a template function in the update mode;
* Processes a view in update mode. This includes a number of steps in a specific order:
* - executing a template function in update mode;
* - executing hooks;
* - refreshing queries;
* - setting host bindings;
Expand Down Expand Up @@ -420,8 +421,9 @@ export function refreshView<T>(

setHostBindings(tView, lView);

if (tView.viewQuery !== null) {
executeViewQueryFn(RenderFlags.Update, tView, context);
const viewQuery = tView.viewQuery;
if (viewQuery !== null) {
executeViewQueryFn(RenderFlags.Update, viewQuery, context);
}

// Refresh child component views.
Expand Down Expand Up @@ -1476,8 +1478,7 @@ export function createLContainer(

/**
* Goes over dynamic embedded views (ones created through ViewContainerRef APIs) and refreshes
* them
* by executing an associated template function.
* them by executing an associated template function.
*/
function refreshDynamicEmbeddedViews(lView: LView) {
let viewOrContainer = lView[CHILD_HEAD];
Expand All @@ -1487,8 +1488,6 @@ function refreshDynamicEmbeddedViews(lView: LView) {
if (isLContainer(viewOrContainer) && viewOrContainer[ACTIVE_INDEX] === -1) {
for (let i = CONTAINER_HEADER_OFFSET; i < viewOrContainer.length; i++) {
const embeddedLView = viewOrContainer[i];
// The directives and pipes are not needed here as an existing view is only being
// refreshed.
const embeddedTView = embeddedLView[TVIEW];
ngDevMode && assertDefined(embeddedTView, 'TView must be allocated');
refreshView(embeddedLView, embeddedTView, embeddedTView.template, embeddedLView[CONTEXT] !);
Expand Down Expand Up @@ -1727,12 +1726,11 @@ export function checkNoChangesInRootView(lView: LView): void {
}
}

function executeViewQueryFn<T>(flags: RenderFlags, tView: TView, component: T): void {
const viewQuery = tView.viewQuery;
if (viewQuery !== null) {
setCurrentQueryIndex(0);
viewQuery(flags, component);
}
function executeViewQueryFn<T>(
flags: RenderFlags, viewQueryFn: ViewQueriesFunction<{}>, component: T): void {
ngDevMode && assertDefined(viewQueryFn, 'View queries function to execute must be defined.');
setCurrentQueryIndex(0);
viewQueryFn(flags, component);
}


Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/acceptance/view_container_ref_spec.ts
Expand Up @@ -61,6 +61,25 @@ describe('ViewContainerRef', () => {
expect(fixture.componentInstance.foo).toBeAnInstanceOf(TemplateRef);
});

it('should construct proper TNode / DOM tree when embedded views are created in a directive constructor',
() => {
@Component({
selector: 'view-insertion-test-cmpt',
template:
`<div>before<ng-template constructorDir><span>|middle|</span></ng-template>after</div>`
})
class ViewInsertionTestCmpt {
}

TestBed.configureTestingModule({declarations: [ViewInsertionTestCmpt, ConstructorDir]});

debugger;
const fixture = TestBed.createComponent(ViewInsertionTestCmpt);

expect(fixture.nativeElement.innerHTML)
.toBe('<div>before<span>|middle|</span><!--container-->after</div>');
});

it('should use comment node of host ng-container as insertion marker', () => {
@Component({template: 'hello'})
class HelloComp {
Expand Down

0 comments on commit 06ffc58

Please sign in to comment.