From f09c6e3a1cad3918df3ef76099667e8dd4414b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 16 Dec 2025 09:19:52 +0100 Subject: [PATCH] QueryClient work --- packages/effect-fc/src/Query.ts | 11 ++++++----- packages/effect-fc/src/QueryClient.ts | 9 ++++++--- packages/effect-fc/src/ReactRuntime.ts | 8 +++++++- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/effect-fc/src/Query.ts b/packages/effect-fc/src/Query.ts index 9d51efa..183b51b 100644 --- a/packages/effect-fc/src/Query.ts +++ b/packages/effect-fc/src/Query.ts @@ -1,4 +1,5 @@ import { type Cause, type Context, Effect, Fiber, identity, Option, Pipeable, Predicate, type Scope, Stream, type Subscribable, SubscriptionRef } from "effect" +import type * as QueryClient from "./QueryClient.js" import * as Result from "./Result.js" @@ -9,7 +10,7 @@ export interface Query + readonly context: Context.Context readonly key: Stream.Stream readonly f: (key: K) => Effect.Effect readonly initialProgress: P @@ -35,7 +36,7 @@ extends Pipeable.Class() implements Query { readonly [QueryTypeId]: QueryTypeId = QueryTypeId constructor( - readonly context: Context.Context>, + readonly context: Context.Context, readonly key: Stream.Stream, readonly f: (key: K) => Effect.Effect, readonly initialProgress: P, @@ -155,10 +156,10 @@ export const make = Effect.fnUntraced(function* , P>, never, - Scope.Scope | Result.forkEffect.OutputContext + Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext > { return new QueryImpl( - yield* Effect.context>(), + yield* Effect.context>(), options.key, options.f as any, options.initialProgress as P, @@ -176,7 +177,7 @@ export const service = , P>, never, - Scope.Scope | Result.forkEffect.OutputContext + Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext > => Effect.tap( make(options), query => Effect.forkScoped(run(query)), diff --git a/packages/effect-fc/src/QueryClient.ts b/packages/effect-fc/src/QueryClient.ts index 9f1e80e..d52adae 100644 --- a/packages/effect-fc/src/QueryClient.ts +++ b/packages/effect-fc/src/QueryClient.ts @@ -63,15 +63,18 @@ export class QueryClientCacheKey extends Pipeable.Class() implements Pipeable.Pipeable, Equal.Equal { readonly [QueryClientCacheKeyTypeId]: QueryClientCacheKeyTypeId = QueryClientCacheKeyTypeId - constructor(readonly key: Query.Query.AnyKey) { + constructor( + readonly key: Query.Query.AnyKey, + readonly f: (key: Query.Query.AnyKey) => Effect.Effect, + ) { super() } [Equal.symbol](that: Equal.Equal) { - return isQueryClientCacheKey(that) && Equivalence.array(Equal.equivalence())(this.key, that.key) + return isQueryClientCacheKey(that) && Equivalence.array(Equal.equivalence())(this.key, that.key) && Equivalence.strict()(this.f, that.f) } [Hash.symbol]() { - return Hash.array(this.key) + return Hash.combine(Hash.hash(this.f))(Hash.array(this.key)) } } diff --git a/packages/effect-fc/src/ReactRuntime.ts b/packages/effect-fc/src/ReactRuntime.ts index c24cd9a..a1a858b 100644 --- a/packages/effect-fc/src/ReactRuntime.ts +++ b/packages/effect-fc/src/ReactRuntime.ts @@ -3,6 +3,7 @@ import { Effect, Layer, ManagedRuntime, Predicate, Runtime, Scope } from "effect import * as React from "react" import * as Component from "./Component.js" import * as ErrorObserver from "./ErrorObserver.js" +import * as QueryClient from "./QueryClient.js" export const TypeId: unique symbol = Symbol.for("@effect-fc/ReactRuntime/ReactRuntime") @@ -17,9 +18,14 @@ export interface ReactRuntime { const ReactRuntimeProto = Object.freeze({ [TypeId]: TypeId } as const) -export const Prelude: Layer.Layer = Layer.mergeAll( +export const Prelude: Layer.Layer< + | Component.ScopeMap + | ErrorObserver.ErrorObserver + | QueryClient.QueryClient +> = Layer.mergeAll( Component.ScopeMap.Default, ErrorObserver.layer, + QueryClient.QueryClient.Default, )