-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Prepare for RxJS v7 #79751
Comments
RxJS v7 was released two weeks ago: https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md |
List of breaking changes: https://rxjs.dev/deprecations/breaking-changes |
Do actually want to implement those methods in Although, the return type of |
Another notable change is anonymous function subscription is deprecated. observable.subscribe(next, error, complete); Instead only the first parameter of observable.subscribe(next, options);
observable.subscribe({next, error, complete}, options); |
RxJS v7 is deprecating the
.toPromise()
method of observable objects, and fixing the type definition to returnPromise<T | undefined>
as there is no way for the type system to know if the observable will always produce at least one notification so the resolve value may be undefined in all places where.toPromise()
is used (though it's made impossible by using certain operators).This method is replaced with two helpers:
firstValueFrom(x$: Observable<T>): Promise<T>
: equivalent ofx$.pipe(first()).toPromise()
, resolves with the first value, unsubscribes after the first notification, rejects ifo$
completes without any notifications.lastValueFrom(x$: Observable<T>): Promise<T>
: equivalent ofx$.pipe(last()).toPromise()
, resolves after the observable completes with the last notification value, rejects ifo$
completes without any notifications.We should implement these methods in
@kbn/std
and start migrating parts of the code base to these helpers. Once RxJS v7 is released we can replace our helpers with the standard ones.If we can get most or all of the codebase migrated to use the new helpers before RxJS v7 is released then we can use an eslint rule to prevent new usage of
toPromise()
, or just fixup the remaining issues when the final upgrade happens.The text was updated successfully, but these errors were encountered: