0.1.8 #11
@@ -1,6 +1,6 @@
|
|||||||
import { AlertDialog, Button, Flex, Text } from "@radix-ui/themes"
|
import { AlertDialog, Button, Flex, Text } from "@radix-ui/themes"
|
||||||
import { ErrorHandler } from "@reffuse/extension-query"
|
import { ErrorHandler } from "@reffuse/extension-query"
|
||||||
import { Cause, Chunk, Context, Effect, Match, Option, Stream } from "effect"
|
import { Cause, Console, Context, Effect, Either, flow, Match, Option, Stream } from "effect"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { AppQueryErrorHandler } from "./query"
|
import { AppQueryErrorHandler } from "./query"
|
||||||
import { R } from "./reffuse"
|
import { R } from "./reffuse"
|
||||||
@@ -12,8 +12,8 @@ export function VQueryErrorHandler() {
|
|||||||
>>())
|
>>())
|
||||||
|
|
||||||
R.useFork(() => AppQueryErrorHandler.pipe(Effect.flatMap(handler =>
|
R.useFork(() => AppQueryErrorHandler.pipe(Effect.flatMap(handler =>
|
||||||
Stream.runForEach(handler.errors, v => Effect.sync(() =>
|
Stream.runForEach(handler.errors, v => Console.error(v).pipe(
|
||||||
setFailure(Option.some(v))
|
Effect.andThen(Effect.sync(() => { setFailure(Option.some(v)) }))
|
||||||
))
|
))
|
||||||
)), [])
|
)), [])
|
||||||
|
|
||||||
@@ -23,15 +23,22 @@ export function VQueryErrorHandler() {
|
|||||||
<AlertDialog.Content maxWidth="450px">
|
<AlertDialog.Content maxWidth="450px">
|
||||||
<AlertDialog.Title>Error</AlertDialog.Title>
|
<AlertDialog.Title>Error</AlertDialog.Title>
|
||||||
<AlertDialog.Description size="2">
|
<AlertDialog.Description size="2">
|
||||||
{Cause.failures(v).pipe(
|
{Either.match(Cause.failureOrCause(v), {
|
||||||
Chunk.head,
|
onLeft: flow(
|
||||||
Option.getOrThrow,
|
Match.value,
|
||||||
|
Match.tag("RequestError", () => <Text>HTTP request error</Text>),
|
||||||
|
Match.tag("ResponseError", () => <Text>HTTP response error</Text>),
|
||||||
|
Match.exhaustive,
|
||||||
|
),
|
||||||
|
|
||||||
Match.value,
|
onRight: flow(
|
||||||
Match.tag("RequestError", () => <Text>HTTP request error</Text>),
|
Cause.dieOption,
|
||||||
Match.tag("ResponseError", () => <Text>HTTP response error</Text>),
|
Option.match({
|
||||||
Match.exhaustive,
|
onSome: () => <Text>Unrecoverable defect</Text>,
|
||||||
)}
|
onNone: () => <Text>Unknown error</Text>,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
})}
|
||||||
</AlertDialog.Description>
|
</AlertDialog.Description>
|
||||||
|
|
||||||
<Flex gap="3" mt="4" justify="end">
|
<Flex gap="3" mt="4" justify="end">
|
||||||
|
|||||||
@@ -16,14 +16,19 @@ export const Route = createFileRoute("/query/usemutation")({
|
|||||||
const Result = Schema.Array(Schema.String)
|
const Result = Schema.Array(Schema.String)
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
const runSync = R.useRunSync()
|
const runFork = R.useRunFork()
|
||||||
|
|
||||||
const [count, setCount] = useState(1)
|
const [count, setCount] = useState(1)
|
||||||
|
|
||||||
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(QueryProgress.QueryProgress.update(() =>
|
||||||
|
AsyncData.Progress.make({ loaded: 0, total: Option.some(100) })
|
||||||
|
)),
|
||||||
Effect.andThen(Effect.sleep("500 millis")),
|
Effect.andThen(Effect.sleep("500 millis")),
|
||||||
Effect.tap(() => QueryProgress.QueryProgress.get),
|
Effect.tap(() => QueryProgress.QueryProgress.update(() =>
|
||||||
|
AsyncData.Progress.make({ loaded: 50, total: Option.some(100) })
|
||||||
|
)),
|
||||||
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),
|
||||||
@@ -63,8 +68,7 @@ function RouteComponent() {
|
|||||||
<Button onClick={() => mutation.forkMutate(count).pipe(
|
<Button onClick={() => mutation.forkMutate(count).pipe(
|
||||||
Effect.flatMap(([, state]) => Stream.runForEach(state, Console.log)),
|
Effect.flatMap(([, state]) => Stream.runForEach(state, Console.log)),
|
||||||
Effect.andThen(Console.log("Mutation done.")),
|
Effect.andThen(Console.log("Mutation done.")),
|
||||||
Effect.forkDaemon,
|
runFork,
|
||||||
runSync,
|
|
||||||
)}>
|
)}>
|
||||||
Get
|
Get
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user