-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
kernelspecs.ts
65 lines (59 loc) · 1.62 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
60
61
62
63
64
65
import {
AppState,
KernelspecsByRefRecord,
KernelspecRecord
} from "@nteract/types";
/**
* Returns a ref to the kernelspec of the kernel the nteract application
* is currently connected to.
*
* @param state The state of the nteract application
*
* @returns A ref to the kernelspec
*/
export const currentKernelspecsRef = (state: AppState) =>
state.core.currentKernelspecsRef;
/**
* Returns a Map of the kernelspecs associated with each kernelspec ref.
*
* @param state The state of the nteract application
*
* @returns An association between a kernelspec ref and the kernelspec
*/
export const kernelspecsByRef = (state: AppState) =>
state.core.entities.kernelspecs.byRef;
/**
* Returns the kernelspec of the kernel that the nteract application is
* currently connected to.
*/
export const currentKernelspecs: (
state: AppState
) => KernelspecsByRefRecord | null = (state: AppState) => {
const ref = state.core.currentKernelspecsRef;
if (ref) {
const kernelspecs = state.core.entities.kernelspecs.byRef.get(ref);
if (kernelspecs) {
return kernelspecs;
}
}
// If we don't have a current kernelspecs ref, return null
return null;
};
export const kernelspecByName: (
state: AppState,
{ name }: { name: string }
) => KernelspecRecord | null | undefined = (
state: AppState,
{ name }: { name: string }
) => {
const kernelspecs = currentKernelspecs(state);
if (kernelspecs && kernelspecs.byName) {
return kernelspecs.byName.get(
name,
kernelspecs.byName.find(
(value: KernelspecRecord) => value.language === name
)
);
}
return null;
};