From 8396f9d19bc191f5f38fe3aa62ddb544956ba40e Mon Sep 17 00:00:00 2001 From: Aleksandar Djindjic Date: Sun, 22 Jan 2023 14:05:48 +0100 Subject: [PATCH 1/2] Improved typings Passing this first param to `CoreSetup` generic would set a proper type to `depsStart` returned from `core.getStartServices()` Signed-off-by: Aleksandar Djindjic --- src/core/CONVENTIONS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/CONVENTIONS.md b/src/core/CONVENTIONS.md index 5d24b54d9920..fff8282b42da 100644 --- a/src/core/CONVENTIONS.md +++ b/src/core/CONVENTIONS.md @@ -182,10 +182,10 @@ export const renderApp = ( ```ts // my_plugin/public/plugin.ts -import { Plugin } from '../../src/core/public'; +import { Plugin, CoreSetup } from '../../src/core/public'; export class MyPlugin implements Plugin { - public setup(core) { + public setup(core: CoreSetup) { core.application.register({ id: 'my-app', async mount(params) { From a29a03bfcd9017a4e551ee3593cae4df6da6e744 Mon Sep 17 00:00:00 2001 From: Josh Romero Date: Wed, 8 Mar 2023 21:28:49 +0000 Subject: [PATCH 2/2] Nit - rename example deps prop Signed-off-by: Josh Romero --- src/core/CONVENTIONS.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/CONVENTIONS.md b/src/core/CONVENTIONS.md index fff8282b42da..7c3de41e5751 100644 --- a/src/core/CONVENTIONS.md +++ b/src/core/CONVENTIONS.md @@ -171,7 +171,7 @@ import { MyAppRoot } from './components/app.ts'; */ export const renderApp = ( core: CoreStart, - deps: MyPluginDepsStart, + deps: MyPluginStartDeps, { element, history }: AppMountParameters ) => { ReactDOM.render(, element); @@ -185,7 +185,7 @@ export const renderApp = ( import { Plugin, CoreSetup } from '../../src/core/public'; export class MyPlugin implements Plugin { - public setup(core: CoreSetup) { + public setup(core: CoreSetup) { core.application.register({ id: 'my-app', async mount(params) { @@ -200,14 +200,14 @@ export class MyPlugin implements Plugin { } ``` -Prefer the pattern shown above, using `core.getStartServices()`, rather than store local references retrieved from `start`. +Prefer the pattern shown above, using `core.getStartServices()`, rather than store local references retrieved from `start`. **Bad:** ```ts export class MyPlugin implements Plugin { // Anti pattern private coreStart?: CoreStart; - private depsStart?: DepsStart; + private depsStart?: DepsStart; public setup(core) { core.application.register({ @@ -218,7 +218,7 @@ export class MyPlugin implements Plugin { return renderApp(this.coreStart, this.depsStart, params); } }); - } + } public start(core, deps) { // Anti pattern @@ -359,5 +359,5 @@ Migration example from the legacy format is available in `src/core/MIGRATION_EXA ### Naming conventions -Export start and setup contracts as `MyPluginStart` and `MyPluginSetup`. +Export start and setup contracts as `MyPluginStart` and `MyPluginSetup`. This avoids naming clashes, if everyone exported them simply as `Start` and `Setup`.