Skip to content

Commit 18220fb

Browse files
committed
refactor: hide actionable touch indexing
1 parent aa12f07 commit 18220fb

13 files changed

Lines changed: 149 additions & 347 deletions

‎packages/contracts/src/snapshot-tree.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,13 @@ export function findSnapshotAncestor<T>(
3131
return null;
3232
}
3333

34-
/**
35-
* Returns the nearest ancestor matching `predicate`; false means keep walking.
36-
*
37-
* Pass `nodeByIndex` when the caller already holds an index over this exact
38-
* node array — a batch asking about many nodes otherwise rebuilds the whole map
39-
* per lookup. Omitting it keeps the one-off call shape, which is what an
40-
* ordinary single-target interaction wants.
41-
*/
34+
/** Returns the nearest ancestor matching `predicate`; false means keep walking. */
4235
export function findNearestAncestor(
4336
nodes: SnapshotNode[],
4437
node: SnapshotNode,
4538
predicate: (ancestor: SnapshotNode) => boolean,
46-
nodeByIndex?: ReadonlyMap<number, SnapshotNode>,
4739
): SnapshotNode | null {
48-
return findSnapshotAncestor(
49-
nodes,
50-
node,
51-
nodeByIndex ?? buildSnapshotNodeMap(nodes),
52-
(ancestor) => (predicate(ancestor) ? ancestor : null),
40+
return findSnapshotAncestor(nodes, node, buildSnapshotNodeMap(nodes), (ancestor) =>
41+
predicate(ancestor) ? ancestor : null,
5342
);
5443
}

‎packages/contracts/src/snapshot.test.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ test('findNearestAncestor adapts a predicate to the shared tree walk', () => {
7777
const isWindow = (ancestor: SnapshotNode) => ancestor.type === 'Window';
7878

7979
assert.equal(findNearestAncestor(nodes, nodes[1]!, isWindow)?.index, 10);
80-
// A caller that already holds an index over this array hands it in instead of
81-
// paying for a rebuilt map per lookup; an index that omits the chain proves
82-
// the supplied map is the one walked, not a quietly rebuilt one.
83-
assert.equal(
84-
findNearestAncestor(nodes, nodes[1]!, isWindow, buildSnapshotNodeMap(nodes))?.index,
85-
10,
86-
);
87-
assert.equal(findNearestAncestor(nodes, nodes[1]!, isWindow, new Map()), null);
8880
});
8981

9082
test('snapshot tree and scroll semantics identify nodes through their stable indexes', () => {

‎src/core/actionable-touch-topology.test.ts‎

Lines changed: 0 additions & 102 deletions
This file was deleted.

‎src/core/actionable-touch-topology.ts‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎src/core/interaction-targeting.test.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
scrollingContainerTypeArb,
88
} from '../__tests__/test-utils/property-arbitraries.ts';
99
import { makeSnapshotState } from '../__tests__/test-utils/snapshot-builders.ts';
10-
import { buildActionableTouchTopology } from './actionable-touch-topology.ts';
1110
import {
1211
classifyActionableTouchCandidates,
12+
createActionableTouchResolver,
1313
resolveActionableTouchResolution,
1414
} from './interaction-targeting.ts';
1515
import {
@@ -204,20 +204,16 @@ test('falls back to the original node when no usable touch target exists', () =>
204204
assert.equal(resolution.node.label, 'Virtual item');
205205
});
206206

207-
test('a prebuilt topology answers every policy branch exactly as the unindexed walk does', () => {
207+
test('the batch resolver preserves every actionability policy branch', () => {
208208
const snapshot = makeSnapshotState(INDEXED_PARITY_POLICY_NODES);
209-
const topology = buildActionableTouchTopology(snapshot.nodes);
209+
const resolveTouch = createActionableTouchResolver(snapshot.nodes);
210210

211211
const unindexed = snapshot.nodes.map((node) =>
212212
resolveActionableTouchResolution(snapshot.nodes, node),
213213
);
214-
const indexed = snapshot.nodes.map((node) =>
215-
resolveActionableTouchResolution(snapshot.nodes, node, topology),
216-
);
214+
const indexed = snapshot.nodes.map(resolveTouch);
217215

218216
assert.deepEqual(indexed, unindexed);
219-
// Pinned rather than merely equal: two identically broken implementations
220-
// would also be deeply equal to each other.
221217
assert.deepEqual(
222218
indexed.map((resolution) => [resolution.node.index, resolution.reason]),
223219
[

0 commit comments

Comments
 (0)