Skip to content

Commit a02c00b

Browse files
committed
refactor: baseChildMap 을 iterable 로 초기값 설정
1 parent b55dc57 commit a02c00b

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

packages/patchlogr-core/src/diff/diffChildNodes.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@ export function diffChildNodes<K, V>(
1414
path: ChangePath<K>,
1515
): {
1616
changes: SpecChange<K, V>[];
17-
modifiedPairs: Array<{ base: HashNode<K, V>; head: HashNode<K, V> }>;
17+
modifiedPairs: Array<{
18+
base: HashNode<K, V>;
19+
head: HashNode<K, V>;
20+
}>;
1821
} {
1922
const changes: SpecChange<K, V>[] = [];
20-
const modifiedPairs: Array<{ base: HashNode<K, V>; head: HashNode<K, V> }> =
21-
[];
23+
const modifiedPairs: Array<{
24+
base: HashNode<K, V>;
25+
head: HashNode<K, V>;
26+
}> = [];
2227

23-
const baseChildren = base.children ?? [];
24-
const headChildren = head.children ?? [];
25-
26-
const baseChildMap = new Map<K, HashNode<K, V>>();
27-
const headChildMap = new Map<K, HashNode<K, V>>();
28-
29-
for (const child of baseChildren) {
30-
baseChildMap.set(child.key, child);
31-
}
32-
for (const child of headChildren) {
33-
headChildMap.set(child.key, child);
34-
}
28+
const baseChildMap = new Map(
29+
base.children?.map((child) => [child.key, child]),
30+
);
31+
const headChildMap = new Map(
32+
head.children?.map((child) => [child.key, child]),
33+
);
3534

3635
// Removed children (base에만 존재)
3736
for (const [key, baseChild] of baseChildMap) {

0 commit comments

Comments
 (0)