Cleanup
All checks were successful
Lint / lint (push) Successful in 11s

This commit is contained in:
Julien Valverdé
2025-01-22 00:59:40 +01:00
parent 3004235690
commit 175cbaa704

View File

@@ -1,4 +1,4 @@
import { Context, Effect, ExecutionStrategy, Exit, Fiber, Option, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
import { Context, Effect, ExecutionStrategy, Exit, Fiber, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
import React from "react"
import * as ReffuseContext from "./ReffuseContext.js"
import * as ReffuseRuntime from "./ReffuseRuntime.js"
@@ -69,48 +69,6 @@ export class Reffuse<R> {
}
/**
* ⚠️ Scope closing on cleanup is currently broken when using React strict mode! ⚠️
*
* Reffuse equivalent to `React.useMemo`.
*
* `useMemo` will only recompute the memoized value by running the given synchronous effect when one of the deps has changed. \
* Trying to run an asynchronous effect will throw.
*
* Changes to the Reffuse runtime or context will recompute the value in addition to the deps.
* You can disable this behavior by setting `doNotReExecuteOnRuntimeOrContextChange` to `true` in `options`.
*/
// useMemo<A, E>(
// effect: Effect.Effect<A, E, R | Scope.Scope>,
// deps?: React.DependencyList,
// options?: RenderOptions & ScopeOptions,
// ): A {
// const runSync = this.useRunSync()
// const [value, scope] = React.useMemo(() => Scope.make(options?.finalizerExecutionStrategy).pipe(
// Effect.flatMap(scope =>
// Effect.provideService(effect, Scope.Scope, scope).pipe(
// Effect.map(value => [value, scope] as const)
// )
// ),
// runSync,
// ), [
// ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
// ...(deps ?? []),
// ])
// React.useEffect(() => {
// // console.log("effect", value, scope)
// return () => {
// // console.log("cleanup", value, scope)
// runSync(Scope.close(scope, Exit.void))
// }
// }, [scope])
// return value
// }
/**
* Reffuse equivalent to `React.useMemo`.
*
@@ -381,17 +339,6 @@ export class Reffuse<R> {
return [reactStateValue, setValue]
}
useStreamState<A, E>(stream: Stream.Stream<A, E, R>): Option.Option<A> {
const [reactStateValue, setReactStateValue] = React.useState(Option.none<A>())
this.useFork(Stream.runForEach(stream, v => Effect.sync(() =>
setReactStateValue(Option.some(v))
)), [stream])
return reactStateValue
}
}