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

Prepare for RxJS v7 #79751

Closed
spalger opened this issue Oct 6, 2020 · 4 comments · Fixed by #129087
Closed

Prepare for RxJS v7 #79751

spalger opened this issue Oct 6, 2020 · 4 comments · Fixed by #129087
Labels

Comments

@spalger
Copy link
Contributor

spalger commented Oct 6, 2020

RxJS v7 is deprecating the .toPromise() method of observable objects, and fixing the type definition to return Promise<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 of x$.pipe(first()).toPromise(), resolves with the first value, unsubscribes after the first notification, rejects if o$ completes without any notifications.

lastValueFrom(x$: Observable<T>): Promise<T>: equivalent of x$.pipe(last()).toPromise(), resolves after the observable completes with the last notification value, rejects if o$ 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.

@streamich
Copy link
Contributor

RxJS v7 was released two weeks ago: https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md

@streamich
Copy link
Contributor

List of breaking changes: https://rxjs.dev/deprecations/breaking-changes

@streamich
Copy link
Contributor

streamich commented May 11, 2021

We should implement these methods in @kbn/std and start migrating parts of the code base to these helpers.

Do actually want to implement those methods in @kbn/std? We could get those from v7 a the .toPromise() method in v7 works, we just need to stop using .toPromise() by v8 upgrade.

Although, the return type of .toPromise() will break TypeScript checks.

@streamich
Copy link
Contributor

streamich commented May 11, 2021

Another notable change is anonymous function subscription is deprecated.

observable.subscribe(next, error, complete);

Instead only the first parameter of .subscribe() method will be used for subscription, either for next method or for Subscriber.

observable.subscribe(next, options);
observable.subscribe({next, error, complete}, options);

@afharo afharo mentioned this issue Apr 1, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants