This commit is contained in:
@@ -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<in out K extends Query.AnyKey, in out A, in out E = never
|
||||
extends Pipeable.Pipeable {
|
||||
readonly [QueryTypeId]: QueryTypeId
|
||||
|
||||
readonly context: Context.Context<Scope.Scope | R>
|
||||
readonly context: Context.Context<Scope.Scope | QueryClient.QueryClient | R>
|
||||
readonly key: Stream.Stream<K>
|
||||
readonly f: (key: K) => Effect.Effect<A, E, R>
|
||||
readonly initialProgress: P
|
||||
@@ -35,7 +36,7 @@ extends Pipeable.Class() implements Query<K, A, E, R, P> {
|
||||
readonly [QueryTypeId]: QueryTypeId = QueryTypeId
|
||||
|
||||
constructor(
|
||||
readonly context: Context.Context<Scope.Scope | NoInfer<R>>,
|
||||
readonly context: Context.Context<Scope.Scope | QueryClient.QueryClient | R>,
|
||||
readonly key: Stream.Stream<K>,
|
||||
readonly f: (key: K) => Effect.Effect<A, E, R>,
|
||||
readonly initialProgress: P,
|
||||
@@ -155,10 +156,10 @@ export const make = Effect.fnUntraced(function* <K extends Query.AnyKey, A, E =
|
||||
): Effect.fn.Return<
|
||||
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
||||
never,
|
||||
Scope.Scope | Result.forkEffect.OutputContext<A, E, R, P>
|
||||
Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext<A, E, R, P>
|
||||
> {
|
||||
return new QueryImpl(
|
||||
yield* Effect.context<Scope.Scope | Result.forkEffect.OutputContext<A, E, R, P>>(),
|
||||
yield* Effect.context<Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext<A, E, R, P>>(),
|
||||
options.key,
|
||||
options.f as any,
|
||||
options.initialProgress as P,
|
||||
@@ -176,7 +177,7 @@ export const service = <K extends Query.AnyKey, A, E = never, R = never, P = nev
|
||||
): Effect.Effect<
|
||||
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
||||
never,
|
||||
Scope.Scope | Result.forkEffect.OutputContext<A, E, R, P>
|
||||
Scope.Scope | QueryClient.QueryClient | Result.forkEffect.OutputContext<A, E, R, P>
|
||||
> => Effect.tap(
|
||||
make(options),
|
||||
query => Effect.forkScoped(run(query)),
|
||||
|
||||
@@ -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<unknown, unknown, unknown>,
|
||||
) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<R, ER> {
|
||||
|
||||
const ReactRuntimeProto = Object.freeze({ [TypeId]: TypeId } as const)
|
||||
|
||||
export const Prelude: Layer.Layer<Component.ScopeMap | ErrorObserver.ErrorObserver> = Layer.mergeAll(
|
||||
export const Prelude: Layer.Layer<
|
||||
| Component.ScopeMap
|
||||
| ErrorObserver.ErrorObserver
|
||||
| QueryClient.QueryClient
|
||||
> = Layer.mergeAll(
|
||||
Component.ScopeMap.Default,
|
||||
ErrorObserver.layer,
|
||||
QueryClient.QueryClient.Default,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user