0.1.0 #1
@@ -19,7 +19,7 @@ export class Reffuse<
|
|||||||
) {
|
) {
|
||||||
this.Provider = parent
|
this.Provider = parent
|
||||||
? ReffuseReactContext.makeNestedProvider(runtime, this.Context, parent)
|
? ReffuseReactContext.makeNestedProvider(runtime, this.Context, parent)
|
||||||
: ReffuseReactContext.makeRootProvider<RuntimeR, OwnContextR>(runtime, this.Context)
|
: ReffuseReactContext.makeRootProvider(runtime, this.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,15 +24,21 @@ export interface ProviderProps<
|
|||||||
readonly children?: React.ReactNode
|
readonly children?: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeRootProvider<RuntimeR, ContextR>(
|
export function makeRootProvider<
|
||||||
|
RuntimeR,
|
||||||
|
ContextR extends ParentContextR | OwnContextR,
|
||||||
|
OwnContextR,
|
||||||
|
ParentContextR,
|
||||||
|
>(
|
||||||
runtime: Runtime.Runtime<RuntimeR>,
|
runtime: Runtime.Runtime<RuntimeR>,
|
||||||
ReactContext: React.Context<Value<RuntimeR, ContextR>>,
|
ReactContext: React.Context<Value<RuntimeR, ContextR>>,
|
||||||
): Provider<RuntimeR, ContextR, never> {
|
): Provider<RuntimeR, OwnContextR, ParentContextR> {
|
||||||
return function ReffuseRootReactContextProvider(props) {
|
return function ReffuseRootReactContextProvider(props) {
|
||||||
const value = React.useMemo(() => ({
|
const value = React.useMemo(() => ({
|
||||||
runtime,
|
runtime,
|
||||||
context: Effect.context<ContextR>().pipe(
|
context: Effect.context<ContextR>().pipe(
|
||||||
Effect.provide(props.layer),
|
Effect.provide(props.layer),
|
||||||
|
Effect.provide(Context.empty() as Context.Context<ParentContextR>), // Just there for type safety. ParentContextR is always never here anyway
|
||||||
Runtime.runSync(runtime),
|
Runtime.runSync(runtime),
|
||||||
),
|
),
|
||||||
}), [props.layer])
|
}), [props.layer])
|
||||||
|
|||||||
Reference in New Issue
Block a user