Pārlūkot izejas kodu

Update setting registry instantiation with plugin preload.

Afshin Darian 6 gadi atpakaļ
vecāks
revīzija
5db35a482a
1 mainītis faili ar 15 papildinājumiem un 9 dzēšanām
  1. 15 9
      packages/apputils-extension/src/index.ts

+ 15 - 9
packages/apputils-extension/src/index.ts

@@ -104,22 +104,27 @@ class SettingsConnector extends DataConnector<
   }
 
   /**
-   * Retrieve a saved bundle from the data connector.
-   *
-   * #### Notes
-   * If `id` is empty, this method will fetch all setting bundles.
+   * Retrieve a plugin from the data connector.
    */
-  async fetch(id = ''): Promise<ISettingRegistry.IPlugin> {
+  async fetch(id: string): Promise<ISettingRegistry.IPlugin> {
     const data = await this._manager.settings.fetch(id);
 
-    // Replace the server ID with the original unmodified version.
-    if (id) {
+    // If ID exists, replace server ID with the original requested ID.
+    // This only applies to non-empty plugin requests and ignores list requests.
+    if (data.id) {
       data.id = id;
     }
 
     return data;
   }
 
+  /**
+   * Retrieve all available plugins from the data connector.
+   */
+  list(): Promise<ISettingRegistry.IPlugin[]> {
+    return this._manager.settings.list();
+  }
+
   /**
    * Save the user setting data in the data connector.
    */
@@ -161,10 +166,11 @@ const paletteRestorer: JupyterLabPlugin<void> = {
  */
 const settings: JupyterLabPlugin<ISettingRegistry> = {
   id: '@jupyterlab/apputils-extension:settings',
-  activate: (app: JupyterLab): ISettingRegistry => {
+  activate: async (app: JupyterLab): Promise<ISettingRegistry> => {
     const connector = new SettingsConnector(app.serviceManager);
+    const plugins = await connector.list();
 
-    return new SettingRegistry({ connector });
+    return new SettingRegistry({ connector, plugins });
   },
   autoStart: true,
   provides: ISettingRegistry