Time
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-01-11 18:26:43 +01:00
parent e8580ec49e
commit 038f38d32c

View File

@@ -1,9 +1,15 @@
import { Reffuse } from "@/reffuse" import { Reffuse } from "@/reffuse"
import { createFileRoute } from "@tanstack/react-router" 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" import { useMemo } from "react"
const timeEverySecond = Stream.repeatEffectWithSchedule(
DateTime.now,
Schedule.intersect(Schedule.forever, Schedule.spaced("1 second")),
)
export const Route = createFileRoute("/time")({ export const Route = createFileRoute("/time")({
component: Time component: Time
}) })
@@ -18,18 +24,19 @@ function Time() {
// eslint-disable-next-line react-hooks/exhaustive-deps // 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(() => DateTime.now),
// Effect.flatMap(v => Ref.set(timeRef, v)), // Effect.flatMap(v => Ref.set(timeRef, v)),
// Effect.repeat(Schedule.spaced("1 second")), // Effect.repeat(Schedule.intersect(
// )) // Schedule.forever,
Reffuse.useFork(DateTime.now.pipe( // Schedule.spaced("1 second"),
Effect.flatMap(v => Ref.set(timeRef, v)), // )),
Effect.repeat(Schedule.intersect( // ), [timeRef])
Schedule.forever,
Schedule.spaced("1 second"),
)),
))
const [time] = Reffuse.useRefState(timeRef) const [time] = Reffuse.useRefState(timeRef)