(root: LayerNode.Node<A, E, any>, replacements: LayerNode.Replacements = [])
| 4 | import { makeGlobalNode } from "./app-node" |
| 5 | |
| 6 | export function build<A, E>(root: LayerNode.Node<A, E, any>, replacements: LayerNode.Replacements = []) { |
| 7 | let allReplacements = replacements |
| 8 | |
| 9 | // Only build the location service map if it's actually needed |
| 10 | if (LayerNode.hasUnbound(root, LocationServiceMap.node) && !hasReplacement(replacements, LocationServiceMap.node)) { |
| 11 | const locationMap = buildLocationServiceMap(replacements) |
| 12 | const locationMapNode = makeGlobalNode({ service: LocationServiceMap.Service, layer: locationMap, deps: [] }) |
| 13 | allReplacements = replacements.concat([[LocationServiceMap.node, locationMapNode]]) |
| 14 | } |
| 15 | |
| 16 | return LayerNode.compile(root, allReplacements) |
| 17 | } |
| 18 | |
| 19 | function hasReplacement(replacements: LayerNode.Replacements, node: LayerNode.Node<unknown, unknown, any>) { |
| 20 | return replacements.some(([source]) => source.name === node.name) |
nothing calls this directly
no test coverage detected