0.1.8 #11
@@ -1,12 +1,14 @@
|
||||
import * as AsyncData from "@typed/async-data"
|
||||
import { type Context, Effect, Ref, SubscriptionRef } from "effect"
|
||||
import { type Context, Effect, type Fiber, Ref, SubscriptionRef } from "effect"
|
||||
import type * as QueryClient from "./QueryClient.js"
|
||||
|
||||
|
||||
export interface MutationRunner<K extends readonly unknown[], A, E, R> {
|
||||
readonly context: Context.Context<R>
|
||||
readonly stateRef: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||
|
||||
readonly mutate: (...key: K) => Effect.Effect<A, E>
|
||||
readonly forkMutate: (...key: K) => Effect.Effect<Fiber.RuntimeFiber<A, E>>
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +42,13 @@ export const make = <EH, K extends readonly unknown[], A, E, HandledE, R>(
|
||||
Effect.provide(context),
|
||||
)
|
||||
|
||||
const forkMutate = (...key: K) => Effect.forkDaemon(mutate(...key))
|
||||
|
||||
return {
|
||||
context,
|
||||
stateRef,
|
||||
|
||||
mutate,
|
||||
forkMutate,
|
||||
}
|
||||
})
|
||||
|
||||
13
packages/extension-query/src/MutationService.ts
Normal file
13
packages/extension-query/src/MutationService.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type * as AsyncData from "@typed/async-data"
|
||||
import { Effect, type Fiber, type SubscriptionRef } from "effect"
|
||||
|
||||
|
||||
export interface MutationService<K extends readonly unknown[], A, E> {
|
||||
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||
readonly mutate: (...key: K) => Effect.Effect<A, E>
|
||||
readonly forkMutate: (...key: K) => Effect.Effect<Fiber.RuntimeFiber<A, E>>
|
||||
}
|
||||
|
||||
export const Tag = <const Id extends string>(id: Id) => <
|
||||
Self, K extends readonly unknown[], A, E = never,
|
||||
>() => Effect.Tag(id)<Self, MutationService<K, A, E>>()
|
||||
@@ -3,6 +3,7 @@ import { type Cause, type Context, Effect, type Fiber, Layer, type Option, type
|
||||
import * as React from "react"
|
||||
import { ReffuseExtension, type ReffuseHelpers } from "reffuse"
|
||||
import * as MutationRunner from "./MutationRunner.js"
|
||||
import type * as MutationService from "./MutationService.js"
|
||||
import * as QueryClient from "./QueryClient.js"
|
||||
import * as QueryRunner from "./QueryRunner.js"
|
||||
import type * as QueryService from "./QueryService.js"
|
||||
@@ -31,10 +32,12 @@ export interface UseMutationProps<K extends readonly unknown[], A, E, R> {
|
||||
|
||||
export interface UseMutationResult<K extends readonly unknown[], A, E> {
|
||||
readonly state: SubscriptionRef.SubscriptionRef<AsyncData.AsyncData<A, E>>
|
||||
readonly mutate: (...key: K) => Effect.Effect<A, E>
|
||||
readonly forkMutate: (...key: K) => Effect.Effect<Fiber.RuntimeFiber<A, E>>
|
||||
|
||||
// readonly layer: <Self, Id extends string>(
|
||||
// tag: Context.TagClass<Self, Id, QueryService.QueryService<K, A, E>>
|
||||
// ) => Layer.Layer<Self>
|
||||
readonly layer: <Self, Id extends string>(
|
||||
tag: Context.TagClass<Self, Id, MutationService.MutationService<K, A, E>>
|
||||
) => Layer.Layer<Self>
|
||||
}
|
||||
|
||||
|
||||
@@ -96,12 +99,14 @@ export const QueryExtension = ReffuseExtension.make(() => ({
|
||||
|
||||
return React.useMemo(() => ({
|
||||
state: runner.stateRef,
|
||||
mutate: runner.mutate,
|
||||
forkMutate: runner.forkMutate,
|
||||
|
||||
// layer: tag => Layer.succeed(tag, {
|
||||
// latestKey: runner.latestKeyRef,
|
||||
// state: runner.stateRef,
|
||||
// refresh: runner.forkRefresh,
|
||||
// }),
|
||||
layer: tag => Layer.succeed(tag, {
|
||||
state: runner.stateRef,
|
||||
mutate: runner.mutate,
|
||||
forkMutate: runner.forkMutate,
|
||||
}),
|
||||
}), [runner])
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export * as ErrorHandler from "./ErrorHandler.js"
|
||||
export * as MutationRunner from "./MutationRunner.js"
|
||||
export * as MutationService from "./MutationService.js"
|
||||
export * as QueryClient from "./QueryClient.js"
|
||||
export * from "./QueryExtension.js"
|
||||
export * as QueryRunner from "./QueryRunner.js"
|
||||
|
||||
Reference in New Issue
Block a user