0.1.0 #1

Merged
Thilawyn merged 87 commits from next into master 2025-01-18 00:54:42 +01:00
4 changed files with 55 additions and 0 deletions
Showing only changes of commit 107d1ba359 - Show all commits

BIN
bun.lockb Executable file

Binary file not shown.

View File

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

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

View File

@@ -0,0 +1 @@
export * as Reffuse from "./Reffuse.js"