Implement Client And Server
μμ μλμ°(μΉλ·°)μμ ν΄λΌμ΄μΈνΈμ μλ² κ΅¬ννκΈ°
μμ μλμ°μμλ @pbkit/wrp-jotai/parent
κ° μ 곡νλ useChannel
, useClientImpl
λ§ μ¬μ©νλ©΄
WRP μμμ μ»μ μ μμ΅λλ€.
ν΄λΌμ΄μΈνΈ ꡬν
pbkitμ ν΅ν΄ μμ±ν μλΉμ€ μ½λ createServiceClient
μ clientImpl
μ μ 곡νλ©΄ λ©λλ€.
import { useClientImpl } from "@pbkit/wrp-jotai/parent";
import { createServiceClient } from "../generated/services/..."
const Client = () => {
const clientImpl = useClientImpl();
const serviceClient = useMemo(() => {
if (!clientImpl) return;
return createServiceClient(clientImpl);
}, [clientImpl]);
const onClick = async () => {
await serviceClient?.getTextValue({}))?.text;
};
μλ² κ΅¬ν
pbkitμ ν΅ν΄ μμ±ν μλΉμ€ μ½λ methodDescriptors
μ channel
μ useWrpServer
μ μ 곡νλ©΄ λ©λλ€.
import { useWrpServer } from "@pbkit/wrp-react";
import { useChannel } from "@pbkit/wrp-jotai/parent";
import { methodDescriptors } from "../generated/services/...";
const Server = () => {
const channel = useChannel();
useWrpServer(channel, {}, [
[
methodDescriptors.getTextValue,
({ res }) => {
res.header({});
res.send({ text: "hello" });
res.end({});
},
],
]);
λΆλͺ¨ μλμ°(μ±)μμ ν΄λΌμ΄μΈνΈμ μλ² κ΅¬ννκΈ°
λΆλͺ¨ μλμ°μμλ @pbkit/wrp-jotai/pwasa
μ @pbkit/wrp-jotai/iframe
μ μ΄μ©ν΄ WRP μμλ€μ λ§λ€ μ
μμ΅λλ€. κ°κ° createPrimitiveWrpAtomSetAtom
κ³Ό useIframeWrpAtomSetUpdateEffect
λ₯Ό
λΆλ¬μμ μλμ κ°μ΄ λ§λ€μ΄μ£ΌμΈμ.
import { useIframeWrpAtomSetUpdateEffect } from "@pbkit/wrp-jotai/iframe";
import { createPrimitiveWrpAtomSetAtom } from "@pbkit/wrp-jotai/pwasa";
const pwasa = createPrimitiveWrpAtomSetAtom();
const Component = () => {
const { iframeRef } = useIframeWrpAtomSetUpdateEffect(pwasa);
return <iframe ref={iframeRef} />;
};
μμ κ°μ΄ pwasa
λ₯Ό μ
λ°μ΄νΈν λ€, @pbkit/wrp-jotai/pwasa
μμ useChannel
,
useClientImpl
μ μ΄μ©ν΄ channel
κ³Ό clientImpl
μ μ»μ μ μμ΅λλ€.
ν΄λΌμ΄μΈνΈ ꡬν
pbkitμ ν΅ν΄ μμ±ν μλΉμ€ μ½λ createServiceClient
μ clientImpl
μ μ 곡νλ©΄ λ©λλ€.
import { useIframeWrpAtomSetUpdateEffect, useClientImpl } from "@pbkit/wrp-jotai/iframe";
import { createPrimitiveWrpAtomSetAtom } from "@pbkit/wrp-jotai/pwasa";
const pwasa = createPrimitiveWrpAtomSetAtom();
const Client = () => {
const { iframeRef } = useIframeWrpAtomSetUpdateEffect(pwasa);
const clientImpl = useClientImpl(pwasa);
const serviceClient = useMemo(() => {
if (!clientImpl) return;
return createServiceClient(clientImpl);
}, [clientImpl]);
const onClick = async () => {
await serviceClient?.getTextValue({}))?.text;
};
return <iframe ref={iframeRef} />;
μλ² κ΅¬ν
pbkitμ ν΅ν΄ μμ±ν μλΉμ€ μ½λ methodDescriptors
μ channel
μ useWrpServer
μ μ 곡νλ©΄ λ©λλ€.
import { useIframeWrpAtomSetUpdateEffect, useChannel } from "@pbkit/wrp-jotai/iframe";
import { createPrimitiveWrpAtomSetAtom } from "@pbkit/wrp-jotai/pwasa";
import { methodDescriptors } from "../generated/services/...";
const pwasa = createPrimitiveWrpAtomSetAtom();
const Server = () => {
const { iframeRef } = useIframeWrpAtomSetUpdateEffect(pwasa);
const channel = useChannel(pwasa);
useWrpServer(channel, {}, [
[
methodDescriptors.getTextValue,
({ res }) => {
res.header({});
res.send({ text: "hello" });
res.end({});
},
],
]);
return <iframe ref={iframeRef} />;