File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff 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 */
255269export 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}
You can’t perform that action at this time.
0 commit comments