@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user