Przeglądaj źródła

Use signal to communication uris availabilty

Eric Charles 5 lat temu
rodzic
commit
c914598c81

+ 4 - 1
packages/extensionmanager-extension/listing/listings.json

@@ -1,8 +1,11 @@
 {
   "listings": {
     "blacklist_uri": "",
-    "builtin_blacklist": [],
+
     "whitelist_uri": "",
+
+    "builtin_blacklist": [],
+
     "builtin_whitelist": ["@jupyterlab/*"]
   }
 }

+ 15 - 2
packages/extensionmanager/src/listings.ts

@@ -1,6 +1,8 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { ISignal, Signal } from '@lumino/signaling';
+
 import { URLExt } from '@jupyterlab/coreutils';
 
 import { ServerConnection } from '@jupyterlab/services';
@@ -30,6 +32,8 @@ export interface IListingApi {
   listings: {
     blacklist_uri: string;
     whitelist_uri: string;
+    builtin_blacklist: string[];
+    builtin_whitelist: string[];
   };
 }
 
@@ -48,12 +52,17 @@ export class Lister {
       .then(data => {
         this.blackListUri = data.listings.blacklist_uri;
         this.whiteListUri = data.listings.whitelist_uri;
+        this._listingUrisLoaded.emit(void 0);
       })
       .catch(error => {
         console.error(error);
       });
   }
 
+  get listingUrisLoaded(): ISignal<Lister, void> {
+    return this._listingUrisLoaded;
+  }
+
   /**
    * Get the black list.
    *
@@ -89,12 +98,16 @@ export class Lister {
   /**
    * The URI of the black listing registry to use.
    */
-  blackListUri: string;
+  private blackListUri: string;
 
   /**
    * The URI of the white listing registry to use.
    */
-  whiteListUri: string;
+  private whiteListUri: string;
+
+  /**
+   */
+  private _listingUrisLoaded = new Signal<Lister, void>(this);
 }
 
 /**

+ 16 - 5
packages/extensionmanager/src/model.ts

@@ -167,6 +167,22 @@ export class ListModel extends VDomModel {
     this.serviceManager = serviceManager;
     this.serverConnectionSettings = ServerConnection.makeSettings();
     this._debouncedUpdate = new Debouncer(this.update.bind(this), 1000);
+    this.lister.listingUrisLoaded.connect(() => {
+      this.performGetBlacklist()
+        .then(data => {
+          this._blacklistingMap = data;
+        })
+        .catch(error => {
+          console.error(error);
+        });
+      this.performGetWhitelist()
+        .then(data => {
+          this._whitelistingMap = data;
+        })
+        .catch(error => {
+          console.error(error);
+        });
+    });
   }
 
   /**
@@ -646,11 +662,6 @@ export class ListModel extends VDomModel {
   protected async update(refreshInstalled = false) {
     // Start both queries before awaiting:
 
-    const blacklistingPromise = this.performGetBlacklist();
-    this._blacklistingMap = await blacklistingPromise;
-    const whitelistingPromise = this.performGetWhitelist();
-    this._whitelistingMap = await whitelistingPromise;
-
     const searchMapPromise = this.performSearch(
       this._blacklistingMap,
       this._whitelistingMap

+ 3 - 3
packages/extensionmanager/src/npm.ts

@@ -288,15 +288,15 @@ export class Searcher {
  */
 export function isJupyterOrg(name: string): boolean {
   /**
-   * A list of whitelisted NPM orgs.
+   * A list of jupyterlab NPM orgs.
    */
-  const whitelist = ['jupyterlab', 'jupyter-widgets'];
+  const jupyter_org = ['jupyterlab', 'jupyter-widgets'];
   const parts = name.split('/');
   const first = parts[0];
   return (
     parts.length > 1 && // Has a first part
     !!first && // with a finite length
     first[0] === '@' && // corresponding to an org name
-    whitelist.indexOf(first.slice(1)) !== -1 // in the org whitelist.
+    jupyter_org.indexOf(first.slice(1)) !== -1 // in the org whitelist.
   );
 }

+ 3 - 3
packages/extensionmanager/tsconfig.json

@@ -10,13 +10,13 @@
       "path": "../apputils"
     },
     {
-      "path": "../services"
+      "path": "../coreutils"
     },
     {
-      "path": "../ui-components"
+      "path": "../services"
     },
     {
-      "path": "../coreutils"
+      "path": "../ui-components"
     }
   ]
 }