Skip to content

Commit 880971c

Browse files
committed
fixup! refactor(core): abstract control flow discovery utilities
1 parent 6724a54 commit 880971c

3 files changed

Lines changed: 7 additions & 35 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export function ɵɵrepeaterTrackByIdentity<T>(_: number, value: T) {
253253
return value;
254254
}
255255

256-
class RepeaterMetadata {
256+
export class RepeaterMetadata {
257257
constructor(
258258
public hasEmptyBlock: boolean,
259259
public trackByFn: TrackByFunction<unknown>,

packages/core/src/render3/util/control_flow.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ import {
4141
ControlFlowBlockType,
4242
DeferBlockData,
4343
ForLoopBlockData,
44-
RepeaterMetadataShape,
4544
} from './control_flow_types';
4645
import {TNode} from '../interfaces/node';
46+
import {RepeaterMetadata} from '../instructions/control_flow';
4747

4848
/**
4949
* Gets all of the control flow blocks that are present inside the specified DOM node.
5050
* @param node Node in which to look for control flow blocks.
51-
*
52-
* @publicApi
5351
*/
5452
export function getControlFlowBlocks(node: Node): ControlFlowBlock[] {
5553
const results: ControlFlowBlock[] = [];
@@ -91,8 +89,6 @@ const deferBlockFinder: ControlFlowBlockViewFinder = ({
9189
const tDetails = getTDeferBlockDetails(tView, tNode);
9290

9391
if (isTDeferBlockDetails(tDetails)) {
94-
// return {lContainer, lView, tNode, tDetails};
95-
9692
const native = getNativeByTNode(tNode, lView);
9793
const lDetails = getLDeferBlockDetails(lView, tNode);
9894

@@ -174,7 +170,7 @@ const forLoopFinder: ControlFlowBlockViewFinder = ({
174170
}: ControlFlowBlockViewFinderConfig) => {
175171
const slot = lView[slotIdx];
176172

177-
if (!isRepeaterMetadata(slot)) {
173+
if (!(slot instanceof RepeaterMetadata)) {
178174
return null;
179175
}
180176

@@ -318,27 +314,13 @@ function getRendererLView(lContainer: LContainer): LView | null {
318314
return lView;
319315
}
320316

321-
/**
322-
* Checks if a value looks like RepeaterMetadata by duck-typing.
323-
* Can't use instanceof because that would require importing from control_flow.ts.
324-
*/
325-
function isRepeaterMetadata(value: unknown): value is RepeaterMetadataShape {
326-
return (
327-
value !== null &&
328-
typeof value === 'object' &&
329-
'hasEmptyBlock' in value &&
330-
'trackByFn' in value &&
331-
typeof (value as RepeaterMetadataShape).trackByFn === 'function'
332-
);
333-
}
334-
335317
/**
336318
* Returns the string representation of the track expression.
337319
*
338320
* @param metadata Metadata containing the track function.
339321
* @returns
340322
*/
341-
function getTrackExpression(metadata: RepeaterMetadataShape): string {
323+
function getTrackExpression(metadata: RepeaterMetadata): string {
342324
const trackByFn = metadata.trackByFn;
343325
if (trackByFn.name === 'ɵɵrepeaterTrackByIndex') {
344326
return '$index';

packages/core/src/render3/util/control_flow_types.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ export interface ControlFlowBlockViewFinderConfig {
9393
/**
9494
* Describes a finder function that extracts `ControlFlowBlock`s from an LView.
9595
*/
96-
export interface ControlFlowBlockViewFinder {
97-
(config: ControlFlowBlockViewFinderConfig): ControlFlowBlock | null;
98-
}
99-
100-
/**
101-
* Represents `RepeaterMetadata` data mirror.
102-
*/
103-
export interface RepeaterMetadataShape {
104-
hasEmptyBlock: boolean;
105-
trackByFn: TrackByFunction<unknown>;
106-
liveCollection?: LiveCollection<unknown, unknown>;
107-
originalTrackByFn?: TrackByFunction<unknown>;
108-
}
96+
export type ControlFlowBlockViewFinder = (
97+
config: ControlFlowBlockViewFinderConfig,
98+
) => ControlFlowBlock | null;

0 commit comments

Comments
 (0)