From 531b19084ea771c555f7defdfe28734ba5648e6d Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Wed, 4 Dec 2019 14:46:43 -0600 Subject: [PATCH] Move setting connector to its own file and clarify loading deferred plugin settings logic in a comment. --- packages/apputils-extension/src/index.ts | 33 +++----------- .../src/settingconnector.ts | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 packages/apputils-extension/src/settingconnector.ts diff --git a/packages/apputils-extension/src/index.ts b/packages/apputils-extension/src/index.ts index acea803d3f82..4cbd210dd5dd 100644 --- a/packages/apputils-extension/src/index.ts +++ b/packages/apputils-extension/src/index.ts @@ -20,7 +20,6 @@ import { } from '@jupyterlab/apputils'; import { - DataConnector, Debouncer, ISettingRegistry, IStateDB, @@ -39,6 +38,8 @@ import { DisposableDelegate } from '@phosphor/disposable'; import { Palette } from './palette'; +import { SettingConnector } from './settingconnector'; + import { themesPlugin, themesPaletteMenuPlugin } from './themeplugins'; /** @@ -91,30 +92,8 @@ const paletteRestorer: JupyterFrontEndPlugin = { const settings: JupyterFrontEndPlugin = { id: '@jupyterlab/apputils-extension:settings', activate: async (app: JupyterFrontEnd): Promise => { - const { isDeferred, isDisabled } = PageConfig.Extension; - const connector = new (class SettingConnector extends DataConnector< - ISettingRegistry.IPlugin, - string - > { - fetch(id: string): Promise { - return app.serviceManager.settings.fetch(id); - } - - async list( - query: 'active' | 'all' = 'all' - ): Promise<{ ids: string[]; values: ISettingRegistry.IPlugin[] }> { - let { ids, values } = await app.serviceManager.settings.list(); - - if (query === 'all') { - return { ids, values }; - } - - return { - ids: ids.filter(id => !isDeferred(id) && !isDisabled(id)), - values: values.filter(({ id }) => !isDeferred(id) && !isDisabled(id)) - }; - } - })(); + const { isDisabled } = PageConfig.Extension; + const connector = new SettingConnector(app.serviceManager.settings); const registry = new SettingRegistry({ connector, @@ -122,7 +101,9 @@ const settings: JupyterFrontEndPlugin = { }); // If there are plugins that have schemas that are not in the setting - // registry after the application has restored, try to load them manually. + // registry after the application has restored, try to load them manually + // because otherwise, its settings will never become available in the + // setting registry. void app.restored.then(async () => { const plugins = await connector.list('all'); plugins.ids.forEach(async (id, index) => { diff --git a/packages/apputils-extension/src/settingconnector.ts b/packages/apputils-extension/src/settingconnector.ts new file mode 100644 index 000000000000..b1192c57a799 --- /dev/null +++ b/packages/apputils-extension/src/settingconnector.ts @@ -0,0 +1,44 @@ +import { + DataConnector, + IDataConnector, + ISettingRegistry, + PageConfig +} from '@jupyterlab/coreutils'; + +/** + * A data connector for fetching settings. + * + * #### Notes + * This connector adds a query parameter to the base services setting manager. + */ +export class SettingConnector extends DataConnector< + ISettingRegistry.IPlugin, + string +> { + constructor(connector: IDataConnector) { + super(); + this._connector = connector; + } + + fetch(id: string): Promise { + return this._connector.fetch(id); + } + + async list( + query: 'active' | 'all' = 'all' + ): Promise<{ ids: string[]; values: ISettingRegistry.IPlugin[] }> { + const { isDeferred, isDisabled } = PageConfig.Extension; + let { ids, values } = await this._connector.list(); + + if (query === 'all') { + return { ids, values }; + } + + return { + ids: ids.filter(id => !isDeferred(id) && !isDisabled(id)), + values: values.filter(({ id }) => !isDeferred(id) && !isDisabled(id)) + }; + } + + private _connector: IDataConnector; +}