Skip to content

Commit c8cee3b

Browse files
committed
fixup! refactor(core): implement ɵɵforeignComponent instruction
1 parent a4915d8 commit c8cee3b

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

packages/core/src/interface/foreign_component.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,16 @@
99
/** Symbol used to store and retrieve the render function for a foreign component. */
1010
export const RENDER: unique symbol = Symbol('RENDER');
1111

12-
/**
13-
* A function returned by a {@link ForeignRenderFn} to perform cleanup when the
14-
* component is destroyed.
15-
*/
16-
export type DisposeFn = () => void;
17-
1812
/**
1913
* A function used to render a foreign component in an Angular template.
2014
*
2115
* The function accepts the component's properties as its only argument. It should return an array
22-
* of nodes rendered and owned by the foreign component. It may also return a {@link DisposeFn} to
23-
* be called when the component is destroyed.
16+
* of nodes rendered and owned by the foreign component. It may also return a callback to perform
17+
* any necessary cleanup when the component is destroyed.
2418
*
2519
* @template TProps The properties of the foreign component.
2620
*/
27-
export type ForeignRenderFn<TProps> = (props: TProps) => [Node[], DisposeFn?];
21+
export type ForeignRenderFn<TProps> = (props: TProps) => [Node[], VoidFunction?];
2822

2923
/**
3024
* Represents a component from another framework that Angular can import and render.

packages/core/src/render3/instructions/foreign_component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import {createForeignView} from '../foreign_view';
1212
import {TContainerNode, TNodeType} from '../interfaces/node';
1313
import {HEADER_OFFSET, RENDERER} from '../interfaces/view';
1414
import {appendChild} from '../node_manipulation';
15+
import {nativeInsertBefore} from '../dom_node_manipulation';
1516
import {getLView, getTView, setCurrentTNode, setCurrentTNodeAsNotParent} from '../state';
1617
import {getOrCreateTNode} from '../tnode_manipulation';
1718
import {addToEndOfViewTree} from '../view/construction';
1819
import {createLContainer} from '../view/container';
1920
import {NodeInjector} from '../di';
2021
import {runInInjectionContext} from '../../di';
22+
import {Renderer} from '../interfaces/renderer';
23+
import {RNode} from '../interfaces/renderer_dom';
2124

2225
/**
2326
* Creation phase instruction to render a foreign component.
@@ -48,7 +51,7 @@ export function ɵɵforeignComponent(
4851
}
4952

5053
// 2. Create the anchor node in the DOM
51-
const renderer = lView[RENDERER];
54+
const renderer = lView[RENDERER] as Renderer;
5255
const comment = renderer.createComment(ngDevMode ? 'foreign-component' : '');
5356
appendChild(tView, lView, comment, tNode);
5457
attachPatchData(comment, lView);
@@ -66,11 +69,11 @@ export function ɵɵforeignComponent(
6669
const [nodes, dispose] = runInInjectionContext(injector, () => foreignComponent[RENDER](props));
6770

6871
// 6. Insert the returned nodes into the foreign view, between its head and tail comment anchors.
69-
const tail = viewRef.tail;
70-
const parentNode = tail.parentNode;
71-
if (parentNode) {
72+
const tail = viewRef.tail as RNode;
73+
const parent = tail.parentElement;
74+
if (parent) {
7275
for (let i = 0; i < nodes.length; i++) {
73-
parentNode.insertBefore(nodes[i], tail);
76+
nativeInsertBefore(renderer, parent, nodes[i], tail, false);
7477
}
7578
}
7679

0 commit comments

Comments
 (0)