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

퀵 가이드 파라미터 추적 개선 #702

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 28 additions & 19 deletions src/components/interactive-docs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export { code } from "./code";
import { Switch } from "@kobalte/core/switch";
import { trackStore } from "@solid-primitives/deep";
import {
batch,
children,
type Component,
createEffect,
createMemo,
on,
onCleanup,
type ParentComponent,
type ParentProps,
Expand Down Expand Up @@ -153,25 +155,32 @@ export function createInteractiveDoc<
}>,
) => {
const { params, selectedLanguage } = useInteractiveDocs();
const show = createMemo(() => {
const whenResolver = (when: Required<typeof props>["when"]) =>
when(params as Params);
const languageResolver = (language: Required<typeof props>["language"]) =>
match(selectedLanguage())
.with(
[P.string, P.string],
([frontend, backend]) =>
`frontend/${frontend}` === language ||
`backend/${backend}` === language,
)
.with(P.string, (hybrid) => `hybrid/${hybrid}` === language)
.with(P.nullish, () => false)
.exhaustive();
return (
(props.when ? whenResolver(props.when) : true) &&
(props.language ? languageResolver(props.language) : true)
);
});
const show = createMemo(
on(
[() => trackStore(params), selectedLanguage],
([params, selectedLanguage]) => {
const whenResolver = (when: Required<typeof props>["when"]) =>
when(params as Params);
const languageResolver = (
language: Required<typeof props>["language"],
) =>
match(selectedLanguage)
.with(
[P.string, P.string],
([frontend, backend]) =>
`frontend/${frontend}` === language ||
`backend/${backend}` === language,
)
.with(P.string, (hybrid) => `hybrid/${hybrid}` === language)
.with(P.nullish, () => false)
.exhaustive();
return (
(props.when ? whenResolver(props.when) : true) &&
(props.language ? languageResolver(props.language) : true)
);
},
),
);
return <Show when={show()}>{props.children}</Show>;
};
const Toggle = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ export function Preview() {
});
};

// 재시도를 누르거나 파라미터가 변경될 때마다 초기화
createEffect(() => {
void trackStore(params);

void reload();
});
// 파라미터가 변경될 때마다 초기화
createEffect(on(() => trackStore(params), reload));

const requestPayment = async () => {
if (paymentStatus().status === "PENDING") return undefined;
Expand Down
5 changes: 3 additions & 2 deletions src/state/interactive-docs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createContextProvider } from "@solid-primitives/context";
import { trackStore } from "@solid-primitives/deep";
import { createHighlighterCore } from "shiki/core";
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
import {
Expand Down Expand Up @@ -185,8 +186,8 @@ const [InteractiveDocsProvider, useInteractiveDocs] = createContextProvider(
const [tabs, setTabs] = createSignal<Tab[]>([]);
createEffect(
on(
[selectedLanguage, codeExamples],
([selectedLanguage, codeExamples]) => {
[() => trackStore(params), selectedLanguage, codeExamples],
([params, selectedLanguage, codeExamples]) => {
const resolveCode = (example: CodeExample<Params, string>): Tab => {
const { code, sections } = example.code(params);
return {
Expand Down
Loading