packages/core: add common Observable type based on TC39

This commit is contained in:
Patrik Oldsberg
2020-05-14 00:12:23 +02:00
parent 579ba54480
commit 150908ae55
2 changed files with 64 additions and 0 deletions
+1
View File
@@ -18,3 +18,4 @@ export * from './apis';
export * from './app';
export * from './navTargets';
export * from './plugin';
export * from './types';
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This file contains non-react related core types used throught Backstage.
*/
/**
* Observer interface for consuming an Observer, see TC39.
*/
export type Observer<T> = {
next?(value: T): void;
error?(error: Error): void;
complete?(): void;
};
/**
* Subscription returned when subscribing to an Observable, see TC39.
*/
export type Subscription = {
/**
* CAncels the subscription
*/
unsubscribe(): void;
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
};
/**
* Observable sequence of values and errors, see TC39.
*
* https://github.com/tc39/proposal-observable
*
* This is used as a common return type for observable values and can be created
* using many different observable implementations, such as zen-observable or RxJS 5.
*/
export type Observable<T> = {
/**
* Subscribes to this observable to start receiving new values.
*/
subscribe(observer: Observer<T>): Subscription;
subscribe(
onNext: (value: T) => void,
onError?: (error: Error) => void,
onComplete?: () => void,
): Subscription;
};