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"
43import { onUnmounted , ref } from " vue"
5- import { Rpc , RpcGroup , RpcTest } from " @effect/rpc "
4+ import { TestClient } from " ../fixtures/TestClient " ;
65
76defineProps <{ msg: string }>()
87
98const 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
3112const 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" ] })
4728onUnmounted (() => clearInterval (interval ))
4829 </script >
4930
0 commit comments