5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,3 +1,6 @@
|
||||
{
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.biome": "explicit"
|
||||
}
|
||||
}
|
||||
|
||||
12
biome.json
12
biome.json
@@ -9,13 +9,19 @@
|
||||
"ignoreUnknown": false
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": false,
|
||||
"indentStyle": "tab"
|
||||
"enabled": false
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
"recommended": true,
|
||||
"style": {
|
||||
"useShorthandFunctionType": "off"
|
||||
},
|
||||
"suspicious": {
|
||||
"noExplicitAny": "off",
|
||||
"noShadowRestrictedNames": "off"
|
||||
}
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
||||
import { Effect, Function, Predicate, Runtime, Scope } from "effect"
|
||||
import * as React from "react"
|
||||
import type * as Component from "./Component.js"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the default type for React props */
|
||||
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
||||
import { Context, Effect, Effectable, ExecutionStrategy, Function, Predicate, Runtime, Scope, Tracer, type Types, type Utils } from "effect"
|
||||
import * as React from "react"
|
||||
import * as Hooks from "./Hooks/index.js"
|
||||
@@ -12,12 +14,12 @@ extends
|
||||
Effect.Effect<(props: P) => A, never, Exclude<R, Scope.Scope>>,
|
||||
Component.Options
|
||||
{
|
||||
new(_: never): {}
|
||||
new(_: never): Record<string, never>
|
||||
readonly [TypeId]: TypeId
|
||||
readonly ["~Props"]: P
|
||||
readonly ["~Success"]: A
|
||||
readonly ["~Error"]: E
|
||||
readonly ["~Context"]: R
|
||||
readonly "~Props": P
|
||||
readonly "~Success": A
|
||||
readonly "~Error": E
|
||||
readonly "~Context": R
|
||||
|
||||
/** @internal */
|
||||
readonly body: (props: P) => Effect.Effect<A, E, R>
|
||||
@@ -53,6 +55,7 @@ const ComponentProto = Object.freeze({
|
||||
this: Component<P, A, E, R>
|
||||
) {
|
||||
const self = this
|
||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
|
||||
runtimeRef.current = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as AsyncData from "@typed/async-data"
|
||||
import { Array, Cause, Chunk, Duration, Effect, Equal, Exit, Fiber, flow, identity, Option, ParseResult, pipe, Pipeable, Predicate, Ref, Schema, Scope, Stream, Subscribable, SubscriptionRef } from "effect"
|
||||
import { Array, Cause, Chunk, type Duration, Effect, Equal, Exit, Fiber, flow, identity, Option, ParseResult, Pipeable, Predicate, pipe, Ref, Schema, type Scope, Stream, type Subscribable, SubscriptionRef } from "effect"
|
||||
import type { NoSuchElementException } from "effect/Cause"
|
||||
import * as React from "react"
|
||||
import * as Hooks from "./Hooks/index.js"
|
||||
@@ -287,6 +287,7 @@ export const useField = <A, I, R, SA, SE, SR, const P extends PropertyPath.Paths
|
||||
): FormField<
|
||||
PropertyPath.ValueFromPath<A, P>,
|
||||
PropertyPath.ValueFromPath<I, P>
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: individual path components need to be compared
|
||||
> => React.useMemo(() => field(self, path), [self, ...path])
|
||||
|
||||
export namespace useInput {
|
||||
|
||||
@@ -11,8 +11,10 @@ export const useCallbackPromise: {
|
||||
callback: (...args: Args) => Effect.Effect<A, E, R>,
|
||||
deps: React.DependencyList,
|
||||
) {
|
||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||
const runtimeRef = React.useRef<Runtime.Runtime<R>>(null!)
|
||||
runtimeRef.current = yield* Effect.runtime<R>()
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
return React.useCallback((...args: Args) => Runtime.runPromise(runtimeRef.current)(callback(...args)), deps)
|
||||
})
|
||||
|
||||
@@ -11,8 +11,10 @@ export const useCallbackSync: {
|
||||
callback: (...args: Args) => Effect.Effect<A, E, R>,
|
||||
deps: React.DependencyList,
|
||||
) {
|
||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||
const runtimeRef = React.useRef<Runtime.Runtime<R>>(null!)
|
||||
runtimeRef.current = yield* Effect.runtime<R>()
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
return React.useCallback((...args: Args) => Runtime.runSync(runtimeRef.current)(callback(...args)), deps)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Effect, ExecutionStrategy, Runtime, Scope } from "effect"
|
||||
import * as React from "react"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
import { closeScope } from "./internal.js"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
|
||||
|
||||
export const useEffect: {
|
||||
@@ -24,5 +24,6 @@ export const useEffect: {
|
||||
() => closeScope(scope, runtime, options)
|
||||
),
|
||||
Runtime.runSync(runtime),
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
), deps)
|
||||
})
|
||||
|
||||
@@ -27,5 +27,6 @@ export const useFork: {
|
||||
...options,
|
||||
finalizerExecutionMode: options?.finalizerExecutionMode ?? "fork",
|
||||
})
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
}, deps)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Effect, ExecutionStrategy, Runtime, Scope } from "effect"
|
||||
import * as React from "react"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
import { closeScope } from "./internal.js"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
|
||||
|
||||
export const useLayoutEffect: {
|
||||
@@ -24,5 +24,6 @@ export const useLayoutEffect: {
|
||||
() => closeScope(scope, runtime, options)
|
||||
),
|
||||
Runtime.runSync(runtime),
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
), deps)
|
||||
})
|
||||
|
||||
@@ -12,5 +12,6 @@ export const useMemo: {
|
||||
deps: React.DependencyList,
|
||||
) {
|
||||
const runtime = yield* Effect.runtime()
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
return yield* React.useMemo(() => Runtime.runSync(runtime)(Effect.cached(factory())), deps)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Effect, Equivalence, Ref, Stream, SubscriptionRef } from "effect"
|
||||
import { Effect, Equivalence, Ref, Stream, type SubscriptionRef } from "effect"
|
||||
import * as React from "react"
|
||||
import * as SetStateAction from "../SetStateAction.js"
|
||||
import { useCallbackSync } from "./useCallbackSync.js"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Effect, ExecutionStrategy, Ref, Runtime, Scope } from "effect"
|
||||
import * as React from "react"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
import { closeScope } from "./internal.js"
|
||||
import type { ScopeOptions } from "./ScopeOptions.js"
|
||||
|
||||
|
||||
export const useScope: {
|
||||
@@ -12,6 +12,7 @@ export const useScope: {
|
||||
} = Effect.fnUntraced(function*(deps, options) {
|
||||
const runtime = yield* Effect.runtime()
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: no reactivity needed
|
||||
const [isInitialRun, initialScope] = React.useMemo(() => Runtime.runSync(runtime)(Effect.all([
|
||||
Ref.make(true),
|
||||
Scope.make(options?.finalizerExecutionStrategy ?? ExecutionStrategy.sequential),
|
||||
@@ -30,6 +31,7 @@ export const useScope: {
|
||||
Effect.map(scope => () => closeScope(scope, runtime, options)),
|
||||
),
|
||||
})
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||
), deps)
|
||||
|
||||
return scope
|
||||
|
||||
@@ -16,6 +16,7 @@ export const useSubscribeStream: {
|
||||
initialValue?: A,
|
||||
) {
|
||||
const [reactStateValue, setReactStateValue] = React.useState(
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: no reactivity needed
|
||||
React.useMemo(() => initialValue
|
||||
? Option.some(initialValue)
|
||||
: Option.none(),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
||||
import { type Equivalence, Function, Predicate } from "effect"
|
||||
import type * as Component from "./Component.js"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/** biome-ignore-all lint/complexity/useArrowFunction: necessary for class prototypes */
|
||||
import { Effect, type Layer, ManagedRuntime, Predicate, type Runtime } from "effect"
|
||||
import * as React from "react"
|
||||
|
||||
@@ -6,7 +7,7 @@ export const TypeId: unique symbol = Symbol.for("effect-fc/ReactRuntime")
|
||||
export type TypeId = typeof TypeId
|
||||
|
||||
export interface ReactRuntime<R, ER> {
|
||||
new(_: never): {}
|
||||
new(_: never): Record<string, never>
|
||||
readonly [TypeId]: TypeId
|
||||
readonly runtime: ManagedRuntime.ManagedRuntime<R, ER>
|
||||
readonly context: React.Context<Runtime.Runtime<R>>
|
||||
@@ -23,6 +24,7 @@ export const make = <R, ER>(
|
||||
): ReactRuntime<R, ER> => Object.setPrototypeOf(
|
||||
Object.assign(function() {}, {
|
||||
runtime: ManagedRuntime.make(layer, memoMap),
|
||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||
context: React.createContext<Runtime.Runtime<R>>(null!),
|
||||
}),
|
||||
ReactRuntimeProto,
|
||||
@@ -48,16 +50,14 @@ export const Provider = <R, ER>(
|
||||
)
|
||||
}
|
||||
|
||||
namespace ProviderInner {
|
||||
export interface Props<R, ER> {
|
||||
interface ProviderInnerProps<R, ER> {
|
||||
readonly runtime: ReactRuntime<R, ER>
|
||||
readonly promise: Promise<Runtime.Runtime<R>>
|
||||
readonly children?: React.ReactNode
|
||||
}
|
||||
}
|
||||
|
||||
const ProviderInner = <R, ER>(
|
||||
{ runtime, promise, children }: ProviderInner.Props<R, ER>
|
||||
{ runtime, promise, children }: ProviderInnerProps<R, ER>
|
||||
): React.ReactNode => React.createElement(
|
||||
runtime.context,
|
||||
{ value: React.use(promise) },
|
||||
|
||||
Reference in New Issue
Block a user