Skip to content

Commit 6f65cfa

Browse files
committed
feat: enhance recover$ function to convert all properties to Stream
1 parent a5f4f70 commit 6f65cfa

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

packages/core/useFluth/index.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,27 @@ export function effect$(render: RenderFunction): () => VNodeChild {
249249

250250
/**
251251
* batch convert object properties to streams
252+
* for recover stream or observable type which deconstructed in vue reactive
253+
* observable properties will also be converted to Stream
254+
* but once used some stream methods, it will be throw error
255+
* from a practical point of view, we can just convert all properties to Stream
256+
*
257+
* example:
258+
* const obj = reactive({
259+
* a$: $("a"),
260+
* b$: $("b"),
261+
* })
262+
* const { a$, b$ } = recover$(toRaw(obj))
263+
* a$.next("c") // obj.a$ will be updated to "c"
264+
* b$.next("d") // obj.b$ will be updated to "d"
265+
*
252266
* @param obj object with stream-like properties
253267
* @returns object with converted streams
254268
*/
255269
export function recover$<T extends Record<string, any>>(
256270
obj: T,
257271
): {
258-
[K in keyof T]: T[K] extends {
259-
value: unknown;
260-
then: unknown;
261-
thenOnce: unknown;
262-
thenImmediate: unknown;
263-
}
264-
? T[K] extends { next: unknown; set: unknown }
265-
? Stream<T[K]["value"]>
266-
: Observable<T[K]["value"] | undefined>
267-
: T[K];
272+
[K in keyof T]: Stream<T[K]>;
268273
} {
269274
return obj as any;
270275
}

0 commit comments

Comments
 (0)