Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GJS/GTS route templates #20768

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/@ember/routing/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
prefixRouteNameArg,
stashParamNames,
} from './lib/utils';
import { hasInternalComponentManager } from '@glimmer/manager';

export interface ExtendedInternalRouteInfo<R extends Route> extends InternalRouteInfo<R> {
_names?: unknown[];
Expand Down Expand Up @@ -1825,6 +1826,15 @@ export function getRenderState(route: Route): RenderState | undefined {
return route[RENDER_STATE];
}

import { precompileTemplate } from '@ember/template-compilation';

function RouteTemplate(Component: object): TemplateFactory {
return precompileTemplate(`<Component @model={{@model}} @controller={{this}} />`, {
strictMode: true,
scope: () => ({ Component }),
});
}
ef4 marked this conversation as resolved.
Show resolved Hide resolved

function buildRenderState(route: Route): RenderState {
let owner = getOwner(route);
assert('Route is unexpectedly missing an owner', owner);
Expand All @@ -1836,10 +1846,20 @@ function buildRenderState(route: Route): RenderState {

let model = route.currentModel;

let template = owner.lookup(`template:${route.templateName || name}`) as
let templateOrComponent = owner.lookup(`template:${route.templateName || name}`) as
| TemplateFactory
| object
| undefined;

let template: TemplateFactory | undefined;
if (templateOrComponent) {
if (hasInternalComponentManager(templateOrComponent)) {
template = RouteTemplate(templateOrComponent);
} else {
template = templateOrComponent as TemplateFactory;
}
}

let render: RenderState = {
owner,
into: undefined,
Expand Down
Loading