@reffuse/extension-query 0.1.4 #15

Merged
Thilawyn merged 340 commits from next into master 2025-05-26 04:15:01 +02:00
Showing only changes of commit 3548ed5718 - Show all commits

View File

@@ -61,17 +61,14 @@ export const make = <K extends readonly unknown[], A, FallbackA, E, HandledE, R>
const queryStateTag = QueryState.makeTag<A | FallbackA, Exclude<E, HandledE>>() const queryStateTag = QueryState.makeTag<A | FallbackA, Exclude<E, HandledE>>()
const interrupt = fiberRef.pipe( const interrupt = Effect.flatMap(fiberRef, Option.match({
Effect.flatMap(Option.match({
onSome: fiber => Ref.set(fiberRef, Option.none()).pipe( onSome: fiber => Ref.set(fiberRef, Option.none()).pipe(
Effect.andThen(Fiber.interrupt(fiber)) Effect.andThen(Fiber.interrupt(fiber))
), ),
onNone: () => Effect.void, onNone: () => Effect.void,
})) }))
)
const forkInterrupt = fiberRef.pipe( const forkInterrupt = Effect.flatMap(fiberRef, Option.match({
Effect.flatMap(Option.match({
onSome: fiber => Ref.set(fiberRef, Option.none()).pipe( onSome: fiber => Ref.set(fiberRef, Option.none()).pipe(
Effect.andThen(Fiber.interrupt(fiber).pipe( Effect.andThen(Fiber.interrupt(fiber).pipe(
Effect.asVoid, Effect.asVoid,
@@ -80,7 +77,6 @@ export const make = <K extends readonly unknown[], A, FallbackA, E, HandledE, R>
), ),
onNone: () => Effect.forkDaemon(Effect.void), onNone: () => Effect.forkDaemon(Effect.void),
})) }))
)
const run = Effect.Do.pipe( const run = Effect.Do.pipe(
Effect.bind("state", () => queryStateTag), Effect.bind("state", () => queryStateTag),
@@ -129,15 +125,13 @@ export const make = <K extends readonly unknown[], A, FallbackA, E, HandledE, R>
)) ))
) )
const setInitialRefreshState = queryStateTag.pipe( const setInitialRefreshState = Effect.flatMap(queryStateTag, state => state.update(previous => {
Effect.flatMap(state => state.update(previous => {
if (AsyncData.isSuccess(previous) || AsyncData.isFailure(previous)) if (AsyncData.isSuccess(previous) || AsyncData.isFailure(previous))
return AsyncData.refreshing(previous) return AsyncData.refreshing(previous)
if (AsyncData.isRefreshing(previous)) if (AsyncData.isRefreshing(previous))
return AsyncData.refreshing(previous.previous) return AsyncData.refreshing(previous.previous)
return AsyncData.loading() return AsyncData.loading()
})) }))
)
const forkRefresh = Queue.unbounded<AsyncData.AsyncData<A | FallbackA, Exclude<E, HandledE>>>().pipe( const forkRefresh = Queue.unbounded<AsyncData.AsyncData<A | FallbackA, Exclude<E, HandledE>>>().pipe(
Effect.flatMap(stateQueue => interrupt.pipe( Effect.flatMap(stateQueue => interrupt.pipe(