0.1.13 #18
@@ -2,8 +2,8 @@ import { R } from "@/reffuse"
|
|||||||
import { Button, Flex, Text } from "@radix-ui/themes"
|
import { Button, Flex, Text } from "@radix-ui/themes"
|
||||||
import { createFileRoute } from "@tanstack/react-router"
|
import { createFileRoute } from "@tanstack/react-router"
|
||||||
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
||||||
import { Console, Effect, Option, Random, Scope, Stream } from "effect"
|
import { Console, Effect, Option, Scope } from "effect"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
|
||||||
const makeUuid = Effect.provide(makeUuid4, GetRandomValues.CryptoRandom)
|
const makeUuid = Effect.provide(makeUuid4, GetRandomValues.CryptoRandom)
|
||||||
@@ -22,8 +22,7 @@ function RouteComponent() {
|
|||||||
), [])
|
), [])
|
||||||
|
|
||||||
const uuidStream = R.useStreamFromReactiveValues([uuid])
|
const uuidStream = R.useStreamFromReactiveValues([uuid])
|
||||||
const stream2 = useMemo(() => Stream.repeatEffect(Random.nextInt), [])
|
const uuidStreamLatestValue = R.useSubscribeStream(uuidStream)
|
||||||
const uuidStreamLatestValue = R.useSubscribeStream(stream2, true)
|
|
||||||
|
|
||||||
const scope = R.useScope([uuid])
|
const scope = R.useScope([uuid])
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type Cause, Chunk, type Context, Effect, ExecutionStrategy, Exit, type Fiber, flow, Function, type Layer, Match, Option, pipe, Pipeable, PubSub, Queue, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
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 * 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"
|
||||||
@@ -501,11 +501,6 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
this: ReffuseNamespace<R>,
|
this: ReffuseNamespace<R>,
|
||||||
stream: Stream.Stream<A, E, R>,
|
stream: Stream.Stream<A, E, R>,
|
||||||
): Option.Option<A>
|
): Option.Option<A>
|
||||||
useSubscribeStream<A, E, R>(
|
|
||||||
this: ReffuseNamespace<R>,
|
|
||||||
stream: Stream.Stream<A, E, R>,
|
|
||||||
pullLatestValue: true,
|
|
||||||
): Option.Some<A>
|
|
||||||
useSubscribeStream<A, E, IE, R>(
|
useSubscribeStream<A, E, IE, R>(
|
||||||
this: ReffuseNamespace<R>,
|
this: ReffuseNamespace<R>,
|
||||||
stream: Stream.Stream<A, E, R>,
|
stream: Stream.Stream<A, E, R>,
|
||||||
@@ -514,25 +509,11 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
useSubscribeStream<A, E, IE, R>(
|
useSubscribeStream<A, E, IE, R>(
|
||||||
this: ReffuseNamespace<R>,
|
this: ReffuseNamespace<R>,
|
||||||
stream: Stream.Stream<A, E, R>,
|
stream: Stream.Stream<A, E, R>,
|
||||||
pullLatestOrInitialValue?: true | (() => Effect.Effect<A, IE, R>),
|
initialValue?: () => Effect.Effect<A, IE, R>,
|
||||||
): Option.Option<A> {
|
): Option.Option<A> {
|
||||||
const [reactStateValue, setReactStateValue] = React.useState(this.useMemo<
|
const [reactStateValue, setReactStateValue] = React.useState(this.useMemo(
|
||||||
Option.Option<A>,
|
() => initialValue
|
||||||
Cause.NoSuchElementException | Cause.Cause<Option.Option<E>> | IE,
|
? Effect.map(initialValue(), Option.some)
|
||||||
R
|
|
||||||
>(
|
|
||||||
() => pullLatestOrInitialValue
|
|
||||||
? Function.isFunction(pullLatestOrInitialValue)
|
|
||||||
? Effect.map(pullLatestOrInitialValue(), Option.some)
|
|
||||||
: Stream.toQueueOfElements(stream).pipe(
|
|
||||||
Effect.flatMap(Queue.takeAll),
|
|
||||||
Effect.flatMap(Chunk.last),
|
|
||||||
Effect.flatMap(Exit.matchEffect({
|
|
||||||
onSuccess: v => Effect.succeed(Option.some(v)),
|
|
||||||
onFailure: Effect.fail,
|
|
||||||
})),
|
|
||||||
Effect.scoped,
|
|
||||||
)
|
|
||||||
: Effect.succeed(Option.none()),
|
: Effect.succeed(Option.none()),
|
||||||
[],
|
[],
|
||||||
{ doNotReExecuteOnRuntimeOrContextChange: true },
|
{ doNotReExecuteOnRuntimeOrContextChange: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user