diff --git a/api/src/HelloWorld.controllers.ts b/api/src/HelloWorld.controllers.ts index e3c3ef95e..aa0051cd7 100644 --- a/api/src/HelloWorld.controllers.ts +++ b/api/src/HelloWorld.controllers.ts @@ -30,6 +30,9 @@ export default Router(HelloWorldRsc)({ currentUser: user, randomUser: generate(S.A.make(User)).value }) + }, + *Set({ echo }) { + yield* Effect.logInfo("Bogus", { echo }) } }) } diff --git a/api/src/resources/HelloWorld.ts b/api/src/resources/HelloWorld.ts index b0d7e02ac..c214cdb23 100644 --- a/api/src/resources/HelloWorld.ts +++ b/api/src/resources/HelloWorld.ts @@ -14,6 +14,10 @@ export class GetHelloWorld extends S.Req()("GetHelloWorld", { echo: S.String }, { allowAnonymous: true, allowRoles: ["user"], success: Response }) {} +export class Set extends S.Req()("Set", { + echo: S.String +}, { allowAnonymous: true, allowRoles: ["user"] }) {} + // codegen:start {preset: meta, sourcePrefix: src/resources/} export const meta = { moduleName: "HelloWorld" } as const // codegen:end diff --git a/frontend/composables/runtime.ts b/frontend/composables/runtime.ts index 756306382..b9661f668 100644 --- a/frontend/composables/runtime.ts +++ b/frontend/composables/runtime.ts @@ -81,8 +81,7 @@ export type RT = ApiClientFactory const config = (globalThis as any).__NUXT__.config as ReturnType< typeof useRuntimeConfig > -const isRemote = config.public.env !== "local-dev" -const disableTracing = !isRemote || !config.public.telemetry +const disableTracing = false // !isRemote || !config.public.telemetry export const runtime = makeRuntime( config.public.feVersion, diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index f37215755..4a29a81cb 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -2,6 +2,9 @@ import { HelloWorldRsc } from "#resources" import { buildFormFromSchema } from "@effect-app/vue/form" import { S } from "effect-app" +import { Atom, AtomRpc, useAtomSet, useAtomValue } from "@effect-atom/atom-vue" +import { makeRpcGroup } from "effect-app/client" +import { RpcClientProtocolLayers } from "~/composables/runtime" class Input extends S.Class("Input")({ title: S.NonEmptyString255, @@ -27,8 +30,32 @@ const makeReq = () => ({ const req = ref(makeReq()) -const helloWorldClient = clientFor(HelloWorldRsc) -const [result] = useSafeQuery(helloWorldClient.GetHelloWorld, req) +const helloWorldRpcs = makeRpcGroup(HelloWorldRsc) +class HelloWorldClient extends AtomRpc.Tag()( + "HelloWorldClient", + { + protocol: RpcClientProtocolLayers("/HelloWorld"), + group: helloWorldRpcs, + }, +) {} + +const result = useAtomValue(() => { + console.log("Recomputing HelloWorld.GetHelloWorld atom with:", req.value) + return Atom.refreshOnWindowFocus( + HelloWorldClient.query("HelloWorld.GetHelloWorld", req.value, { + reactivityKeys: ["echo"], + }), + ) +}) + +const increment = useAtomSet(() => HelloWorldClient.mutation("HelloWorld.Set")) +const test = () => + increment({ payload: { echo: "test" }, reactivityKeys: { echo: ["echo"] } }) + +// const mutation = Effect.fn("MySpan")(function* () { +// yield* Effect.logInfo("doing something") +// increment({ payload: { echo: "test" }, reactivityKeys: { echo: ["echo"] } }) +// }) // onMounted(() => { // setInterval(() => { @@ -41,7 +68,7 @@ const [result] = useSafeQuery(helloWorldClient.GetHelloWorld, req) // }) onMounted(() => { - const t = setInterval(() => (req.value = makeReq()), 5000) + const t = setInterval(() => (req.value = makeReq()), 10_000) return () => clearInterval(t) }) @@ -49,6 +76,7 @@ onMounted(() => {