0.2.0 #18
@@ -5,7 +5,7 @@ import * as React from "react"
|
|||||||
import { Memoized } from "./index.js"
|
import { Memoized } from "./index.js"
|
||||||
|
|
||||||
|
|
||||||
export const TypeId: unique symbol = Symbol.for("effect-fc/Component")
|
export const TypeId: unique symbol = Symbol.for("effect-fc/Component/Component")
|
||||||
export type TypeId = typeof TypeId
|
export type TypeId = typeof TypeId
|
||||||
|
|
||||||
export interface Component<P extends {}, A extends React.ReactNode, E, R>
|
export interface Component<P extends {}, A extends React.ReactNode, E, R>
|
||||||
@@ -60,8 +60,8 @@ const ComponentProto = Object.freeze({
|
|||||||
) {
|
) {
|
||||||
const self = this
|
const self = this
|
||||||
// biome-ignore lint/style/noNonNullAssertion: React ref initialization
|
// biome-ignore lint/style/noNonNullAssertion: React ref initialization
|
||||||
const runtimeRef = React.useRef<Runtime.Runtime<ComponentScopeMap | Exclude<R, Scope.Scope>>>(null!)
|
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
|
||||||
runtimeRef.current = yield* Effect.runtime<ComponentScopeMap | Exclude<R, Scope.Scope>>()
|
runtimeRef.current = yield* Effect.runtime<Exclude<R, Scope.Scope>>()
|
||||||
|
|
||||||
return React.useRef(function ScopeProvider(props: P) {
|
return React.useRef(function ScopeProvider(props: P) {
|
||||||
const scope = Runtime.runSync(runtimeRef.current)(useScope(
|
const scope = Runtime.runSync(runtimeRef.current)(useScope(
|
||||||
@@ -433,14 +433,14 @@ export const useScope: {
|
|||||||
(
|
(
|
||||||
deps: React.DependencyList,
|
deps: React.DependencyList,
|
||||||
options?: ScopeOptions,
|
options?: ScopeOptions,
|
||||||
): Effect.Effect<Scope.Scope, never, ComponentScopeMap>
|
): Effect.Effect<Scope.Scope>
|
||||||
} = Effect.fnUntraced(function*(deps, options) {
|
} = Effect.fnUntraced(function*(deps, options) {
|
||||||
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||||
const runtimeRef = React.useRef<Runtime.Runtime<never>>(null!)
|
const runtimeRef = React.useRef<Runtime.Runtime<never>>(null!)
|
||||||
runtimeRef.current = yield* Effect.runtime()
|
runtimeRef.current = yield* Effect.runtime()
|
||||||
|
|
||||||
const key = React.useId()
|
const key = React.useId()
|
||||||
const scopeMap = yield* ComponentScopeMap
|
const scopeMap = yield* ComponentScopeMap as unknown as Effect.Effect<ComponentScopeMap>
|
||||||
|
|
||||||
const scope = React.useMemo(() => Runtime.runSync(runtimeRef.current)(Effect.andThen(
|
const scope = React.useMemo(() => Runtime.runSync(runtimeRef.current)(Effect.andThen(
|
||||||
scopeMap.ref,
|
scopeMap.ref,
|
||||||
@@ -610,7 +610,7 @@ export const useContext: {
|
|||||||
<ROut, E, RIn>(
|
<ROut, E, RIn>(
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
layer: Layer.Layer<ROut, E, RIn>,
|
||||||
options?: ScopeOptions,
|
options?: ScopeOptions,
|
||||||
): Effect.Effect<Context.Context<ROut>, E, RIn | ComponentScopeMap>
|
): Effect.Effect<Context.Context<ROut>, E, RIn>
|
||||||
} = Effect.fnUntraced(function* <ROut, E, RIn>(
|
} = Effect.fnUntraced(function* <ROut, E, RIn>(
|
||||||
layer: Layer.Layer<ROut, E, RIn>,
|
layer: Layer.Layer<ROut, E, RIn>,
|
||||||
options?: ScopeOptions,
|
options?: ScopeOptions,
|
||||||
|
|||||||
Reference in New Issue
Block a user