This commit is contained in:
@@ -295,7 +295,7 @@ export namespace useInput {
|
|||||||
readonly debounce?: Duration.DurationInput
|
readonly debounce?: Duration.DurationInput
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Result<T> {
|
export interface Success<T> {
|
||||||
readonly value: T
|
readonly value: T
|
||||||
readonly setValue: React.Dispatch<React.SetStateAction<T>>
|
readonly setValue: React.Dispatch<React.SetStateAction<T>>
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ export namespace useInput {
|
|||||||
export const useInput = Effect.fnUntraced(function* <A, I>(
|
export const useInput = Effect.fnUntraced(function* <A, I>(
|
||||||
field: FormField<A, I>,
|
field: FormField<A, I>,
|
||||||
options?: useInput.Options,
|
options?: useInput.Options,
|
||||||
): Effect.fn.Return<useInput.Result<I>, Cause.NoSuchElementException, Scope.Scope> {
|
): Effect.fn.Return<useInput.Success<I>, Cause.NoSuchElementException, Scope.Scope> {
|
||||||
const internalValueRef = yield* Component.useOnChange(() => Effect.tap(
|
const internalValueRef = yield* Component.useOnChange(() => Effect.tap(
|
||||||
Effect.andThen(field.encodedValue, SubscriptionRef.make),
|
Effect.andThen(field.encodedValue, SubscriptionRef.make),
|
||||||
internalValueRef => Effect.forkScoped(Effect.all([
|
internalValueRef => Effect.forkScoped(Effect.all([
|
||||||
@@ -336,7 +336,7 @@ export namespace useOptionalInput {
|
|||||||
readonly defaultValue: T
|
readonly defaultValue: T
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Result<T> extends useInput.Result<T> {
|
export interface Success<T> extends useInput.Success<T> {
|
||||||
readonly enabled: boolean
|
readonly enabled: boolean
|
||||||
readonly setEnabled: React.Dispatch<React.SetStateAction<boolean>>
|
readonly setEnabled: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ export namespace useOptionalInput {
|
|||||||
export const useOptionalInput = Effect.fnUntraced(function* <A, I>(
|
export const useOptionalInput = Effect.fnUntraced(function* <A, I>(
|
||||||
field: FormField<A, Option.Option<I>>,
|
field: FormField<A, Option.Option<I>>,
|
||||||
options: useOptionalInput.Options<I>,
|
options: useOptionalInput.Options<I>,
|
||||||
): Effect.fn.Return<useOptionalInput.Result<I>, Cause.NoSuchElementException, Scope.Scope> {
|
): Effect.fn.Return<useOptionalInput.Success<I>, Cause.NoSuchElementException, Scope.Scope> {
|
||||||
const [enabledRef, internalValueRef] = yield* Component.useOnChange(() => Effect.tap(
|
const [enabledRef, internalValueRef] = yield* Component.useOnChange(() => Effect.tap(
|
||||||
Effect.andThen(
|
Effect.andThen(
|
||||||
field.encodedValue,
|
field.encodedValue,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import * as Result from "./Result.js"
|
|||||||
export const MutationTypeId: unique symbol = Symbol.for("@effect-fc/Mutation/Mutation")
|
export const MutationTypeId: unique symbol = Symbol.for("@effect-fc/Mutation/Mutation")
|
||||||
export type MutationTypeId = typeof MutationTypeId
|
export type MutationTypeId = typeof MutationTypeId
|
||||||
|
|
||||||
export interface Mutation<in out K extends readonly any[], in out A, in out E = never, in out R = never, in out P = never>
|
export interface Mutation<in out K extends Mutation.AnyKey, in out A, in out E = never, in out R = never, in out P = never>
|
||||||
extends Pipeable.Pipeable {
|
extends Pipeable.Pipeable {
|
||||||
readonly [MutationTypeId]: MutationTypeId
|
readonly [MutationTypeId]: MutationTypeId
|
||||||
|
|
||||||
@@ -21,7 +21,11 @@ extends Pipeable.Pipeable {
|
|||||||
mutateSubscribable(key: K): Effect.Effect<Subscribable.Subscribable<Result.Result<A, E, P>>>
|
mutateSubscribable(key: K): Effect.Effect<Subscribable.Subscribable<Result.Result<A, E, P>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MutationImpl<in out K extends readonly any[], in out A, in out E = never, in out R = never, in out P = never>
|
export declare namespace Mutation {
|
||||||
|
export type AnyKey = readonly any[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MutationImpl<in out K extends Mutation.AnyKey, in out A, in out E = never, in out R = never, in out P = never>
|
||||||
extends Pipeable.Class() implements Mutation<K, A, E, R, P> {
|
extends Pipeable.Class() implements Mutation<K, A, E, R, P> {
|
||||||
readonly [MutationTypeId]: MutationTypeId = MutationTypeId
|
readonly [MutationTypeId]: MutationTypeId = MutationTypeId
|
||||||
|
|
||||||
@@ -95,16 +99,16 @@ extends Pipeable.Class() implements Mutation<K, A, E, R, P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isMutation = (u: unknown): u is Mutation<unknown[], unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, MutationTypeId)
|
export const isMutation = (u: unknown): u is Mutation<readonly unknown[], unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, MutationTypeId)
|
||||||
|
|
||||||
export declare namespace make {
|
export declare namespace make {
|
||||||
export interface Options<K extends readonly any[] = never, A = void, E = never, R = never, P = never> {
|
export interface Options<K extends Mutation.AnyKey = never, A = void, E = never, R = never, P = never> {
|
||||||
readonly f: (key: K) => Effect.Effect<A, E, Result.forkEffect.InputContext<R, NoInfer<P>>>
|
readonly f: (key: K) => Effect.Effect<A, E, Result.forkEffect.InputContext<R, NoInfer<P>>>
|
||||||
readonly initialProgress?: P
|
readonly initialProgress?: P
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const make = Effect.fnUntraced(function* <const K extends readonly any[] = never, A = void, E = never, R = never, P = never>(
|
export const make = Effect.fnUntraced(function* <const K extends Mutation.AnyKey = never, A = void, E = never, R = never, P = never>(
|
||||||
options: make.Options<K, A, E, R, P>
|
options: make.Options<K, A, E, R, P>
|
||||||
): Effect.fn.Return<
|
): Effect.fn.Return<
|
||||||
Mutation<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
Mutation<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import * as Result from "./Result.js"
|
|||||||
export const QueryTypeId: unique symbol = Symbol.for("@effect-fc/Query/Query")
|
export const QueryTypeId: unique symbol = Symbol.for("@effect-fc/Query/Query")
|
||||||
export type QueryTypeId = typeof QueryTypeId
|
export type QueryTypeId = typeof QueryTypeId
|
||||||
|
|
||||||
export interface Query<in out K extends readonly any[], in out A, in out E = never, in out R = never, in out P = never>
|
export interface Query<in out K extends Query.AnyKey, in out A, in out E = never, in out R = never, in out P = never>
|
||||||
extends Pipeable.Pipeable {
|
extends Pipeable.Pipeable {
|
||||||
readonly [QueryTypeId]: QueryTypeId
|
readonly [QueryTypeId]: QueryTypeId
|
||||||
|
|
||||||
@@ -26,7 +26,11 @@ extends Pipeable.Pipeable {
|
|||||||
readonly refreshSubscribable: Effect.Effect<Subscribable.Subscribable<Result.Result<A, E, P>>, Cause.NoSuchElementException>
|
readonly refreshSubscribable: Effect.Effect<Subscribable.Subscribable<Result.Result<A, E, P>>, Cause.NoSuchElementException>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class QueryImpl<in out K extends readonly any[], in out A, in out E = never, in out R = never, in out P = never>
|
export declare namespace Query {
|
||||||
|
export type AnyKey = readonly any[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export class QueryImpl<in out K extends Query.AnyKey, in out A, in out E = never, in out R = never, in out P = never>
|
||||||
extends Pipeable.Class() implements Query<K, A, E, R, P> {
|
extends Pipeable.Class() implements Query<K, A, E, R, P> {
|
||||||
readonly [QueryTypeId]: QueryTypeId = QueryTypeId
|
readonly [QueryTypeId]: QueryTypeId = QueryTypeId
|
||||||
|
|
||||||
@@ -136,17 +140,17 @@ extends Pipeable.Class() implements Query<K, A, E, R, P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isQuery = (u: unknown): u is Query<unknown[], unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, QueryTypeId)
|
export const isQuery = (u: unknown): u is Query<readonly unknown[], unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, QueryTypeId)
|
||||||
|
|
||||||
export declare namespace make {
|
export declare namespace make {
|
||||||
export interface Options<K extends readonly any[], A, E = never, R = never, P = never> {
|
export interface Options<K extends Query.AnyKey, A, E = never, R = never, P = never> {
|
||||||
readonly key: Stream.Stream<K>
|
readonly key: Stream.Stream<K>
|
||||||
readonly f: (key: NoInfer<K>) => Effect.Effect<A, E, Result.forkEffect.InputContext<R, NoInfer<P>>>
|
readonly f: (key: NoInfer<K>) => Effect.Effect<A, E, Result.forkEffect.InputContext<R, NoInfer<P>>>
|
||||||
readonly initialProgress?: P
|
readonly initialProgress?: P
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const make = Effect.fnUntraced(function* <K extends readonly any[], A, E = never, R = never, P = never>(
|
export const make = Effect.fnUntraced(function* <K extends Query.AnyKey, A, E = never, R = never, P = never>(
|
||||||
options: make.Options<K, A, E, R, P>
|
options: make.Options<K, A, E, R, P>
|
||||||
): Effect.fn.Return<
|
): Effect.fn.Return<
|
||||||
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
||||||
@@ -167,7 +171,7 @@ export const make = Effect.fnUntraced(function* <K extends readonly any[], A, E
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const service = <K extends readonly any[], A, E = never, R = never, P = never>(
|
export const service = <K extends Query.AnyKey, A, E = never, R = never, P = never>(
|
||||||
options: make.Options<K, A, E, R, P>
|
options: make.Options<K, A, E, R, P>
|
||||||
): Effect.Effect<
|
): Effect.Effect<
|
||||||
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
Query<K, A, E, Result.forkEffect.OutputContext<A, E, R, P>, P>,
|
||||||
@@ -178,7 +182,7 @@ export const service = <K extends readonly any[], A, E = never, R = never, P = n
|
|||||||
query => Effect.forkScoped(run(query)),
|
query => Effect.forkScoped(run(query)),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const run = <K extends readonly any[], A, E, R, P>(
|
export const run = <K extends Query.AnyKey, A, E, R, P>(
|
||||||
self: Query<K, A, E, R, P>
|
self: Query<K, A, E, R, P>
|
||||||
): Effect.Effect<void> => {
|
): Effect.Effect<void> => {
|
||||||
const _self = self as QueryImpl<K, A, E, R, P>
|
const _self = self as QueryImpl<K, A, E, R, P>
|
||||||
|
|||||||
25
packages/effect-fc/src/QueryClient.ts
Normal file
25
packages/effect-fc/src/QueryClient.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { type HashMap, Pipeable, Predicate, type Subscribable, type SubscriptionRef } from "effect"
|
||||||
|
import type * as Query from "./Query.js"
|
||||||
|
import type * as Result from "./Result.js"
|
||||||
|
|
||||||
|
|
||||||
|
export const QueryClientTypeId: unique symbol = Symbol.for("@effect-fc/QueryClient/QueryClient")
|
||||||
|
export type QueryClientTypeId = typeof QueryClientTypeId
|
||||||
|
|
||||||
|
export interface QueryClient extends Pipeable.Pipeable {
|
||||||
|
readonly [QueryClientTypeId]: QueryClientTypeId
|
||||||
|
|
||||||
|
readonly cache: Subscribable.Subscribable<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||||
|
}
|
||||||
|
|
||||||
|
export class QueryClientImpl extends Pipeable.Class() implements QueryClient {
|
||||||
|
readonly [QueryClientTypeId]: QueryClientTypeId = QueryClientTypeId
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
readonly cache: SubscriptionRef.SubscriptionRef<HashMap.HashMap<Query.Query.AnyKey, Result.Final<unknown, unknown, unknown>>>
|
||||||
|
) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isQueryClient = (u: unknown): u is QueryClient => Predicate.hasProperty(u, QueryClientTypeId)
|
||||||
@@ -7,6 +7,7 @@ export * as Mutation from "./Mutation.js"
|
|||||||
export * as PropertyPath from "./PropertyPath.js"
|
export * as PropertyPath from "./PropertyPath.js"
|
||||||
export * as PubSub from "./PubSub.js"
|
export * as PubSub from "./PubSub.js"
|
||||||
export * as Query from "./Query.js"
|
export * as Query from "./Query.js"
|
||||||
|
export * as QueryClient from "./QueryClient.js"
|
||||||
export * as ReactRuntime from "./ReactRuntime.js"
|
export * as ReactRuntime from "./ReactRuntime.js"
|
||||||
export * as Result from "./Result.js"
|
export * as Result from "./Result.js"
|
||||||
export * as SetStateAction from "./SetStateAction.js"
|
export * as SetStateAction from "./SetStateAction.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user