0.1.13 #18
@@ -18,6 +18,20 @@ export function VQueryErrorHandler() {
|
|||||||
), [])
|
), [])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const error2 = R.useSubscribeStream(
|
||||||
|
R.useMemo(() => AppQueryErrorHandler.pipe(
|
||||||
|
Effect.flatMap()
|
||||||
|
|
||||||
|
Effect.map(handler => handler.errors.pipe(
|
||||||
|
Stream.changes,
|
||||||
|
Stream.tap(Console.error),
|
||||||
|
Stream.tap(() => Effect.sync(() => setOpen(true))),
|
||||||
|
))
|
||||||
|
), []),
|
||||||
|
|
||||||
|
() => Effect.fail(new Error()),
|
||||||
|
)
|
||||||
|
|
||||||
if (Option.isNone(error))
|
if (Option.isNone(error))
|
||||||
return <></>
|
return <></>
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
this.SubRef = this.SubRef.bind(this as any) as any
|
this.SubRef = this.SubRef.bind(this as any) as any
|
||||||
this.SubscribeRefs = this.SubscribeRefs.bind(this as any) as any
|
this.SubscribeRefs = this.SubscribeRefs.bind(this as any) as any
|
||||||
this.RefState = this.RefState.bind(this as any) as any
|
this.RefState = this.RefState.bind(this as any) as any
|
||||||
this.SubscribeStream = this.SubscribeStream.bind(this as any) as any
|
// this.SubscribeStream = this.SubscribeStream.bind(this as any) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -483,14 +483,23 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
useSubscribeStream<A, InitialA extends A | undefined, E, InitialE, R>(
|
useSubscribeStream<A, E, R>(
|
||||||
this: ReffuseNamespace<R>,
|
this: ReffuseNamespace<R>,
|
||||||
stream: Stream.Stream<A, E, R>,
|
stream: Stream.Stream<A, E, R>,
|
||||||
initialValue?: () => Effect.Effect<InitialA, InitialE, R>,
|
): Option.Option<A>
|
||||||
): InitialA extends A ? Option.Some<A> : Option.Option<A> {
|
useSubscribeStream<A, E, R>(
|
||||||
const [reactStateValue, setReactStateValue] = React.useState<Option.Option<A>>(this.useMemo(
|
this: ReffuseNamespace<R>,
|
||||||
|
stream: Stream.Stream<A, E, R>,
|
||||||
|
initialValue: () => Effect.Effect<A, E, R>,
|
||||||
|
): Option.Some<A>
|
||||||
|
useSubscribeStream<A, E, R>(
|
||||||
|
this: ReffuseNamespace<R>,
|
||||||
|
stream: Stream.Stream<A, E, R>,
|
||||||
|
initialValue?: () => Effect.Effect<A, E, R>,
|
||||||
|
): Option.Option<A> {
|
||||||
|
const [reactStateValue, setReactStateValue] = React.useState(this.useMemo(
|
||||||
() => initialValue
|
() => initialValue
|
||||||
? Effect.map(initialValue(), v => Option.some(v as A))
|
? Effect.map(initialValue(), Option.some)
|
||||||
: Effect.succeed(Option.none()),
|
: Effect.succeed(Option.none()),
|
||||||
[],
|
[],
|
||||||
{ doNotReExecuteOnRuntimeOrContextChange: true },
|
{ doNotReExecuteOnRuntimeOrContextChange: true },
|
||||||
@@ -501,7 +510,7 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
v => Effect.sync(() => setReactStateValue(Option.some(v))),
|
v => Effect.sync(() => setReactStateValue(Option.some(v))),
|
||||||
), [stream])
|
), [stream])
|
||||||
|
|
||||||
return reactStateValue as InitialA extends A ? Option.Some<A> : Option.Option<A>
|
return reactStateValue
|
||||||
}
|
}
|
||||||
|
|
||||||
usePullStream<A, InitialA extends A | undefined, E, InitialE, R>(
|
usePullStream<A, InitialA extends A | undefined, E, InitialE, R>(
|
||||||
@@ -580,16 +589,16 @@ export abstract class ReffuseNamespace<R> {
|
|||||||
return props.children(this.useRefState(props.ref))
|
return props.children(this.useRefState(props.ref))
|
||||||
}
|
}
|
||||||
|
|
||||||
SubscribeStream<A, InitialA extends A | undefined, E, InitialE, R>(
|
// SubscribeStream<A, E, R, InitialA extends A = never, InitialE = never>(
|
||||||
this: ReffuseNamespace<R>,
|
// this: ReffuseNamespace<R>,
|
||||||
props: {
|
// props: {
|
||||||
readonly stream: Stream.Stream<A, E, R>
|
// readonly stream: Stream.Stream<A, E, R>
|
||||||
readonly initialValue?: () => Effect.Effect<InitialA, InitialE, R>
|
// readonly initialValue?: () => Effect.Effect<InitialA, InitialE, R>
|
||||||
readonly children: (latestValue: InitialA extends A ? Option.Some<A> : Option.Option<A>) => React.ReactNode
|
// readonly children: (latestValue: InitialA extends A ? Option.Some<A> : Option.Option<A>) => React.ReactNode
|
||||||
},
|
// },
|
||||||
): React.ReactNode {
|
// ): React.ReactNode {
|
||||||
return props.children(this.useSubscribeStream(props.stream, props.initialValue))
|
// return props.children(this.useSubscribeStream(props.stream, props.initialValue))
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user