Skip to content
Draft
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
3 changes: 3 additions & 0 deletions api/src/HelloWorld.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export default Router(HelloWorldRsc)({
currentUser: user,
randomUser: generate(S.A.make(User)).value
})
},
*Set({ echo }) {
yield* Effect.logInfo("Bogus", { echo })
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/resources/HelloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class GetHelloWorld extends S.Req<GetHelloWorld>()("GetHelloWorld", {
echo: S.String
}, { allowAnonymous: true, allowRoles: ["user"], success: Response }) {}

export class Set extends S.Req<Set>()("Set", {
echo: S.String
}, { allowAnonymous: true, allowRoles: ["user"] }) {}

// codegen:start {preset: meta, sourcePrefix: src/resources/}
export const meta = { moduleName: "HelloWorld" } as const
// codegen:end
3 changes: 1 addition & 2 deletions frontend/composables/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 31 additions & 3 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>("Input")({
title: S.NonEmptyString255,
Expand All @@ -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>()(
"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(() => {
Expand All @@ -41,14 +68,15 @@ 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)
})
</script>

<template>
<div>
Hi world!
<v-btn @click="test()">Test</v-btn>
<v-form @submit.prevent="form.submit">
<template v-for="(field, name) in form.fields" :key="name">
<!-- TODO: field.type text, or via length, or is multiLine -->
Expand Down