Browse Source

Make sure kernelChanged always emits args.

Afshin Darian 6 years ago
parent
commit
5a70dc2e43
2 changed files with 30 additions and 32 deletions
  1. 25 25
      packages/apputils/src/clientsession.tsx
  2. 5 7
      packages/notebook/src/panel.ts

+ 25 - 25
packages/apputils/src/clientsession.tsx

@@ -403,7 +403,7 @@ export class ClientSession implements IClientSession {
   shutdown(): Promise<void> {
     const session = this._session;
     if (this.isDisposed || !session) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
     this._session = null;
     return session.shutdown();
@@ -422,7 +422,7 @@ export class ClientSession implements IClientSession {
   restart(): Promise<boolean> {
     return this.initialize().then(() => {
       if (this.isDisposed) {
-        return Promise.reject(void 0);
+        return Promise.reject();
       }
       let kernel = this.kernel;
       if (!kernel) {
@@ -451,14 +451,14 @@ export class ClientSession implements IClientSession {
    */
   setPath(path: string): Promise<void> {
     if (this.isDisposed || this._path === path) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
     this._path = path;
     if (this._session) {
       return this._session.setPath(path);
     }
     this._propertyChanged.emit('path');
-    return Promise.resolve(void 0);
+    return Promise.resolve();
   }
 
   /**
@@ -466,14 +466,14 @@ export class ClientSession implements IClientSession {
    */
   setName(name: string): Promise<void> {
     if (this.isDisposed || this._name === name) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
     this._name = name;
     if (this._session) {
       return this._session.setName(name);
     }
     this._propertyChanged.emit('name');
-    return Promise.resolve(void 0);
+    return Promise.resolve();
   }
 
   /**
@@ -481,14 +481,14 @@ export class ClientSession implements IClientSession {
    */
   setType(type: string): Promise<void> {
     if (this.isDisposed || this._type === type) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
     this._type = type;
     if (this._session) {
       return this._session.setType(name);
     }
     this._propertyChanged.emit('type');
-    return Promise.resolve(void 0);
+    return Promise.resolve();
   }
 
   /**
@@ -536,14 +536,13 @@ export class ClientSession implements IClientSession {
       preference.shouldStart === false ||
       preference.canStart === false
     ) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
     // Try to use an existing kernel.
     if (preference.id) {
-      return this._changeKernel({ id: preference.id }).then(
-        () => void 0,
-        () => this._selectKernel(false)
-      );
+      return this._changeKernel({ id: preference.id })
+        .then(() => undefined)
+        .catch(() => this._selectKernel(false));
     }
     let name = ClientSession.getDefaultKernel({
       specs: this.manager.specs,
@@ -551,10 +550,9 @@ export class ClientSession implements IClientSession {
       preference
     });
     if (name) {
-      return this._changeKernel({ name }).then(
-        () => void 0,
-        () => this._selectKernel(false)
-      );
+      return this._changeKernel({ name })
+        .then(() => undefined)
+        .catch(() => this._selectKernel(false));
     }
     return this._selectKernel(false);
   }
@@ -579,13 +577,13 @@ export class ClientSession implements IClientSession {
   /**
    * Select a kernel.
    *
-   * @param cancellable: whether the dialog should have a cancel button.
+   * @param cancelable: whether the dialog should have a cancel button.
    */
-  private _selectKernel(cancellable: boolean): Promise<void> {
+  private _selectKernel(cancelable: boolean): Promise<void> {
     if (this.isDisposed) {
-      return Promise.resolve(void 0);
+      return Promise.resolve();
     }
-    const buttons = cancellable
+    const buttons = cancelable
       ? [Dialog.cancelButton(), Dialog.okButton({ label: 'SELECT' })]
       : [Dialog.okButton({ label: 'SELECT' })];
 
@@ -603,10 +601,12 @@ export class ClientSession implements IClientSession {
         }
         let model = result.value;
         if (model === null && this._session) {
-          return this.shutdown().then(() => this._kernelChanged.emit(null));
+          return this.shutdown().then(() => {
+            this._kernelChanged.emit({ oldValue: null, newValue: null });
+          });
         }
         if (model) {
-          return this._changeKernel(model).then(() => void 0);
+          return this._changeKernel(model).then(() => undefined);
         }
       })
       .then(() => {
@@ -716,9 +716,9 @@ export class ClientSession implements IClientSession {
       this._session.dispose();
     }
     this._session = null;
-    this._terminated.emit(void 0);
+    this._terminated.emit(undefined);
     if (kernel) {
-      this._kernelChanged.emit(null);
+      this._kernelChanged.emit({ oldValue: null, newValue: null });
     }
   }
 

+ 5 - 7
packages/notebook/src/panel.ts

@@ -133,18 +133,16 @@ export class NotebookPanel extends DocumentWidget<Notebook, INotebookModel> {
     sender: any,
     args: Session.IKernelChangedArgs
   ): void {
-    const kernel = args && args.newValue;
-
-    if (!this.model || !kernel) {
+    if (!this.model || !args.newValue) {
       return;
     }
-
-    kernel.ready.then(() => {
+    let { newValue } = args;
+    newValue.ready.then(() => {
       if (this.model) {
-        this._updateLanguage(kernel.info.language_info);
+        this._updateLanguage(newValue.info.language_info);
       }
     });
-    this._updateSpec(kernel);
+    this._updateSpec(newValue);
   }
 
   /**