0.1.8 #11

Merged
Thilawyn merged 233 commits from next into master 2025-04-21 02:08:14 +02:00
8 changed files with 29 additions and 25 deletions
Showing only changes of commit d82d1d1c29 - Show all commits

View File

@@ -1,6 +1,7 @@
import { R } from "@/reffuse" import { R } from "@/reffuse"
import { HttpClient } from "@effect/platform" import { HttpClient } from "@effect/platform"
import { Button, Container, Flex, Slider, Text } from "@radix-ui/themes" import { Button, Container, Flex, Slider, Text } from "@radix-ui/themes"
import { QueryProgress } from "@reffuse/extension-query"
import { createFileRoute } from "@tanstack/react-router" import { createFileRoute } from "@tanstack/react-router"
import * as AsyncData from "@typed/async-data" import * as AsyncData from "@typed/async-data"
import { Array, Console, Effect, flow, Option, Schema, Stream } from "effect" import { Array, Console, Effect, flow, Option, Schema, Stream } from "effect"
@@ -22,6 +23,7 @@ function RouteComponent() {
const mutation = R.useMutation({ const mutation = R.useMutation({
mutation: ([count]: readonly [count: number]) => Console.log(`Querying ${ count } IDs...`).pipe( mutation: ([count]: readonly [count: number]) => Console.log(`Querying ${ count } IDs...`).pipe(
Effect.andThen(Effect.sleep("500 millis")), Effect.andThen(Effect.sleep("500 millis")),
Effect.tap(() => QueryProgress.QueryProgress.get),
Effect.andThen(HttpClient.get(`https://www.uuidtools.com/api/generate/v4/count/${ count }`)), Effect.andThen(HttpClient.get(`https://www.uuidtools.com/api/generate/v4/count/${ count }`)),
HttpClient.withTracerPropagation(false), HttpClient.withTracerPropagation(false),
Effect.flatMap(res => res.json), Effect.flatMap(res => res.json),

View File

@@ -2,13 +2,11 @@ import type * as AsyncData from "@typed/async-data"
import { type Cause, type Context, Effect, type Fiber, Layer, type Option, 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 MutationRunner from "./MutationRunner.js"
import type * as MutationService from "./MutationService.js" import type * as MutationService from "./MutationService.js"
import * as QueryClient from "./QueryClient.js" import * as QueryClient from "./QueryClient.js"
import type * as QueryProgress from "./QueryProgress.js" import type * as QueryProgress from "./QueryProgress.js"
import * as QueryRunner from "./QueryRunner.js"
import type * as QueryService from "./QueryService.js" import type * as QueryService from "./QueryService.js"
import type * as QueryState from "./QueryState.js" import { MutationRunner, QueryRunner } from "./internal/index.js"
export interface UseQueryProps<K extends readonly unknown[], A, E, R> { export interface UseQueryProps<K extends readonly unknown[], A, E, R> {
@@ -29,7 +27,7 @@ export interface UseQueryResult<K extends readonly unknown[], A, E> {
export interface UseMutationProps<K extends readonly unknown[], A, E, R> { export interface UseMutationProps<K extends readonly unknown[], A, E, R> {
readonly mutation: (key: K) => Effect.Effect<A, E, R | QueryProgress.QueryProgress | QueryState.QueryState<A, E>> readonly mutation: (key: K) => Effect.Effect<A, E, R | QueryProgress.QueryProgress>
} }
export interface UseMutationResult<K extends readonly unknown[], A, E> { export interface UseMutationResult<K extends readonly unknown[], A, E> {

View File

@@ -1,36 +1,37 @@
import * as AsyncData from "@typed/async-data" import * as AsyncData from "@typed/async-data"
import { Effect, flow, Layer, Match, Option } from "effect" import { Effect, flow, Layer, Match, Option } from "effect"
import * as QueryState from "./QueryState.js" import { QueryState } from "./internal/index.js"
export class QueryProgress extends Effect.Tag("@reffuse/extension-query/QueryProgress")<QueryProgress, { export class QueryProgress extends Effect.Tag("@reffuse/extension-query/QueryProgress")<QueryProgress, {
readonly get: Effect.Effect<Option.Option<AsyncData.Progress>, never, QueryState.QueryState<unknown, unknown>> readonly get: Effect.Effect<Option.Option<AsyncData.Progress>>
readonly update: ( readonly update: (
f: (previous: Option.Option<AsyncData.Progress>) => AsyncData.Progress f: (previous: Option.Option<AsyncData.Progress>) => AsyncData.Progress
) => Effect.Effect<void, never, QueryState.QueryState<unknown, unknown>> ) => Effect.Effect<void>
}>() { }>() {
static readonly Live = Layer.sync(this, () => { static readonly Live: Layer.Layer<
const queryStateTag = QueryState.makeTag() QueryProgress,
never,
QueryState.QueryState<any, any>
> = Layer.effect(this, Effect.gen(function*() {
const state = yield* QueryState.makeTag()
const get = queryStateTag.pipe( const get = state.get.pipe(
Effect.flatMap(state => state.get),
Effect.map(flow(Match.value, Effect.map(flow(Match.value,
Match.tag("Loading", v => v.progress), Match.tag("Loading", v => v.progress),
Match.tag("Refreshing", v => v.progress), Match.tag("Refreshing", v => v.progress),
Match.orElse(() => Option.none()), Match.orElse(() => Option.none()),
)), ))
) )
const update = (f: (previous: Option.Option<AsyncData.Progress>) => AsyncData.Progress) => get.pipe( const update = (f: (previous: Option.Option<AsyncData.Progress>) => AsyncData.Progress) => get.pipe(
Effect.map(f), Effect.map(f),
Effect.flatMap(progress => queryStateTag.pipe( Effect.flatMap(progress => state.update(previous =>
Effect.flatMap(queryState => queryState.update(previous =>
AsyncData.updateProgress(previous, progress) AsyncData.updateProgress(previous, progress)
))
)), )),
) )
return { get, update } return { get, update }
}) }))
} }

View File

@@ -1,9 +1,6 @@
export * as ErrorHandler from "./ErrorHandler.js" export * as ErrorHandler from "./ErrorHandler.js"
export * as MutationRunner from "./MutationRunner.js"
export * as MutationService from "./MutationService.js" export * as MutationService from "./MutationService.js"
export * as QueryClient from "./QueryClient.js" export * as QueryClient from "./QueryClient.js"
export * from "./QueryExtension.js" export * from "./QueryExtension.js"
export * as QueryProgress from "./QueryProgress.js" export * as QueryProgress from "./QueryProgress.js"
export * as QueryRunner from "./QueryRunner.js"
export * as QueryService from "./QueryService.js" export * as QueryService from "./QueryService.js"
export * as QueryState from "./QueryState.js"

View File

@@ -1,7 +1,7 @@
import * as AsyncData from "@typed/async-data" import * as AsyncData from "@typed/async-data"
import { type Context, Effect, type Fiber, Queue, Ref, Stream, SubscriptionRef } from "effect" import { type Context, Effect, type Fiber, Queue, Ref, Stream, SubscriptionRef } from "effect"
import type * as QueryClient from "./QueryClient.js" import type * as QueryClient from "../QueryClient.js"
import * as QueryProgress from "./QueryProgress.js" import * as QueryProgress from "../QueryProgress.js"
import * as QueryState from "./QueryState.js" import * as QueryState from "./QueryState.js"
@@ -19,7 +19,7 @@ export interface MutationRunner<K extends readonly unknown[], A, E, R> {
export interface MakeProps<EH, K extends readonly unknown[], A, E, HandledE, R> { export interface MakeProps<EH, K extends readonly unknown[], A, E, HandledE, R> {
readonly QueryClient: QueryClient.GenericTagClass<EH, HandledE> readonly QueryClient: QueryClient.GenericTagClass<EH, HandledE>
readonly mutation: (key: K) => Effect.Effect<A, E, R | QueryProgress.QueryProgress | QueryState.QueryState<A, Exclude<E, HandledE>>> readonly mutation: (key: K) => Effect.Effect<A, E, R | QueryProgress.QueryProgress>
} }
export const make = <EH, K extends readonly unknown[], A, E, HandledE, R>( export const make = <EH, K extends readonly unknown[], A, E, HandledE, R>(

View File

@@ -1,7 +1,7 @@
import { BrowserStream } from "@effect/platform-browser" import { BrowserStream } from "@effect/platform-browser"
import * as AsyncData from "@typed/async-data" import * as AsyncData from "@typed/async-data"
import { type Cause, type Context, Effect, Fiber, identity, Option, Ref, type Scope, Stream, SubscriptionRef } from "effect" import { type Cause, type Context, Effect, Fiber, identity, Option, Ref, type Scope, Stream, SubscriptionRef } from "effect"
import type * as QueryClient from "./QueryClient.js" import type * as QueryClient from "../QueryClient.js"
export interface QueryRunner<K extends readonly unknown[], A, E, R> { export interface QueryRunner<K extends readonly unknown[], A, E, R> {

View File

@@ -1,4 +1,4 @@
import * as AsyncData from "@typed/async-data" import type * as AsyncData from "@typed/async-data"
import { Context, Effect, Layer } from "effect" import { Context, Effect, Layer } from "effect"

View File

@@ -0,0 +1,6 @@
/** @internal */
export * as MutationRunner from "./MutationRunner.js"
/** @internal */
export * as QueryRunner from "./QueryRunner.js"
/** @internal */
export * as QueryState from "./QueryState.js"