Skip to content

Commit

Permalink
feat: support resolving view from multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaAmaju committed Sep 9, 2024
1 parent 7bffb24 commit 1bf90c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-keys-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stack54": minor
---

Add support for resolving view from multiple locations
11 changes: 9 additions & 2 deletions packages/core/src/runtime/render/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const isLazy = <T>(value: any): value is Lazy<T> => {
};

export function resolveComponent<T>(
path: string,
path: string | string[],
components: T
): T extends Record<string, infer R>
? R extends Lazy<infer R1>
Expand All @@ -66,7 +66,14 @@ export function resolveComponent<T>(
string,
TemplateModule | Lazy<TemplateModule>
>;
const entry = components_[path];

const path_ = Array.isArray(path)
? Object.keys(components_).find((entry) => path.includes(entry))
: path;

if (!path_) throw new Error("Template not found");

const entry = components_[path_];
// @ts-expect-error
return isLazy(entry) ? entry().then((_) => _.default) : entry.default;
}
Expand Down

0 comments on commit 1bf90c1

Please sign in to comment.