當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ISettingRegistry.transform方法代碼示例

本文整理匯總了TypeScript中@jupyterlab/coreutils.ISettingRegistry.transform方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ISettingRegistry.transform方法的具體用法?TypeScript ISettingRegistry.transform怎麽用?TypeScript ISettingRegistry.transform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@jupyterlab/coreutils.ISettingRegistry的用法示例。


在下文中一共展示了ISettingRegistry.transform方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: async

  activate: async (app: JupyterLab, registry: ISettingRegistry) => {
    const { commands } = app;
    let canonical: ISettingRegistry.ISchema;
    let loaded: { [name: string]: ISettingRegistry.IShortcut[] } = {};

    /**
     * Populate the plugin's schema defaults.
     */
    function populate(schema: ISettingRegistry.ISchema) {
      loaded = {};
      schema.properties.shortcuts.default = Object.keys(registry.plugins)
        .map(plugin => {
          let shortcuts =
            registry.plugins[plugin].schema['jupyter.lab.shortcuts'] || [];
          loaded[plugin] = shortcuts;
          return shortcuts;
        })
        .reduce((acc, val) => acc.concat(val), [])
        .sort((a, b) => a.command.localeCompare(b.command));
    }

    registry.pluginChanged.connect(async (sender, plugin) => {
      if (plugin !== shortcuts.id) {
        // If the plugin changed its shortcuts, reload everything.
        let oldShortcuts = loaded[plugin];
        let newShortcuts =
          registry.plugins[plugin].schema['jupyter.lab.shortcuts'] || [];
        if (
          oldShortcuts === undefined ||
          !JSONExt.deepEqual(oldShortcuts, newShortcuts)
        ) {
          canonical = null;
          await registry.reload(shortcuts.id);
        }
      }
    });

    // Transform the plugin object to return different schema than the default.
    registry.transform(shortcuts.id, {
      compose: plugin => {
        // Only override the canonical schema the first time.
        if (!canonical) {
          canonical = JSONExt.deepCopy(plugin.schema);
          populate(canonical);
        }

        const defaults = canonical.properties.shortcuts.default;
        const user = {
          shortcuts: ((plugin.data && plugin.data.user) || {}).shortcuts || []
        };
        const composite = {
          shortcuts: SettingRegistry.reconcileShortcuts(
            defaults,
            user.shortcuts as ISettingRegistry.IShortcut[]
          )
        };

        plugin.data = { composite, user };

        return plugin;
      },
      fetch: plugin => {
        // Only override the canonical schema the first time.
        if (!canonical) {
          canonical = JSONExt.deepCopy(plugin.schema);
          populate(canonical);
        }

        return {
          data: plugin.data,
          id: plugin.id,
          raw: plugin.raw,
          schema: canonical,
          version: plugin.version
        };
      }
    });

    try {
      // Repopulate the canonical variable after the setting registry has
      // preloaded all initial plugins.
      canonical = null;

      const settings = await registry.load(shortcuts.id);

      Private.loadShortcuts(commands, settings.composite);
      settings.changed.connect(() => {
        Private.loadShortcuts(commands, settings.composite);
      });
    } catch (error) {
      console.error(`Loading ${shortcuts.id} failed.`, error);
    }
  },
開發者ID:AlbertHilb,項目名稱:jupyterlab,代碼行數:93,代碼來源:index.ts


注:本文中的@jupyterlab/coreutils.ISettingRegistry.transform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。