@@ -80,36 +80,36 @@ export class Reffuse<R> {
|
|||||||
* Changes to the Reffuse runtime or context will recompute the value in addition to the deps.
|
* 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`.
|
* You can disable this behavior by setting `doNotReExecuteOnRuntimeOrContextChange` to `true` in `options`.
|
||||||
*/
|
*/
|
||||||
useMemo<A, E>(
|
// useMemo<A, E>(
|
||||||
effect: Effect.Effect<A, E, R | Scope.Scope>,
|
// effect: Effect.Effect<A, E, R | Scope.Scope>,
|
||||||
deps?: React.DependencyList,
|
// deps?: React.DependencyList,
|
||||||
options?: RenderOptions & ScopeOptions,
|
// options?: RenderOptions & ScopeOptions,
|
||||||
): A {
|
// ): A {
|
||||||
const runSync = this.useRunSync()
|
// const runSync = this.useRunSync()
|
||||||
|
|
||||||
const [value, scope] = React.useMemo(() => Scope.make(options?.finalizerExecutionStrategy).pipe(
|
// const [value, scope] = React.useMemo(() => Scope.make(options?.finalizerExecutionStrategy).pipe(
|
||||||
Effect.flatMap(scope =>
|
// Effect.flatMap(scope =>
|
||||||
Effect.provideService(effect, Scope.Scope, scope).pipe(
|
// Effect.provideService(effect, Scope.Scope, scope).pipe(
|
||||||
Effect.map(value => [value, scope] as const)
|
// Effect.map(value => [value, scope] as const)
|
||||||
)
|
// )
|
||||||
),
|
// ),
|
||||||
|
|
||||||
runSync,
|
// runSync,
|
||||||
), [
|
// ), [
|
||||||
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
|
// ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
|
||||||
...(deps ?? []),
|
// ...(deps ?? []),
|
||||||
])
|
// ])
|
||||||
|
|
||||||
React.useEffect(() => {
|
// React.useEffect(() => {
|
||||||
// console.log("effect", value, scope)
|
// // console.log("effect", value, scope)
|
||||||
return () => {
|
// return () => {
|
||||||
// console.log("cleanup", value, scope)
|
// // console.log("cleanup", value, scope)
|
||||||
runSync(Scope.close(scope, Exit.void))
|
// runSync(Scope.close(scope, Exit.void))
|
||||||
}
|
// }
|
||||||
}, [scope])
|
// }, [scope])
|
||||||
|
|
||||||
return value
|
// return value
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reffuse equivalent to `React.useMemo`.
|
* Reffuse equivalent to `React.useMemo`.
|
||||||
@@ -120,18 +120,18 @@ export class Reffuse<R> {
|
|||||||
* Changes to the Reffuse runtime or context will recompute the value in addition to the deps.
|
* 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`.
|
* You can disable this behavior by setting `doNotReExecuteOnRuntimeOrContextChange` to `true` in `options`.
|
||||||
*/
|
*/
|
||||||
// useMemo<A, E>(
|
useMemo<A, E>(
|
||||||
// effect: Effect.Effect<A, E, R>,
|
effect: Effect.Effect<A, E, R>,
|
||||||
// deps?: React.DependencyList,
|
deps?: React.DependencyList,
|
||||||
// options?: RenderOptions,
|
options?: RenderOptions,
|
||||||
// ): A {
|
): A {
|
||||||
// const runSync = this.useRunSync()
|
const runSync = this.useRunSync()
|
||||||
|
|
||||||
// return React.useMemo(() => runSync(effect), [
|
return React.useMemo(() => runSync(effect), [
|
||||||
// ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
|
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
|
||||||
// ...(deps ?? []),
|
...(deps ?? []),
|
||||||
// ])
|
])
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reffuse equivalent to `React.useEffect`.
|
* Reffuse equivalent to `React.useEffect`.
|
||||||
|
|||||||
Reference in New Issue
Block a user