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): complete the stream after the first value on one time events #7439

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/rxjs/src/internal/observable/fromEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ export function fromEvent<T>(
}

return new Observable<T>((subscriber) => {
const handler = (...args: any[]) => subscriber.next(1 < args.length ? args : args[0]);
const handler = (...args: any[]) => {
subscriber.next(1 < args.length ? args : args[0]);
if(!isFunction(options) && options?.once){
subscriber.complete();
}
};
if (isValidTarget) {
// Valid event targets, even if they have a `length` property
// will be subscribed to as a single item.
Expand Down
Loading