-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
kernelspecs.ts
59 lines (55 loc) · 1.99 KB
/
kernelspecs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { ofType } from "redux-observable";
import { ActionsObservable } from "redux-observable";
import { kernelspecs } from "rx-jupyter";
import { empty, of } from "rxjs";
import { catchError, map, mergeMap } from "rxjs/operators";
import * as actions from "@nteract/actions";
import * as selectors from "@nteract/selectors";
import { KernelspecProps, ServerConfig } from "@nteract/types";
export const fetchKernelspecsEpic = (
action$: ActionsObservable<actions.FetchKernelspecs>,
state$: any
) =>
action$.pipe(
ofType(actions.FETCH_KERNELSPECS),
mergeMap((action: actions.FetchKernelspecs) => {
const {
payload: { hostRef, kernelspecsRef }
} = action;
const state = state$.value;
const host = selectors.currentHost(state);
if (host.type !== "jupyter") {
// Dismiss any usage that isn't targeting a jupyter server
return empty();
}
const serverConfig: ServerConfig = selectors.serverConfig(host);
return kernelspecs.list(serverConfig).pipe(
map(data => {
const defaultKernelName = data.response.default;
const kernelspecs: { [key: string]: KernelspecProps } = {};
Object.keys(data.response.kernelspecs).forEach(key => {
const value = data.response.kernelspecs[key];
kernelspecs[key] = {
name: value.name,
resources: value.resources,
argv: value.spec.argv,
displayName: value.spec.display_name,
env: value.spec.env,
interruptMode: value.spec.interrupt_mode,
language: value.spec.language,
metadata: value.spec.metadata
};
});
return actions.fetchKernelspecsFulfilled({
hostRef,
kernelspecsRef,
defaultKernelName,
kernelspecs
});
}),
catchError(error => {
return of(actions.fetchKernelspecsFailed({ kernelspecsRef, error }));
})
);
})
);