⬅️ Back to Table of Contents
📄 index.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
2 |
📦 Imports |
10 |
📊 Variables & Constants |
1 |
🟢 Vue Composition API |
2 |
📚 Table of Contents
🛠️ File Location:
📂 packages/rxjs/from/index.ts
📦 Imports
Name |
Source |
ObservableInput |
rxjs |
Subscription |
rxjs |
MaybeRef |
vue |
Ref |
vue |
WatchOptions |
vue |
fromEventRx |
rxjs |
fromRxjs |
rxjs |
Observable |
rxjs |
isRef |
vue |
watch |
vue |
Variables & Constants
Name |
Type |
Kind |
Value |
Exported |
innerSub |
Subscription | undefined |
let/var |
*not shown* |
✗ |
Vue Composition API
Name |
Type |
Reactive Variables |
Composables |
watch |
watch |
none |
none |
watch |
watch |
none |
none |
Functions
Code
export function from<T>(value: ObservableInput<T> | Ref<T>, watchOptions?: WatchOptions): Observable<T> {
if (isRef<T>(value))
return new Observable(subscriber => watch(value, val => subscriber.next(val), watchOptions))
return fromRxjs(value)
}
- Parameters:
value: ObservableInput<T> | Ref<T>
watchOptions: WatchOptions
- Return Type:
Observable<T>
- Calls:
isRef (from vue)
watch (from vue)
subscriber.next
fromRxjs (from rxjs)
fromEvent(value: MaybeRef<T>, event: string): Observable<Event>
Code
export function fromEvent<T extends HTMLElement | null>(value: MaybeRef<T>, event: string): Observable<Event> {
if (isRef<T>(value)) {
return new Observable((subscriber) => {
let innerSub: Subscription | undefined
return watch(value, (element) => {
innerSub?.unsubscribe()
if (element instanceof HTMLElement) {
innerSub = fromEventRx(element, event).subscribe(subscriber)
subscriber.add(innerSub)
}
}, { immediate: true })
})
}
if (value === null) {
throw new Error('The value is `null`, and it should be an HTMLElement.')
}
return fromEventRx(value, event)
}
- Parameters:
value: MaybeRef<T>
event: string
- Return Type:
Observable<Event>
- Calls:
isRef (from vue)
watch (from vue)
innerSub?.unsubscribe
fromEventRx(element, event).subscribe
subscriber.add
fromEventRx (from rxjs)