@reffuse/extension-query 0.1.5 #16
@@ -1,4 +1,4 @@
|
|||||||
import { type Context, Effect, ExecutionStrategy, Exit, type Fiber, type Layer, Match, Option, pipe, Pipeable, Queue, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
import { Chunk, type Context, Effect, ExecutionStrategy, Exit, type Fiber, flow, type Layer, Match, Option, pipe, Pipeable, Queue, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as ReffuseContext from "./ReffuseContext.js"
|
import * as ReffuseContext from "./ReffuseContext.js"
|
||||||
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
||||||
@@ -495,19 +495,34 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
return reactStateValue as InitialA extends A ? Option.Some<A> : Option.Option<A>
|
return reactStateValue as InitialA extends A ? Option.Some<A> : Option.Option<A>
|
||||||
}
|
}
|
||||||
|
|
||||||
// usePullStream<A, InitialA extends A | undefined, E, R>(
|
usePullStream<A, InitialA extends A | undefined, E, R extends ContextR, ContextR>(
|
||||||
// this: ReffuseNamespace<R>,
|
this: ReffuseNamespace<ContextR>,
|
||||||
// stream: Stream.Stream<A, E, R>,
|
stream: Stream.Stream<A, E, R>,
|
||||||
// initialValue?: InitialA,
|
initialValue?: InitialA,
|
||||||
// ): [
|
): [
|
||||||
// latestValue: InitialA extends A ? Option.Some<A> : Option.Option<A>,
|
latestValue: InitialA extends A ? Option.Some<A> : Option.Option<A>,
|
||||||
// pull: () => void,
|
pull: Effect.Effect<Chunk.Chunk<A>, Option.Option<E>, R>,
|
||||||
// ] {
|
] {
|
||||||
// const [reactStateValue, setReactStateValue] = React.useState<Option.Option<A>>(Option.fromNullable(initialValue))
|
const scope = this.useScope([stream])
|
||||||
// const pull = this.useMemo(() => Stream.toPull(stream), [stream])
|
|
||||||
|
|
||||||
// return reactStateValue as InitialA extends A ? Option.Some<A> : Option.Option<A>
|
const [reactStateValue, setReactStateValue] = React.useState<Option.Option<A>>(Option.fromNullable(initialValue))
|
||||||
// }
|
const pull = this.useMemo(() => Stream.toPull(stream).pipe(
|
||||||
|
Effect.map(Effect.tap(flow(
|
||||||
|
Chunk.last,
|
||||||
|
v => Option.match(v, {
|
||||||
|
onSome: () => Effect.sync(() => setReactStateValue(v)),
|
||||||
|
onNone: () => Effect.void,
|
||||||
|
}),
|
||||||
|
))),
|
||||||
|
|
||||||
|
Effect.provideService(Scope.Scope, scope),
|
||||||
|
), [stream, scope])
|
||||||
|
|
||||||
|
return [
|
||||||
|
reactStateValue as InitialA extends A ? Option.Some<A> : Option.Option<A>,
|
||||||
|
pull,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SubRef<B, const P extends PropertyPath.Paths<B>, R>(
|
SubRef<B, const P extends PropertyPath.Paths<B>, R>(
|
||||||
|
|||||||
Reference in New Issue
Block a user