@@ -1,3 +1,4 @@
|
|||||||
|
import { Ref } from "effect"
|
||||||
import "./App.css"
|
import "./App.css"
|
||||||
import reactLogo from "./assets/react.svg"
|
import reactLogo from "./assets/react.svg"
|
||||||
import { Reffuse } from "./Reffuse"
|
import { Reffuse } from "./Reffuse"
|
||||||
@@ -6,7 +7,10 @@ import viteLogo from "/vite.svg"
|
|||||||
|
|
||||||
export function App() {
|
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 <>
|
return <>
|
||||||
@@ -20,7 +24,8 @@ export function App() {
|
|||||||
</div>
|
</div>
|
||||||
<h1>Vite + React</h1>
|
<h1>Vite + React</h1>
|
||||||
<div className="card">
|
<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}
|
count is {count}
|
||||||
</button>
|
</button>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -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)
|
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)
|
return this.useRuntime().runSyncExit(effect)
|
||||||
}
|
}
|
||||||
|
|
||||||
runPromise<A, E>(
|
useRunPromise<A, E>(
|
||||||
effect: Effect.Effect<A, E, R>,
|
effect: Effect.Effect<A, E, R>,
|
||||||
options?: { readonly signal?: AbortSignal },
|
options?: { readonly signal?: AbortSignal },
|
||||||
): Promise<A> {
|
): Promise<A> {
|
||||||
return this.useRuntime().runPromise(effect, options)
|
return this.useRuntime().runPromise(effect, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
runPromiseExit<A, E>(
|
useRunPromiseExit<A, E>(
|
||||||
effect: Effect.Effect<A, E, R>,
|
effect: Effect.Effect<A, E, R>,
|
||||||
options?: { readonly signal?: AbortSignal },
|
options?: { readonly signal?: AbortSignal },
|
||||||
): Promise<Exit.Exit<A, ER | E>> {
|
): Promise<Exit.Exit<A, ER | E>> {
|
||||||
return this.useRuntime().runPromiseExit(effect, options)
|
return this.useRuntime().runPromiseExit(effect, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
runFork<A, E>(
|
useRunFork<A, E>(
|
||||||
self: Effect.Effect<A, E, R>,
|
self: Effect.Effect<A, E, R>,
|
||||||
options?: Runtime.RunForkOptions,
|
options?: Runtime.RunForkOptions,
|
||||||
): Fiber.RuntimeFiber<A, ER | E> {
|
): Fiber.RuntimeFiber<A, ER | E> {
|
||||||
@@ -66,7 +66,7 @@ export class Reffuse<R, ER> {
|
|||||||
return React.useEffect(() => {
|
return React.useEffect(() => {
|
||||||
const fiber = runtime.runFork(self.pipe(Effect.scoped), options)
|
const fiber = runtime.runFork(self.pipe(Effect.scoped), options)
|
||||||
return () => { runtime.runFork(Fiber.interrupt(fiber)) }
|
return () => { runtime.runFork(Fiber.interrupt(fiber)) }
|
||||||
}, deps)
|
}, [runtime, ...deps ?? []])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user