From 1fe445f01b3289eab0bf9deeb50c05eef9f19731 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 19 Nov 2019 18:12:43 +0100 Subject: [PATCH] use sync getter for config on client side instead of observable --- src/core/MIGRATION.md | 14 ++++++-------- src/core/public/mocks.ts | 3 +-- src/core/public/plugins/plugin_context.ts | 7 +++---- src/core/public/plugins/plugins_service.test.ts | 6 +----- src/plugins/testbed/public/plugin.ts | 6 +----- x-pack/legacy/plugins/siem/public/apps/index.ts | 3 +-- x-pack/legacy/plugins/uptime/public/apps/index.ts | 3 +-- 7 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index 3182998dbca4b..e9e599f520009 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -1261,23 +1261,21 @@ export const config: PluginConfigDescriptor = { exposeToBrowser: ['uiProp'], schema: configSchema, }; - -export type ClientConfigType = Pick ``` -Configuration containing only the exposed properties will be then available on the client-side plugin using the same API as the server-side: +Configuration containing only the exposed properties will be then available on the client-side using the plugin's `initializerContext`: ```typescript // my_plugin/public/index.ts -import { ClientConfigType } from '../server'; +interface ClientConfigType { + uiProp: string; +} export class Plugin implements Plugin { constructor(private readonly initializerContext: PluginInitializerContext) {} public async setup(core: CoreSetup, deps: {}) { - const config = await this.initializerContext.config - .create() - .pipe(take(1)) - .toPromise(); + const config = this.initializerContext.config.get(); + // ... } ``` diff --git a/src/core/public/mocks.ts b/src/core/public/mocks.ts index 9089a6138b58a..2b09bec433660 100644 --- a/src/core/public/mocks.ts +++ b/src/core/public/mocks.ts @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -import { of } from 'rxjs'; import { applicationServiceMock } from './application/application_service.mock'; import { chromeServiceMock } from './chrome/chrome_service.mock'; import { CoreContext, CoreSetup, CoreStart, PluginInitializerContext, NotificationsSetup } from '.'; @@ -94,7 +93,7 @@ function pluginInitializerContextMock() { }, }, config: { - create: () => of({} as T), + get: () => ({} as T), }, }; diff --git a/src/core/public/plugins/plugin_context.ts b/src/core/public/plugins/plugin_context.ts index d1c05ebcd5e58..dbb76b30554a7 100644 --- a/src/core/public/plugins/plugin_context.ts +++ b/src/core/public/plugins/plugin_context.ts @@ -18,7 +18,6 @@ */ import { omit } from 'lodash'; -import { Observable, of } from 'rxjs'; import { DiscoveredPlugin } from '../../server'; import { PluginOpaqueId, PackageInfo, EnvironmentMode } from '../../server/types'; import { CoreContext } from '../core_system'; @@ -41,7 +40,7 @@ export interface PluginInitializerContext { packageInfo: Readonly; }; readonly config: { - create: () => Observable; + get: () => T; }; } @@ -67,8 +66,8 @@ export function createPluginInitializerContext( opaqueId, env: coreContext.env, config: { - create() { - return of((pluginConfig as unknown) as T); + get() { + return (pluginConfig as unknown) as T; }, }, }; diff --git a/src/core/public/plugins/plugins_service.test.ts b/src/core/public/plugins/plugins_service.test.ts index ef2a1410ddc6f..2983d7583cb49 100644 --- a/src/core/public/plugins/plugins_service.test.ts +++ b/src/core/public/plugins/plugins_service.test.ts @@ -46,7 +46,6 @@ import { CoreSetup, CoreStart, PluginInitializerContext } from '..'; import { docLinksServiceMock } from '../doc_links/doc_links_service.mock'; import { savedObjectsMock } from '../saved_objects/saved_objects_service.mock'; import { contextServiceMock } from '../context/context_service.mock'; -import { take } from 'rxjs/operators'; export let mockPluginInitializers: Map; @@ -229,10 +228,7 @@ describe('PluginsService', () => { const initializerContext = mockPluginInitializers.get('pluginA')!.mock .calls[0][0] as PluginInitializerContext; - const config = await initializerContext.config - .create() - .pipe(take(1)) - .toPromise(); + const config = initializerContext.config.get(); expect(config).toMatchObject(pluginConfig); }); diff --git a/src/plugins/testbed/public/plugin.ts b/src/plugins/testbed/public/plugin.ts index 32f9be3498a11..8c70485d9ee8b 100644 --- a/src/plugins/testbed/public/plugin.ts +++ b/src/plugins/testbed/public/plugin.ts @@ -17,7 +17,6 @@ * under the License. */ -import { take } from 'rxjs/operators'; import { Plugin, CoreSetup, PluginInitializerContext } from 'kibana/public'; interface ConfigType { @@ -28,10 +27,7 @@ export class TestbedPlugin implements Plugin() - .pipe(take(1)) - .toPromise(); + const config = this.initializerContext.config.get(); // eslint-disable-next-line no-console console.log(`Testbed plugin set up. uiProp: '${config.uiProp}'`); diff --git a/x-pack/legacy/plugins/siem/public/apps/index.ts b/x-pack/legacy/plugins/siem/public/apps/index.ts index 1f53707cd973d..73f9b65ba3546 100644 --- a/x-pack/legacy/plugins/siem/public/apps/index.ts +++ b/x-pack/legacy/plugins/siem/public/apps/index.ts @@ -4,13 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { of } from 'rxjs'; import chrome from 'ui/chrome'; import { npStart } from 'ui/new_platform'; import { Plugin } from './plugin'; new Plugin( // eslint-disable-next-line @typescript-eslint/no-explicit-any - { opaqueId: Symbol('siem'), env: {} as any, config: { create: () => of({} as any) } }, + { opaqueId: Symbol('siem'), env: {} as any, config: { get: () => ({} as any) } }, chrome ).start(npStart.core, npStart.plugins); diff --git a/x-pack/legacy/plugins/uptime/public/apps/index.ts b/x-pack/legacy/plugins/uptime/public/apps/index.ts index 20a8156d7b066..53a74022778f4 100644 --- a/x-pack/legacy/plugins/uptime/public/apps/index.ts +++ b/x-pack/legacy/plugins/uptime/public/apps/index.ts @@ -4,12 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { of } from 'rxjs'; import chrome from 'ui/chrome'; import { npStart } from 'ui/new_platform'; import { Plugin } from './plugin'; new Plugin( - { opaqueId: Symbol('uptime'), env: {} as any, config: { create: () => of({} as any) } }, + { opaqueId: Symbol('uptime'), env: {} as any, config: { get: () => ({} as any) } }, chrome ).start(npStart);