0.1.0 #1
@@ -24,5 +24,9 @@
|
|||||||
"clean:node": "rm -rf node_modules"
|
"clean:node": "rm -rf node_modules"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/react": "^19.0.4",
|
||||||
|
"effect": "^3.12.1",
|
||||||
|
"react": "^19.0.0",
|
||||||
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
50
packages/reffuse/src/Reffuse.ts
Normal file
50
packages/reffuse/src/Reffuse.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { Effect, Exit, ManagedRuntime } from "effect"
|
||||||
|
import { createContext, useContext, type Context, type ReactNode } from "react"
|
||||||
|
|
||||||
|
|
||||||
|
export class Reffuse<R, ER> {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly runtime: ManagedRuntime.ManagedRuntime<R, ER>
|
||||||
|
) {
|
||||||
|
this.Context = createContext(runtime)
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly Context: Context<ManagedRuntime.ManagedRuntime<R, ER>>
|
||||||
|
|
||||||
|
Provider(props: { readonly children: ReactNode }) {
|
||||||
|
return this.Context.Provider({
|
||||||
|
...props,
|
||||||
|
value: this.runtime,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
useRuntime(): ManagedRuntime.ManagedRuntime<R, ER> {
|
||||||
|
return useContext(this.Context)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
runSync<A, E>(effect: Effect.Effect<A, E, R>): A {
|
||||||
|
return this.useRuntime().runSync(effect)
|
||||||
|
}
|
||||||
|
|
||||||
|
runSyncExit<A, E>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, ER | E> {
|
||||||
|
return this.useRuntime().runSyncExit(effect)
|
||||||
|
}
|
||||||
|
|
||||||
|
runPromise<A, E>(
|
||||||
|
effect: Effect.Effect<A, E, R>,
|
||||||
|
options?: { readonly signal?: AbortSignal },
|
||||||
|
): Promise<A> {
|
||||||
|
return this.useRuntime().runPromise(effect, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
runPromiseExit<A, E>(
|
||||||
|
effect: Effect.Effect<A, E, R>,
|
||||||
|
options?: { readonly signal?: AbortSignal },
|
||||||
|
): Promise<Exit.Exit<A, ER | E>> {
|
||||||
|
return this.useRuntime().runPromiseExit(effect, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * as Reffuse from "./Reffuse.js"
|
||||||
|
|||||||
Reference in New Issue
Block a user