Tests
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-01-10 22:34:53 +01:00
parent 00bf5a3c63
commit 5f455295ad
2 changed files with 13 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
import { Ref } from "effect"
import "./App.css"
import reactLogo from "./assets/react.svg"
import { Reffuse } from "./Reffuse"
@@ -6,7 +7,10 @@ import viteLogo from "/vite.svg"
export function App() {
const [count, setCount] = Reffuse.useRefState(Reffuse.useRef(0))
const runtime = Reffuse.useRuntime()
const countRef = Reffuse.useRef(0)
const [count] = Reffuse.useRefState(countRef)
return <>
@@ -20,7 +24,8 @@ export function App() {
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
{/* <button onClick={() => setCount((count) => count + 1)}> */}
<button onClick={() => Ref.update(countRef, count => count + 1).pipe(runtime.runSync)}>
count is {count}
</button>
<p>

View File

@@ -26,29 +26,29 @@ export class Reffuse<R, ER> {
}
runSync<A, E>(effect: Effect.Effect<A, E, R>): A {
useRunSync<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> {
useRunSyncExit<A, E>(effect: Effect.Effect<A, E, R>): Exit.Exit<A, ER | E> {
return this.useRuntime().runSyncExit(effect)
}
runPromise<A, E>(
useRunPromise<A, E>(
effect: Effect.Effect<A, E, R>,
options?: { readonly signal?: AbortSignal },
): Promise<A> {
return this.useRuntime().runPromise(effect, options)
}
runPromiseExit<A, E>(
useRunPromiseExit<A, E>(
effect: Effect.Effect<A, E, R>,
options?: { readonly signal?: AbortSignal },
): Promise<Exit.Exit<A, ER | E>> {
return this.useRuntime().runPromiseExit(effect, options)
}
runFork<A, E>(
useRunFork<A, E>(
self: Effect.Effect<A, E, R>,
options?: Runtime.RunForkOptions,
): Fiber.RuntimeFiber<A, ER | E> {
@@ -66,7 +66,7 @@ export class Reffuse<R, ER> {
return React.useEffect(() => {
const fiber = runtime.runFork(self.pipe(Effect.scoped), options)
return () => { runtime.runFork(Fiber.interrupt(fiber)) }
}, deps)
}, [runtime, ...deps ?? []])
}