Skip to content

Commit bfbab9c

Browse files
committed
extract TestClient
1 parent f08e30e commit bfbab9c

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

sample/vue/src/components/HelloWorld.vue

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
<script setup lang="ts">
2-
import { Atom, AtomRpc, useAtomSet, useAtomValue } from "@effect-atom/atom-vue"
3-
import { Effect, Schema } from "effect"
2+
import { Atom, useAtomSet, useAtomValue } from "@effect-atom/atom-vue"
43
import { onUnmounted, ref } from "vue"
5-
import { Rpc, RpcGroup, RpcTest } from "@effect/rpc"
4+
import { TestClient } from "../fixtures/TestClient";
65
76
defineProps<{ msg: string }>()
87
98
const count = ref(0)
109
11-
const req = ref({ echo: "initial" })
12-
13-
class Rpcs extends RpcGroup.make(
14-
Rpc.make("Get", {
15-
payload: { echo: Schema.String },
16-
success: Schema.Struct({ echo: Schema.String, at: Schema.Date }),
17-
}),
18-
Rpc.make("Set", { payload: { state: Schema.String } }),
19-
) {}
20-
21-
let state = "initial"
22-
class TestClient extends AtomRpc.Tag<TestClient>()("TestClient", {
23-
group: Rpcs,
24-
makeEffect: RpcTest.makeClient(Rpcs, { flatten: true }),
25-
protocol: Rpcs.toLayer({
26-
Get: (req) => Effect.succeed({ echo: req.echo, state, at: new Date() }),
27-
Set: (req) => Effect.sync(() => state = req.state),
28-
}),
29-
}) {}
10+
const req = ref({ echo: "Hello World" })
3011
3112
const result = useAtomValue(() => {
3213
console.log("Computing Atom:", req.value)
@@ -43,7 +24,7 @@ const interval = setInterval(
4324
(req.value = { echo: `Hello World ${new Date().toLocaleTimeString()}` }),
4425
5_000,
4526
)
46-
const onSet = () => set({ payload: { state: new Date().toISOString() }, reactivityKeys: ["Get"] })
27+
const onSet = () => set({ payload: { state: "state "+ new Date().toISOString() }, reactivityKeys: ["Get"] })
4728
onUnmounted(() => clearInterval(interval))
4829
</script>
4930

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { AtomRpc } from "@effect-atom/atom-vue"
2+
import { Rpc, RpcGroup, RpcTest } from "@effect/rpc"
3+
import { Effect, Schema } from "effect"
4+
5+
class Rpcs extends RpcGroup.make(
6+
Rpc.make("Get", {
7+
payload: { echo: Schema.String },
8+
success: Schema.Struct({ echo: Schema.String, at: Schema.Date })
9+
}),
10+
Rpc.make("Set", { payload: { state: Schema.String } })
11+
) {}
12+
13+
let state = "initial"
14+
export class TestClient extends AtomRpc.Tag<TestClient>()("TestClient", {
15+
group: Rpcs,
16+
makeEffect: RpcTest.makeClient(Rpcs, { flatten: true }),
17+
protocol: Rpcs.toLayer({
18+
Get: (req) => Effect.succeed({ echo: req.echo, state, at: new Date() }),
19+
Set: (req) => Effect.sync(() => state = req.state)
20+
})
21+
}) {}

0 commit comments

Comments
 (0)