Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fromEvent): support HTMLElement #2048

Merged
merged 3 commits into from Oct 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/rxjs/from/index.ts
Expand Up @@ -19,9 +19,12 @@ export function from<T>(value: ObservableInput<T> | Ref<T>, watchOptions?: Watch
}
}

export function fromEvent<T extends HTMLElement>(value: Ref<T>, event: string): Observable<Event> {
return from(value, { immediate: true }).pipe(
filter(value => value instanceof HTMLElement),
mergeMap(value => fromEventRx(value, event)),
)
export function fromEvent<T extends HTMLElement>(value: Ref<T> | T, event: string): Observable<Event> {
rorry121 marked this conversation as resolved.
Show resolved Hide resolved
if (isRef<T>(value)) {
return from(value, { immediate: true }).pipe(
filter(value => value instanceof HTMLElement),
mergeMap(value => fromEventRx(value, event)),
)
}
return fromEventRx(value, event);
antfu marked this conversation as resolved.
Show resolved Hide resolved
}