({
store,
index,
path,
host,
}: Params)
| 17 | }; |
| 18 | |
| 19 | export default function parameterise({ |
| 20 | store, |
| 21 | index, |
| 22 | path, |
| 23 | host, |
| 24 | }: Params): Returns | null { |
| 25 | const removedPaths: Array<string> = []; |
| 26 | const matchedLeaves: Array<Leaf> = []; |
| 27 | const router = store[host]; |
| 28 | if (!router) return null; |
| 29 | const matchedRoute = router.lookup(path); |
| 30 | if (!matchedRoute) return null; |
| 31 | const nextPath = getNextPath(index, path, matchedRoute); |
| 32 | const foundPathnames = findPathnamesInRouter(router.ctx, nextPath); |
| 33 | for (const found of foundPathnames) { |
| 34 | matchedLeaves.push(found.leaf); |
| 35 | removedPaths.push(found.pathname); |
| 36 | remove(router.ctx, found.pathname); |
| 37 | pruneRouter(router.ctx.rootNode, pathToArray(found.pathname)); |
| 38 | } |
| 39 | const mergedLeaf = matchedLeaves.reduce(mergeLeaves); |
| 40 | mergedLeaf.pathname = nextPath; |
| 41 | removedPaths.forEach((path) => unset(store[host].ctx.staticRoutesMap, path)); |
| 42 | unset(store[host].ctx.staticRoutesMap, nextPath); |
| 43 | router.insert(nextPath, { data: mergedLeaf }); |
| 44 | return { |
| 45 | removedPaths, |
| 46 | insertedPath: nextPath, |
| 47 | insertedLeaf: mergedLeaf, |
| 48 | }; |
| 49 | } |
no test coverage detected