0.1.3 #5
@@ -1,5 +1,5 @@
|
|||||||
import type * as AsyncData from "@typed/async-data"
|
import type * as AsyncData from "@typed/async-data"
|
||||||
import { type Cause, type Context, Effect, type Fiber, Layer, type Stream, type SubscriptionRef } from "effect"
|
import { type Cause, type Context, Effect, type Fiber, Layer, type Option, type Stream, type SubscriptionRef } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { ReffuseExtension, type ReffuseHelpers } from "reffuse"
|
import { ReffuseExtension, type ReffuseHelpers } from "reffuse"
|
||||||
import * as QueryRunner from "./QueryRunner.js"
|
import * as QueryRunner from "./QueryRunner.js"
|
||||||
@@ -13,7 +13,7 @@ export interface UseQueryProps<K extends readonly unknown[], A, E, R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UseQueryResult<K extends readonly unknown[], A, E> {
|
export interface UseQueryResult<K extends readonly unknown[], A, E> {
|
||||||
readonly keyStream: Stream.Stream<K>
|
readonly latestKey: SubscriptionRef.SubscriptionRef<Option.Option<K>>
|
||||||
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||||
readonly refresh: Effect.Effect<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>
|
readonly refresh: Effect.Effect<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>
|
||||||
|
|
||||||
@@ -41,12 +41,12 @@ export const QueryExtension = ReffuseExtension.make(() => ({
|
|||||||
[props.refreshOnWindowFocus, runner])
|
[props.refreshOnWindowFocus, runner])
|
||||||
|
|
||||||
return React.useMemo(() => ({
|
return React.useMemo(() => ({
|
||||||
keyStream: props.key,
|
latestKey: runner.latestKeyRef,
|
||||||
state: runner.stateRef,
|
state: runner.stateRef,
|
||||||
refresh: runner.forkRefresh,
|
refresh: runner.forkRefresh,
|
||||||
|
|
||||||
layer: tag => Layer.succeed(tag, {
|
layer: tag => Layer.succeed(tag, {
|
||||||
keyStream: props.key,
|
latestKey: runner.latestKeyRef,
|
||||||
state: runner.stateRef,
|
state: runner.stateRef,
|
||||||
refresh: runner.forkRefresh,
|
refresh: runner.forkRefresh,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import { type Cause, Effect, Fiber, identity, Option, Ref, type Scope, Stream, S
|
|||||||
|
|
||||||
|
|
||||||
export interface QueryRunner<K extends readonly unknown[], A, E, R> {
|
export interface QueryRunner<K extends readonly unknown[], A, E, R> {
|
||||||
readonly key: Stream.Stream<K>
|
|
||||||
readonly query: (key: K) => Effect.Effect<A, E, R>
|
readonly query: (key: K) => Effect.Effect<A, E, R>
|
||||||
|
|
||||||
|
readonly latestKeyRef: SubscriptionRef.SubscriptionRef<Option.Option<K>>
|
||||||
readonly stateRef: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
readonly stateRef: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||||
readonly fiberRef: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>>
|
readonly fiberRef: SubscriptionRef.SubscriptionRef<Option.Option<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>>
|
||||||
|
|
||||||
@@ -128,9 +128,9 @@ export const make = <K extends readonly unknown[], A, E, R>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key,
|
|
||||||
query,
|
query,
|
||||||
|
|
||||||
|
latestKeyRef,
|
||||||
stateRef,
|
stateRef,
|
||||||
fiberRef,
|
fiberRef,
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type * as AsyncData from "@typed/async-data"
|
import type * as AsyncData from "@typed/async-data"
|
||||||
import { type Cause, Effect, type Fiber, type Stream, type SubscriptionRef } from "effect"
|
import { type Cause, Effect, type Fiber, type Option, type SubscriptionRef } from "effect"
|
||||||
|
|
||||||
|
|
||||||
export interface QueryService<K extends readonly unknown[], A, E> {
|
export interface QueryService<K extends readonly unknown[], A, E> {
|
||||||
readonly keyStream: Stream.Stream<K>
|
readonly latestKey: SubscriptionRef.SubscriptionRef<Option.Option<K>>
|
||||||
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||||
readonly refresh: Effect.Effect<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>
|
readonly refresh: Effect.Effect<Fiber.RuntimeFiber<void, Cause.NoSuchElementException>>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user