-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Enhancements pattern #62998
Enhancements pattern #62998
Conversation
1ad678d
to
f0d5bab
Compare
Here's a PR that avoids using ids - stacey-gammon#14 |
Thanks @mattkime I like that approach! I merged your changes then made some additional changes on top. The greeter implementations have been moved to their own registry to highlight when |
41f1cc9
to
d2cd642
Compare
examples/greeting/public/plugin.ts
Outdated
(this.greetingProvider = customProvider), | ||
registerGreetingDefinition: (greetingDefinition: GreetingDefinition) => { | ||
this.greetingDefinitions[greetingDefinition.id] = greetingDefinition; | ||
return () => this.greetingProvider(greetingDefinition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't returning () => this.greetingProvider(greetingDefinition)
from within the setup
lifecycle potentially cause issues if this is called before another plugin has the chance to call setCustomProvider
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, good catch.
how about this change? (sorry I shouldn't have squashed the second commit, force of habit).
it ensures that an error is thrown if the accessor is used before this plugin's start lifecycle.
d2cd642
to
f25c73f
Compare
this.greetingDefinitions[greetingDefinition.id] = greetingDefinition; | ||
return () => { | ||
if (!this.greetingProvider) { | ||
throw new Error('Greeters can only be retrieved after setup lifecycle.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think throwing an explicit error here is definitely a step in the right direction. There's still the potential for a run-time exception. However, this already exists with the way that the NP setup/start lifecycles work in practicality after getStartServices
was introduced...
I've been trying to think of a different name for this besides "enhancements pattern", but naming is hard and I haven't come up with anything. Conceptually, it seems like we're combining the registry pattern and a variant of the factory pattern where the factory itself can be replaced... |
Yea. Maybe this can all be encapsulated under "best practices when creating and using registries" and that includes:
Once #59189 is done I would group all these multiple new plugins under a single folder. The examples folder right now is difficult to grok quickly because so many examples are split between multiple plugins. |
Registry with enhanced items? Seems like 'registry' should be in there somewhere. |
…essing statically
Co-Authored-By: Brandon Kobel <brandon.kobel@gmail.com>
Co-Authored-By: Anton Dosov <Dosantinc@gmail.com>
05b57fc
to
42eba3f
Compare
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
sorry to provide feedback late. I am not sure how this relates to registries ? it seems that the fact that there is a registry and that we are registring item definitions in it does not affect this pattern, and we could use pattern like this to extend any functionality of any service where that would be requeired. Due to the fact that this can only be done from one place i think this should be limited to our internal usage (x-pack plugins extending the oss) and as such hidden behind a The registry with item definitions would allow us to do another thing that is not showcased in this examples (unless i missed it), that is extending the actual registered items. Lets say pugin A exposes a registry, plugin B adds few items to this registry, plugin C overrides the item in the registry with a new item, that extends the original item. i guess we could collapse all into single example, but imo this way both of the things we want to show will be less clear so i would vote for having two separate examples, and the first one not using registry to make it clear this kind of pattern can be used to extend any functionality. |
This PR adds a few example plugins to showcase the enhancements pattern discussed in #62815
From the
Enhancements_pattern_plugin
readme:Enhancements pattern
This plugin shows a recommended pattern for how one plugin can enhance another plugins functionality when dealing with a registry of items.
There are three key pieces. The plugin that creates the registry should:
setCustomProvider
function in the Setup contract.There are three plugin associated with this example.
greeting
plugin exposes a registry of greetings. The default provider uses the very basicalert
function to greet the user.greetingEnhanced
plugin registers a custom greeting provider which uses an EuiModal to greet the user with improved stylign.enhancementsPatternExplorer
registers a few example greetings as well as an app to expose thegreet
functionality.To see how this works, first run Kibana with nothing in your
kibana.yml
viayarn start --run-examples
. Navigate to the Enhancements pattern app and see how the greetings look.Then, stop kibana and edit
kibana.yml
to turn thegreetingEnhanced
plugin off by adding this line:Restart kibana and go through the same motions, and you should now see just the basic
alert
window.Screenshots:
Once I get buy in on this pattern I will add tests for the example plugin.
closes #62815