-
-
Notifications
You must be signed in to change notification settings - Fork 552
/
Copy pathkernels.ts
76 lines (69 loc) · 2.04 KB
/
kernels.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
66
67
68
69
70
71
72
73
74
75
76
import { AppState, KernelRef } from "@nteract/types";
import { createSelector } from "reselect";
/**
* Returns a map of the available kernels keyed by the
* kernel ref.
*
* @param state The state of the nteract application
*
* @returns The kernels by ref
*/
export const kernelsByRef = (state: AppState) =>
state.core.entities.kernels.byRef;
/**
* Returns the kernel associated with a given KernelRef.
*
* @param state The state of the nteract application
* @param { kernelRef: KernelRef} An object containing the KernelRef
*
* @returns The kernel for the KernelRef
*/
export const kernel = (
state: AppState,
{ kernelRef }: { kernelRef?: KernelRef }
) => {
return kernelRef ? kernelsByRef(state).get(kernelRef, null) : null;
};
/**
* Returns the KernelRef for the kernel the nteract application is currently
* connected to.
*
* @param state The state of the nteract application
*
* @returns The KernelRef for the kernel
*/
export const currentKernelRef = (state: AppState) => state.core.kernelRef;
/**
* Returns the kernelspec of the kernel that we are currently connected to.
* Returns null if there is no kernel.
*/
export const currentKernel = createSelector(
[currentKernelRef, kernelsByRef],
(kernelRef, byRef) => (kernelRef ? byRef.get(kernelRef) : null)
);
/**
* Returns the type of the kernel the nteract application is currently
* connected to. Returns `null` if there is no kernel.
*/
export const currentKernelType = createSelector(
currentKernel,
kernel => {
if (kernel && kernel.type) {
return kernel.type;
}
return null;
}
);
/**
* Returns the state of the kernel the nteract application is currently
* connected to. Returns "not connected" if there is no kernel.
*/
export const currentKernelStatus = createSelector(
[currentKernel],
kernel => {
if (kernel && kernel.status) {
return kernel.status;
}
return "not connected";
}
);