fix: subscription streams

This commit is contained in:
liyasthomas
2021-12-12 06:19:58 +05:30
parent 67002a204e
commit 534fe8030f
4 changed files with 78 additions and 52 deletions

View File

@@ -100,11 +100,20 @@ export function pluckMultipleFromRef<T, K extends Array<keyof T>>(
return Object.fromEntries(keys.map((x) => [x, pluckRef(sourceRef, x)])) as any
}
export type StreamSubscriberFunc = <T>(
stream: Observable<T>,
next?: ((value: T) => void) | undefined,
error?: ((e: any) => void) | undefined,
complete?: (() => void) | undefined
) => void
/**
* A composable that provides the ability to run streams
* and subscribe to them and respect the component lifecycle.
*/
export function useStreamSubscriber() {
export function useStreamSubscriber(): {
subscribeToStream: StreamSubscriberFunc
} {
const subs: Subscription[] = []
const runAndSubscribe = <T>(