Skip to content

Commit

Permalink
퀵 가이드 파라미터 추적 개선 (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
CirnoV authored Dec 12, 2024
1 parent bc9570c commit 8719c77
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
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

0 comments on commit 8719c77

Please sign in to comment.