-
-
Notifications
You must be signed in to change notification settings - Fork 551
/
Copy pathbase.ts
44 lines (42 loc) · 1.14 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { HostId } from "../../ids";
import { Observable } from "rxjs";
/**
* A set of common attributes for both local and remote Jupyter
* targets.
*/
export interface BaseHostProps {
id?: HostId | null;
defaultKernelName: string;
bookstoreEnabled?: boolean;
showHeaderEditor?: boolean;
}
/**
* An RxJS operator for determining if the host that is currently
* set as the current host in the state is of a particular type.
*
* @param hostType The host type to filter by
*/
export const ofHostType = (...hostTypes: Array<string | [string]>) => (
source: Observable<any>
) => {
// Switch to the splat mode
if (hostTypes.length === 1 && Array.isArray(hostTypes[0])) {
return ofHostType(...(hostTypes[0] as [string]));
}
return new Observable((observer: any) =>
source.subscribe({
next(state) {
const host = state.core.app.host;
if (host && hostTypes.indexOf(host.type) !== -1) {
return observer.next(state);
}
},
error(err) {
observer.error(err);
},
complete() {
observer.complete();
}
})
);
};