Skip to content

Commit

Permalink
Resolver test plugin not using mount context. (#54933)
Browse files Browse the repository at this point in the history
Mount context was deprecated. Use core.getStartServices() instead.
  • Loading branch information
Robert Austin authored Jan 15, 2020
1 parent 781ef7a commit 63ad7a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useEffect } from 'react';
import styled from 'styled-components';

/**
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle.
* Render the Resolver Test app. Returns a cleanup function.
*/
export function renderApp(
{ element }: AppMountParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,35 @@ export class ResolverTestPlugin
ResolverTestPluginSetupDependencies,
ResolverTestPluginStartDependencies
> {
private resolveEmbeddable!: (
value: IEmbeddable | undefined | PromiseLike<IEmbeddable | undefined> | undefined
) => void;
/**
* We register our application during the `setup` phase, but the embeddable
* plugin API is not available until the `start` phase. In order to access
* the embeddable API from our application, we pass a Promise to the application
* which we resolve during the `start` phase.
*/
private embeddablePromise: Promise<IEmbeddable | undefined> = new Promise<
IEmbeddable | undefined
>(resolve => {
this.resolveEmbeddable = resolve;
});
public setup(core: CoreSetup) {
public setup(core: CoreSetup<ResolverTestPluginStartDependencies>) {
core.application.register({
id: 'resolver_test',
title: i18n.translate('xpack.resolver_test.pluginTitle', {
defaultMessage: 'Resolver Test',
}),
mount: async (_context, params) => {
let resolveEmbeddable: (
value: IEmbeddable | undefined | PromiseLike<IEmbeddable | undefined> | undefined
) => void;

const promise = new Promise<IEmbeddable | undefined>(resolve => {
resolveEmbeddable = resolve;
});

(async () => {
const [, { embeddable }] = await core.getStartServices();
const factory = embeddable.getEmbeddableFactory('resolver');
resolveEmbeddable!(factory.create({ id: 'test basic render' }));
})();

const { renderApp } = await import('./applications/resolver_test');
/**
* Pass a promise which resolves to the Resolver embeddable.
*/
return renderApp(params, this.embeddablePromise);
return renderApp(params, promise);
},
});
}

public start(...args: [unknown, { embeddable: IEmbeddableStart }]) {
const [, plugins] = args;
const factory = plugins.embeddable.getEmbeddableFactory('resolver');
/**
* Provide the Resolver embeddable to the application
*/
this.resolveEmbeddable(factory.create({ id: 'test basic render' }));
}
public stop() {}
public start() {}
}

0 comments on commit 63ad7a9

Please sign in to comment.