0.2.2 #31

Merged
Thilawyn merged 184 commits from next into master 2026-01-16 17:05:31 +01:00
3 changed files with 15 additions and 9 deletions
Showing only changes of commit b29dec7d30 - Show all commits

View File

@@ -1,4 +1,4 @@
import { type Cause, type Context, DateTime, type Duration, Effect, Exit, Fiber, HashMap, identity, Option, Pipeable, Predicate, type Scope, Stream, Subscribable, SubscriptionRef } from "effect" import { type Cause, Console, type Context, DateTime, type Duration, Effect, Exit, Fiber, HashMap, identity, Option, Pipeable, Predicate, type Scope, Stream, Subscribable, SubscriptionRef } from "effect"
import * as QueryClient from "./QueryClient.js" import * as QueryClient from "./QueryClient.js"
import * as Result from "./Result.js" import * as Result from "./Result.js"
@@ -195,13 +195,18 @@ extends Pipeable.Class() implements Query<K, A, E, R, P> {
Scope.Scope | QueryClient.QueryClient | R Scope.Scope | QueryClient.QueryClient | R
> { > {
return Effect.andThen(this.getCacheEntry(key), Option.match({ return Effect.andThen(this.getCacheEntry(key), Option.match({
onSome: entry => QueryClient.isQueryClientCacheEntryStale(entry, this.staleTime) onSome: entry => Effect.andThen(
? Effect.succeed(Subscribable.make({ QueryClient.isQueryClientCacheEntryStale(entry, this.staleTime),
get: Effect.succeed(entry.result as Result.Result<A, E, P>), isStale => isStale
get changes() { return Stream.make(entry.result as Result.Result<A, E, P>) }, ? this.start(key, Result.willRefresh(entry.result) as Result.Final<A, E, P>)
})) : Effect.succeed(Subscribable.make({
: this.start(key, Result.willRefresh(entry.result) as Result.Final<A, E, P>), get: Effect.succeed(entry.result as Result.Result<A, E, P>),
onNone: () => this.start(key, initial), get changes() { return Stream.make(entry.result as Result.Result<A, E, P>) },
})),
),
onNone: () => this.start(key, initial).pipe(
Effect.tap(Console.log("Cache missed"))
),
})) }))
} }

View File

@@ -111,5 +111,5 @@ export const isQueryClientCacheEntryStale = (
staleTime: Duration.DurationInput, staleTime: Duration.DurationInput,
): Effect.Effect<boolean> => Effect.andThen( ): Effect.Effect<boolean> => Effect.andThen(
DateTime.now, DateTime.now,
now => Duration.lessThan(DateTime.distanceDuration(self.createdAt, now), staleTime), now => Duration.greaterThanOrEqualTo(DateTime.distanceDuration(self.createdAt, now), staleTime),
) )

View File

@@ -28,6 +28,7 @@ const ResultView = Component.makeUntraced("Result")(function*() {
Effect.andThen(response => response.json), Effect.andThen(response => response.json),
Effect.andThen(Schema.decodeUnknown(Post)), Effect.andThen(Schema.decodeUnknown(Post)),
), ),
staleTime: "10 seconds",
}) })
const mutation = yield* Mutation.make({ const mutation = yield* Mutation.make({