Query work
All checks were successful
Lint / lint (push) Successful in 13s

This commit is contained in:
Julien Valverdé
2025-03-05 00:16:13 +01:00
parent adaadf13b2
commit 8fa24b1791
5 changed files with 34 additions and 20 deletions

View File

@@ -7,8 +7,8 @@ import * as QueryRunner from "./QueryRunner.js"
export interface UseQueryProps<A, E, R> {
effect: () => Effect.Effect<A, E, R>
readonly deps: React.DependencyList
readonly query: () => Effect.Effect<A, E, R>
readonly key: React.DependencyList
}
export interface UseQueryResult<A, E> {
@@ -22,12 +22,14 @@ export const QueryExtension = ReffuseExtension.make(() => ({
this: ReffuseHelpers.ReffuseHelpers<R>,
props: UseQueryProps<A, E, R>,
): UseQueryResult<A, E> {
const runner = this.useMemo(() => QueryRunner.make(props.effect()), [])
const runner = this.useMemo(() => QueryRunner.make({
query: props.query()
}), [])
this.useEffect(() => Effect.addFinalizer(() => runner.forkInterrupt).pipe(
Effect.andThen(Ref.set(runner.queryRef, props.effect())),
Effect.andThen(Ref.set(runner.queryRef, props.query())),
Effect.andThen(runner.forkFetch),
), [runner, ...props.deps])
), [runner, ...props.key])
this.useFork(() => Stream.runForEach(
BrowserStream.fromEventListenerWindow("focus"),