All files / app/codeCharta/state/selectors/accumulatedData idToNode.selector.ts

100% Statements 12/12
100% Branches 1/1
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1959x 59x   59x   59x 4x 2x     2x 2x 10x   2x     59x  
import { createSelector } from "@ngrx/store"
import { hierarchy } from "d3-hierarchy"
import { CodeMapNode } from "../../../codeCharta.model"
import { AccumulatedData, accumulatedDataSelector } from "./accumulatedData.selector"
 
export const _calculateIdToNode = (accumulatedData: Pick<AccumulatedData, "unifiedMapNode">): Map<number, CodeMapNode> => {
    if (!accumulatedData.unifiedMapNode) {
        return new Map()
    }
 
    const idToNode: Map<number, CodeMapNode> = new Map([[accumulatedData.unifiedMapNode.id, accumulatedData.unifiedMapNode]])
    for (const { data } of hierarchy(accumulatedData.unifiedMapNode)) {
        idToNode.set(data.id, data)
    }
    return idToNode
}
 
export const idToNodeSelector = createSelector(accumulatedDataSelector, _calculateIdToNode)