Merge pull request #5691 from backstage/rugvip/observable

core-api: updated Observable type to support interop
This commit is contained in:
Patrik Oldsberg
2021-05-17 14:14:53 +02:00
committed by GitHub
5 changed files with 34 additions and 2 deletions
+13
View File
@@ -0,0 +1,13 @@
---
'@backstage/core-api': patch
---
Updated the `Observable` type to provide interoperability with `Symbol.observable`, making it compatible with at least `zen-observable` and `RxJS 7`.
In cases where this change breaks tests that mocked the `Observable` type, the following addition to the mock should fix the breakage:
```ts
[Symbol.observable]() {
return this;
},
```
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/test-utils': patch
---
Updated `MockErrorApi` to work with new `Observable` type in `@backstage/core`.
+8
View File
@@ -53,6 +53,10 @@ export class PublishSubject<T>
ZenObservable.SubscriptionObserver<T>
>();
[Symbol.observable]() {
return this;
}
get closed() {
return this.isClosed;
}
@@ -148,6 +152,10 @@ export class BehaviorSubject<T>
ZenObservable.SubscriptionObserver<T>
>();
[Symbol.observable]() {
return this;
}
get closed() {
return this.isClosed;
}
+4 -2
View File
@@ -39,7 +39,7 @@ export type Subscription = {
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
readonly closed: boolean;
};
/**
@@ -51,12 +51,14 @@ export type Subscription = {
* using many different observable implementations, such as zen-observable or RxJS 5.
*/
export type Observable<T> = {
[Symbol.observable](): Observable<T>;
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: Observer<T>): Subscription;
subscribe(
onNext: (value: T) => void,
onNext?: (value: T) => void,
onError?: (error: Error) => void,
onComplete?: () => void,
): Subscription;
@@ -32,6 +32,10 @@ type Waiter = {
const nullObservable = {
subscribe: () => ({ unsubscribe: () => {}, closed: true }),
[Symbol.observable]() {
return this;
},
};
export class MockErrorApi implements ErrorApi {