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

This commit is contained in:
Julien Valverdé
2025-05-11 08:11:03 +02:00
parent 9ccabbb627
commit 6f65574ebd
3 changed files with 18 additions and 53 deletions

View File

@@ -1,4 +1,4 @@
import { Chunk, type Context, Effect, ExecutionStrategy, Exit, type Fiber, flow, type Layer, Match, Option, pipe, Pipeable, PubSub, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
import { type Context, Effect, ExecutionStrategy, Exit, type Fiber, type Layer, Match, Option, pipe, Pipeable, PubSub, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
import * as React from "react"
import * as ReffuseContext from "./ReffuseContext.js"
import * as ReffuseRuntime from "./ReffuseRuntime.js"
@@ -527,50 +527,6 @@ export abstract class ReffuseNamespace<R> {
return reactStateValue
}
usePullStream<A, E, IE, R>(
this: ReffuseNamespace<R>,
stream: Stream.Stream<A, E, R>,
): [latestValue: Option.Option<A>, pull: Effect.Effect<Chunk.Chunk<A>, Option.Option<E>>]
usePullStream<A, E, IE, R>(
this: ReffuseNamespace<R>,
stream: Stream.Stream<A, E, R>,
initialValue: () => Effect.Effect<A, IE, R>,
): [latestValue: Option.Some<A>, pull: Effect.Effect<Chunk.Chunk<A>, Option.Option<E>>]
usePullStream<A, E, IE, R>(
this: ReffuseNamespace<R>,
stream: Stream.Stream<A, E, R>,
initialValue?: () => Effect.Effect<A, IE, R>,
): [latestValue: Option.Option<A>, pull: Effect.Effect<Chunk.Chunk<A>, Option.Option<E>>] {
const scope = this.useScope([stream])
const [reactStateValue, setReactStateValue] = React.useState(this.useMemo(
() => initialValue
? Effect.map(initialValue(), Option.some)
: Effect.succeed(Option.none()),
[],
{ doNotReExecuteOnRuntimeOrContextChange: true },
))
const pull = this.useMemo(() => Effect.context<R>().pipe(
Effect.flatMap(context => Stream.toPull(Stream.changesWith(stream, (x, y) => x === y)).pipe(
Effect.map(effect => effect.pipe(
Effect.tap(flow(
Chunk.last,
v => Option.match(v, {
onSome: () => Effect.sync(() => setReactStateValue(v)),
onNone: () => Effect.void,
}),
)),
Effect.provide(context),
)),
Effect.provideService(Scope.Scope, scope),
))
), [stream, scope])
return [reactStateValue, pull]
}
SubRef<B, const P extends PropertyPath.Paths<B>, R>(
this: ReffuseNamespace<R>,