0.1.0 #1

Merged
Thilawyn merged 87 commits from next into master 2025-01-18 00:54:42 +01:00
2 changed files with 9 additions and 3 deletions
Showing only changes of commit cf0951039c - Show all commits

View File

@@ -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)
} }

View File

@@ -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])