useMemoSync
All checks were successful
Lint / lint (push) Successful in 10s

This commit is contained in:
Julien Valverdé
2025-01-19 01:32:26 +01:00
parent d070ebb903
commit 7ada793943

View File

@@ -98,16 +98,7 @@ export class Reffuse<R> {
return value return value
} }
/** useMemoSync<A, E>(
* 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`.
*/
useMemoUnscoped<A, E>(
effect: Effect.Effect<A, E, R>, effect: Effect.Effect<A, E, R>,
deps?: React.DependencyList, deps?: React.DependencyList,
options?: RenderOptions, options?: RenderOptions,
@@ -280,15 +271,15 @@ export class Reffuse<R> {
useRef<A>(value: A): SubscriptionRef.SubscriptionRef<A> { useRef<A>(value: A): SubscriptionRef.SubscriptionRef<A> {
return this.useMemoUnscoped( return this.useMemoSync(
SubscriptionRef.make(value), SubscriptionRef.make(value),
[], [],
{ doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes { doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes
) )
} }
useRefFromEffect<A, E>(effect: Effect.Effect<A, E, R | Scope.Scope>): SubscriptionRef.SubscriptionRef<A> { useRefFromEffect<A, E>(effect: Effect.Effect<A, E, R>): SubscriptionRef.SubscriptionRef<A> {
return this.useMemo( return this.useMemoSync(
effect.pipe(Effect.flatMap(SubscriptionRef.make)), effect.pipe(Effect.flatMap(SubscriptionRef.make)),
[], [],
{ doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes { doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes