diff --git a/packages/example/src/routes/time.tsx b/packages/example/src/routes/time.tsx index 077922c..754c51f 100644 --- a/packages/example/src/routes/time.tsx +++ b/packages/example/src/routes/time.tsx @@ -1,9 +1,15 @@ import { Reffuse } from "@/reffuse" import { createFileRoute } from "@tanstack/react-router" -import { Console, DateTime, Effect, Ref, Schedule, SubscriptionRef } from "effect" +import { Console, DateTime, Effect, Ref, Schedule, Stream, SubscriptionRef } from "effect" import { useMemo } from "react" +const timeEverySecond = Stream.repeatEffectWithSchedule( + DateTime.now, + Schedule.intersect(Schedule.forever, Schedule.spaced("1 second")), +) + + export const Route = createFileRoute("/time")({ component: Time }) @@ -18,18 +24,19 @@ function Time() { // eslint-disable-next-line react-hooks/exhaustive-deps ), []) - // Reffuse.useFork(Effect.addFinalizer(() => Console.log("Component unmounted.")).pipe( + Reffuse.useFork(Effect.addFinalizer(() => Console.log("Cleanup")).pipe( + Effect.flatMap(() => + Stream.runForEach(timeEverySecond, v => Ref.set(timeRef, v)) + ) + ), [timeRef]) + // Reffuse.useFork(Effect.addFinalizer(() => Console.log("Cleanup")).pipe( // Effect.flatMap(() => DateTime.now), // Effect.flatMap(v => Ref.set(timeRef, v)), - // Effect.repeat(Schedule.spaced("1 second")), - // )) - Reffuse.useFork(DateTime.now.pipe( - Effect.flatMap(v => Ref.set(timeRef, v)), - Effect.repeat(Schedule.intersect( - Schedule.forever, - Schedule.spaced("1 second"), - )), - )) + // Effect.repeat(Schedule.intersect( + // Schedule.forever, + // Schedule.spaced("1 second"), + // )), + // ), [timeRef]) const [time] = Reffuse.useRefState(timeRef)