Skip to content

Commit

Permalink
rename app. and component. to components. (#29175)
Browse files Browse the repository at this point in the history
this is how you create function references to functions in your child components.
avoid introducing two new concepts `app` and `component` when one will do.

GitOrigin-RevId: 4e0dbbb436221d5cf06a6b013871af61d5b88c10
  • Loading branch information
ldanilek authored and Convex, Inc. committed Aug 26, 2024
1 parent 4fcac35 commit 61e3a99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
26 changes: 10 additions & 16 deletions src/cli/codegen_templates/component_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export function componentServerJS(isRoot: boolean): string {
internalActionGeneric,
internalMutationGeneric,
internalQueryGeneric,
appGeneric,
componentGeneric,
componentsGeneric,
createComponentArg,
} from "convex/server";
Expand Down Expand Up @@ -105,14 +104,11 @@ export function componentServerJS(isRoot: boolean): string {
* @returns The wrapped endpoint function. Route a URL path to this function in \`convex/http.js\`.
*/
export const httpAction = httpActionGeneric;
export const components = componentsGeneric();
`;
if (isRoot) {
result += `
export const app = appGeneric();
`;
} else {
if (!isRoot) {
result += `
export const component = componentGeneric();
export const componentArg = createComponentArg();
`;
}
Expand All @@ -126,6 +122,7 @@ function componentServerDTSPrelude(_isRoot: boolean): string {
)}
import {
ActionBuilder,
AnyComponents,
HttpActionBuilder,
MutationBuilder,
QueryBuilder,
Expand Down Expand Up @@ -264,13 +261,11 @@ function componentServerDTSPrelude(_isRoot: boolean): string {

export function componentServerStubDTS(isRoot: boolean): string {
let result = componentServerDTSPrelude(isRoot);
if (isRoot) {
result += `
export declare const app: AnyApp;
`;
} else {
result += `
export declare const components: AnyComponents;
`;
if (!isRoot) {
result += `
export declare const component: AnyComponent;
export declare const componentArg: (ctx: GenericCtx, name: string) => any;
`;
}
Expand All @@ -285,8 +280,7 @@ export async function componentServerDTS(
): Promise<string> {
const result = [componentServerDTSPrelude(componentDirectory.isRoot)];

const identifier = componentDirectory.isRoot ? "app" : "component";
result.push(`export declare const ${identifier}: {`);
result.push(`export declare const components: {`);

const definitionPath = toComponentDefinitionPath(
rootComponent,
Expand Down
14 changes: 2 additions & 12 deletions src/server/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,19 +583,9 @@ export function createComponentArg(): (ctx: any, name: string) => any {
/**
* @internal
*/
export const appGeneric = () => createChildComponents("app", []);
export const componentsGeneric = () => createChildComponents("components", []);

/**
* @internal
*/
export type AnyApp = AnyChildComponents;

/**
* @internal
*/
export const componentGeneric = () => createChildComponents("component", []);

/**
* @internal
*/
export type AnyComponent = AnyChildComponents;
export type AnyComponents = AnyChildComponents;
6 changes: 2 additions & 4 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export type {
export {
defineApp,
defineComponent,
appGeneric,
componentGeneric,
componentsGeneric,
currentSystemUdfInComponent,
createComponentArg,
createFunctionHandle,
Expand All @@ -181,8 +180,7 @@ export {
*/
export type {
ComponentDefinition,
AnyApp,
AnyComponent,
AnyComponents,
FunctionHandle,
} from "./components/index.js";

Expand Down

0 comments on commit 61e3a99

Please sign in to comment.