Refresh on window focus
All checks were successful
Lint / lint (push) Successful in 13s

This commit is contained in:
Julien Valverdé
2025-03-05 00:44:13 +01:00
parent 86539f33f0
commit 1e8a5d412f
2 changed files with 13 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { BrowserStream } from "@effect/platform-browser"
import * as AsyncData from "@typed/async-data"
import { Effect, Fiber, identity, Option, Ref, SubscriptionRef } from "effect"
import { Effect, Fiber, identity, Option, Ref, Stream, SubscriptionRef } from "effect"
export interface QueryRunner<A, E, R> {
@@ -10,6 +11,8 @@ export interface QueryRunner<A, E, R> {
readonly forkInterrupt: Effect.Effect<Fiber.RuntimeFiber<void>>
readonly forkFetch: Effect.Effect<Fiber.RuntimeFiber<void>>
readonly forkRefresh: Effect.Effect<Fiber.RuntimeFiber<void>>
readonly refreshOnWindowFocus: Effect.Effect<void>
}
@@ -91,6 +94,11 @@ export const make = <A, E, R>(
Effect.forkDaemon,
)
const refreshOnWindowFocus = Stream.runForEach(
BrowserStream.fromEventListenerWindow("focus"),
() => forkRefresh,
)
return {
queryRef,
stateRef,
@@ -99,5 +107,7 @@ export const make = <A, E, R>(
forkInterrupt,
forkFetch,
forkRefresh,
refreshOnWindowFocus,
}
})