Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Improved typings (opensearch-project#3302)
Browse files Browse the repository at this point in the history
* 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 <djindjic@gmail.com>

* Nit - rename example deps prop

Signed-off-by: Josh Romero <rmerqg@amazon.com>

---------

Signed-off-by: Aleksandar Djindjic <djindjic@gmail.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: Miki <miki@amazon.com>
Signed-off-by: David Sinclair <david@sinclair.tech>
  • Loading branch information
3 people authored and sikhote committed Apr 24, 2023
1 parent bd903e9 commit 3a84bc3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import { MyAppRoot } from './components/app.ts';
*/
export const renderApp = (
core: CoreStart,
deps: MyPluginDepsStart,
deps: MyPluginStartDeps,
{ element, history }: AppMountParameters
) => {
ReactDOM.render(<MyAppRoot core={core} deps={deps} routerHistory={history} />, element);
Expand All @@ -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<MyPluginStartDeps>) {
core.application.register({
id: 'my-app',
async mount(params) {
Expand All @@ -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({
Expand All @@ -218,7 +218,7 @@ export class MyPlugin implements Plugin {
return renderApp(this.coreStart, this.depsStart, params);
}
});
}
}

public start(core, deps) {
// Anti pattern
Expand Down Expand Up @@ -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`.

0 comments on commit 3a84bc3

Please sign in to comment.