Skip to content

Commit

Permalink
refactor: cascadeLoaderData move
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Nov 11, 2022
1 parent d785a69 commit b83fd3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 0 additions & 4 deletions examples/react/basic-ssr/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { Outlet } from '@tanstack/react-router'

import { router } from './router'

console.log(router.state)

export function App() {
console.log(router.state)

return (
// Build our routes and render our router
<>
Expand Down
13 changes: 0 additions & 13 deletions packages/router-core/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,3 @@ export function createRoute<

return route
}

export function cascadeLoaderData(matches: RouteMatch<any, any>[]) {
matches.forEach((match, index) => {
const parent = matches[index - 1]

if (parent) {
match.loaderData = replaceEqualDeep(match.loaderData, {
...parent.loaderData,
...match.routeLoaderData,
})
}
})
}
15 changes: 14 additions & 1 deletion packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
matchPathname,
resolvePath,
} from './path'
import { AnyRoute, cascadeLoaderData, createRoute, Route } from './route'
import { AnyRoute, createRoute, Route } from './route'
import {
AnyLoaderData,
AnyPathParams,
Expand Down Expand Up @@ -1282,3 +1282,16 @@ export function createRouter<
function isCtrlEvent(e: MouseEvent) {
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey)
}

function cascadeLoaderData(matches: RouteMatch<any, any>[]) {
matches.forEach((match, index) => {
const parent = matches[index - 1]

if (parent) {
match.loaderData = replaceEqualDeep(match.loaderData, {
...parent.loaderData,
...match.routeLoaderData,
})
}
})
}

0 comments on commit b83fd3a

Please sign in to comment.