core-app-api: import Observable from plugin api + fix definition there

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-05-31 16:10:02 +02:00
parent 145f209335
commit aa38b2447d
15 changed files with 24 additions and 93 deletions
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AlertApi, AlertMessage } from '@backstage/core-plugin-api';
import { AlertApi, AlertMessage, Observable } from '@backstage/core-plugin-api';
import { PublishSubject } from '../../../lib/subjects';
import { Observable } from '../../../types';
/**
* Base implementation for the AlertApi that simply forwards alerts to consumers.
@@ -14,9 +14,8 @@
* limitations under the License.
*/
import { AppThemeApi, AppTheme } from '@backstage/core-plugin-api';
import { AppThemeApi, AppTheme, Observable } from '@backstage/core-plugin-api';
import { BehaviorSubject } from '../../../lib/subjects';
import { Observable } from '../../../types';
const STORAGE_KEY = 'theme';
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ErrorApi, ErrorContext } from '@backstage/core-plugin-api';
import { ErrorApi, ErrorContext, Observable } from '@backstage/core-plugin-api';
import { PublishSubject } from '../../../lib/subjects';
import { Observable } from '../../../types';
/**
* Base implementation for the ErrorApi that simply forwards errors to consumers.
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Observable } from '@backstage/core-plugin-api';
import { BehaviorSubject } from '../../../lib/subjects';
import { Observable } from '../../../types';
type RequestQueueEntry<ResultType> = {
scopes: Set<string>;
@@ -19,10 +19,10 @@ import {
PendingAuthRequest,
AuthRequester,
AuthRequesterOptions,
Observable,
} from '@backstage/core-plugin-api';
import { OAuthPendingRequests, PendingRequest } from './OAuthPendingRequests';
import { BehaviorSubject } from '../../../lib/subjects';
import { Observable } from '../../../types';
/**
* The OAuthRequestManager is an implementation of the OAuthRequestApi.
@@ -17,8 +17,8 @@ import {
StorageApi,
StorageValueChange,
ErrorApi,
Observable,
} from '@backstage/core-plugin-api';
import { Observable } from '../../../types';
import ObservableImpl from 'zen-observable';
const buckets = new Map<string, WebStorage>();
@@ -24,13 +24,13 @@ import {
ProfileInfo,
BackstageIdentity,
AuthRequestOptions,
Observable,
} from '@backstage/core-plugin-api';
import { SessionManager } from '../../../../lib/AuthSessionManager/types';
import {
AuthSessionStore,
StaticAuthSessionManager,
} from '../../../../lib/AuthSessionManager';
import { Observable } from '../../../../types';
import { OAuthApiCreateOptions } from '../types';
export type GithubAuthResponse = {
@@ -18,7 +18,6 @@ import OAuth2Icon from '@material-ui/icons/AcUnit';
import { DefaultAuthConnector } from '../../../../lib/AuthConnector';
import { RefreshingAuthSessionManager } from '../../../../lib/AuthSessionManager';
import { SessionManager } from '../../../../lib/AuthSessionManager/types';
import { Observable } from '../../../../types';
import {
AuthRequestOptions,
BackstageIdentity,
@@ -29,6 +28,7 @@ import {
SessionState,
SessionApi,
BackstageIdentityApi,
Observable,
} from '@backstage/core-plugin-api';
import { OAuth2Session } from './types';
import { OAuthApiCreateOptions } from '../types';
@@ -17,7 +17,6 @@
import SamlIcon from '@material-ui/icons/AcUnit';
import { DirectAuthConnector } from '../../../../lib/AuthConnector';
import { SessionManager } from '../../../../lib/AuthSessionManager/types';
import { Observable } from '../../../../types';
import {
ProfileInfo,
BackstageIdentity,
@@ -26,6 +25,7 @@ import {
ProfileInfoApi,
BackstageIdentityApi,
SessionApi,
Observable,
} from '@backstage/core-plugin-api';
import { SamlSession } from './types';
import {
-1
View File
@@ -17,4 +17,3 @@
export * from './apis';
export * from './app';
export * from './routing';
export * from './types';
@@ -15,8 +15,7 @@
*/
import { BehaviorSubject } from '../subjects';
import { SessionState } from '@backstage/core-plugin-api';
import { Observable } from '../../types';
import { Observable, SessionState } from '@backstage/core-plugin-api';
export class SessionStateTracker {
private readonly subject = new BehaviorSubject<SessionState>(
@@ -14,8 +14,7 @@
* limitations under the License.
*/
import { Observable } from '../../types';
import { SessionState } from '@backstage/core-plugin-api';
import { Observable, SessionState } from '@backstage/core-plugin-api';
export type GetSessionOptions = {
optional?: boolean;
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Observable } from '../types';
import { Observable } from '@backstage/core-plugin-api';
import ObservableImpl from 'zen-observable';
// TODO(Rugvip): These are stopgap and probably incomplete implementations of subjects.
-73
View File
@@ -1,73 +0,0 @@
/*
* 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 throughout 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;
};
// Declares the global well-known Symbol.observable
// We get the actual runtime polyfill from zen-observable
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
/**
* 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> = {
[Symbol.observable](): 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;
};
+12 -2
View File
@@ -39,9 +39,17 @@ export type Subscription = {
/**
* Value indicating whether the subscription is closed.
*/
readonly closed: Boolean;
readonly closed: boolean;
};
// Declares the global well-known Symbol.observable
// We get the actual runtime polyfill from zen-observable
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
/**
* Observable sequence of values and errors, see TC39.
*
@@ -51,12 +59,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;