Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start services #63720

Merged
merged 2 commits into from Apr 16, 2020
Merged

Start services #63720

merged 2 commits into from Apr 16, 2020

Conversation

streamich
Copy link
Contributor

@streamich streamich commented Apr 16, 2020

Summary

Adds createStartServicesGetter utility.

Usage example:

setup(core, plugins) {
  const start = createStartServicesGetter(core.getStartServices);

  plugins.expressions.registerFunction(someCanvasFunction(start));
}

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@streamich streamich requested a review from a team as a code owner April 16, 2020 14:43
@streamich streamich added release_note:skip Skip the PR/issue when compiling release notes review Team:AppArch v7.8.0 v8.0.0 labels Apr 16, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! I tested it in the data plugin (temporarily removing the service getters we were using in getInternalStartServices), and it all worked as expected.

You just have to remember to pass the correct parameters to the CoreSetup generic so that TS doesn't complain:

  public setup(
    core: CoreSetup<DataStartDependencies, DataPublicPluginStart>,
    { expressions, uiActions }: DataSetupDependencies
  ): DataPublicPluginSetup {
    const startServices = createStartServicesGetter(core.getStartServices);

    // ultimately we can just get rid of this function & instead pass `startServices`
    const getInternalStartServices: GetInternalStartServicesFn = () => {
      const { core: coreStart, self } = startServices();
      return {
        fieldFormats: self.fieldFormats,
        notifications: coreStart.notifications,
      };
    };
    // ...etc
  }

One pattern we could discuss as a next step is how we want to pass down a single service, in cases where we want to be explicit about which start services are actually required by a component. But IMO this solves the overarching problem in the simplest way possible.

@lukeelmers lukeelmers requested review from alexwizp and a team April 16, 2020 20:09
@streamich
Copy link
Contributor Author

streamich commented Apr 16, 2020

One pattern we could discuss as a next step is how we want to pass down a single service, in cases where we want to be explicit about which start services are actually required by a component.

One way is to use casting, this way code stays nice and clean.

interface SomethingParams {
  start: StartServicesGetter<Pick<MyPluginStartDeps, 'data'>>;
}

class Something {
  constructor({ start }: SomethingParams) {
    start().plugins.data.indexPatterns(...)
  }
}

and in plugin itself no changes needed:

setup(core) {
  const start = createStartServicesGetter(core.getStartServices);
  new Something({ start });
}

@streamich streamich merged commit 239f73b into elastic:master Apr 16, 2020
streamich added a commit that referenced this pull request Apr 17, 2020
* feat: 🎸 add createStartServicesGetter() to /public  kibana_util

* test: 💍 add createStartServicesGetter() tests
gmmorris added a commit to gmmorris/kibana that referenced this pull request Apr 17, 2020
* master: (40 commits)
  [APM]Upgrade apm-rum agent to latest version to fix full page reload (elastic#63723)
  add deprecation warning for legacy 3rd party plugins (elastic#62401)
  Migrate timelion vis (elastic#62819)
  Replacebad scope link with actual values (elastic#63444)
  Index pattern management UI -> TypeScript and New Platform Ready (create_index_pattern_wizard) (elastic#63111)
  [SIEM] Threat hunting enhancements: Filter for/out value, Show top field, Copy to Clipboard, Draggable chart legends (elastic#61207)
  [Maps] fix term join agg key collision (elastic#63324)
  [Ingest] Fix agent config key sorting (elastic#63488)
  [Monitoring] Fixed server response errors (elastic#63181)
  update elastic charts to 18.3.0 (elastic#63732)
  Start services (elastic#63720)
  [APM] Encode spaces when creating ML job (elastic#63683)
  Uptime 7.7 docs (elastic#62228)
  [DOCS] Updates remote cluster and ccr docs (elastic#63517)
  [Maps] Add 3rd party vector tile support (elastic#62084)
  [Endpoint][EPM] Retrieve Index Pattern from Ingest Manager (elastic#63016)
  [Endpoint] Host Details Policy Response Panel (elastic#63518)
  [Uptime] Certificate expiration threshold settings (elastic#63682)
  Refactor saved object types to use `namespaceType` (elastic#63217)
  [SIEM][CASE] Create comments sequentially (elastic#63692)
  ...
@streamich streamich mentioned this pull request Apr 30, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants