Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Oct 2, 2024
1 parent f5b58cc commit 17dca50
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 59 deletions.
49 changes: 10 additions & 39 deletions packages/react-router/lib/server-runtime/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,16 @@ export interface AppLoadContext {
*/
export type AppData = unknown;

export async function callRouteAction({
loadContext,
action,
params,
request,
routeId,
}: {
request: Request;
action: ActionFunction;
params: ActionFunctionArgs["params"];
loadContext: AppLoadContext;
routeId: string;
}) {
let result = await action({
request: stripRoutesParam(stripIndexParam(request)),
context: loadContext,
params,
});

return result;
}

export async function callRouteLoader({
loadContext,
loader,
params,
request,
routeId,
}: {
request: Request;
loader: LoaderFunction;
params: LoaderFunctionArgs["params"];
loadContext: AppLoadContext;
routeId: string;
}) {
let result = await loader({
request: stripRoutesParam(stripIndexParam(request)),
context: loadContext,
params,
// Need to use RR's version here to permit the optional context even
// though we know it'll always be provided in remix
export async function callRouteHandler(
handler: LoaderFunction | ActionFunction,
args: LoaderFunctionArgs | ActionFunctionArgs
) {
let result = await handler({
request: stripRoutesParam(stripIndexParam(args.request)),
params: args.params,
context: args.context,
});

return result;
Expand Down
32 changes: 12 additions & 20 deletions packages/react-router/lib/server-runtime/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import type {
LoaderFunctionArgs as RRLoaderFunctionArgs,
ActionFunctionArgs as RRActionFunctionArgs,
} from "../router/utils";
import { callRouteAction, callRouteLoader } from "./data";
import { callRouteHandler } from "./data";
import type { FutureConfig } from "../dom/ssr/entry";
import type { ServerRouteModule } from "./routeModules";
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
ServerRouteModule,
} from "./routeModules";

export interface RouteManifest<Route> {
[routeId: string]: Route;
Expand Down Expand Up @@ -88,27 +92,15 @@ export function createStaticHandlerDataRoutes(
route.id === "root" || route.module.ErrorBoundary != null,
id: route.id,
path: route.path,
// Need to use RR's version in the param typed here to permit the optional
// context even though we know it'll always be provided in remix
loader: route.module.loader
? // Need to use RR's version here to permit the optional context even
// though we know it'll always be provided in remix
(args: RRLoaderFunctionArgs, dataStrategyCtx?: unknown) =>
callRouteLoader({
request: args.request,
params: args.params,
loadContext: args.context,
loader: route.module.loader!,
routeId: route.id,
})
? (args: RRLoaderFunctionArgs) =>
callRouteHandler(route.module.loader!, args as LoaderFunctionArgs)
: undefined,
action: route.module.action
? (args: RRActionFunctionArgs, dataStrategyCtx?: unknown) =>
callRouteAction({
request: args.request,
params: args.params,
loadContext: args.context,
action: route.module.action!,
routeId: route.id,
})
? (args: RRActionFunctionArgs) =>
callRouteHandler(route.module.action!, args as ActionFunctionArgs)
: undefined,
handle: route.module.handle,
};
Expand Down

0 comments on commit 17dca50

Please sign in to comment.