Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
allocate = () => {
// Set up a closure around the current props, for determining if we should really update state
const { kernelName, host, cwd } = this.props;
const { endpoint, token } = this.props.host;
kernels.start(host, kernelName, cwd).subscribe(
xhr => {
this.setState(
(
_prevState: KernelAllocatorState,
currentProps: KernelAllocatorProps
) => {
// Ensure that the props haven't changed on us midway -- if they have,
// we shouldn't try to connect to our (now) old kernel
if (
currentProps.kernelName !== kernelName ||
currentProps.cwd !== cwd ||
currentProps.host.endpoint !== endpoint ||
currentProps.host.token !== token
) {
console.log(
"Props changed while in the middle of starting a kernel, assuming that another kernel is starting up"
allocate = () => {
// Set up a closure around the current props, for determining if we should really update state
const { kernelName, host, cwd } = this.props;
const { endpoint, token } = this.props.host;
kernels.start(host, kernelName, cwd).subscribe(
xhr => {
this.setState(
(
_prevState: KernelAllocatorState,
currentProps: KernelAllocatorProps
) => {
// Ensure that the props haven't changed on us midway -- if they have,
// we shouldn't try to connect to our (now) old kernel
if (
currentProps.kernelName !== kernelName ||
currentProps.cwd !== cwd ||
currentProps.host.endpoint !== endpoint ||
currentProps.host.token !== token
) {
console.log(
"Props changed while in the middle of starting a kernel, assuming that another kernel is starting up"
if (!sessionId) {
return empty();
}
const content = selectors.content(state, { contentRef });
if (!content || content.type !== "notebook") {
return empty();
}
const {
filepath,
model: { notebook }
} = content;
const { cwd } = extractNewKernel(filepath, notebook);
const kernelRef = createKernelRef();
return kernels.start(serverConfig, kernelSpecName, cwd).pipe(
mergeMap(({ response }) => {
const { id: kernelId } = response;
const sessionPayload = {
kernel: { id: kernelId, name: kernelSpecName }
};
// The sessions API will close down the old kernel for us if it is
// on this session
return sessions.update(serverConfig, sessionId, sessionPayload).pipe(
mergeMap(({ response: session }) => {
const kernel: RemoteKernelProps = Object.assign(
{},
session.kernel,
{
type: "websocket",
sessionId,
cwd,
if (!sessionId) {
return empty();
}
const content = selectors.content(state, { contentRef });
if (!content || content.type !== "notebook") {
return empty();
}
const {
filepath,
model: { notebook }
} = content;
const { cwd } = extractNewKernel(filepath, notebook);
const kernelRef = createKernelRef();
return kernels.start(serverConfig, kernelSpecName, cwd).pipe(
mergeMap(({ response }) => {
const { id: kernelId } = response;
const sessionPayload = {
kernel: { id: kernelId, name: kernelSpecName }
};
// The sessions API will close down the old kernel for us if it is
// on this session
return sessions.update(serverConfig, sessionId, sessionPayload).pipe(
mergeMap(({ response: session }) => {
const kernel: RemoteKernelProps = Object.assign(
{},
session.kernel,
{
type: "websocket",
sessionId,
cwd,
mergeMap(({ payload: { serverId, kernelName } }) => {
const configPath = [
"entities",
"serversById",
serverId,
"server",
"config"
];
const config = objectPath.get(state$.value, configPath);
return kernels.start(config, kernelName, "").pipe(
mergeMap(data => {
const session = uuid();
const kernel = Object.assign({}, data.response, {
channel: kernels.connect(
config,
data.response.id,
session
)
});
kernel.channel.next(kernelInfoRequest());
return merge(
of(
actions.activateKernelFulfilled({
serverId,