Replace services modules by passing down references explicitly #63596
Labels
Team:Visualizations
Visualization editors, elastic-charts and infrastructure
technical debt
Improvement of the software architecture and operational architecture
In a lot of places we are currently using the "services module" pattern to pass down references to global services within the plugin. In most cases the
createGetterSetter
utility from the utils package is used to store the references in a plugin-global module which is imported in the places the services are required.Examples:
https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts#L51
https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts#L67
https://github.com/elastic/kibana/blob/master/src/legacy/core_plugins/vis_type_table/public/services.ts#L23
This has several downsides:
All these problems go away when all dependencies are passed down explicitly from the plugin class of a plugin:
Lens and Dashboard are doing it this way:
https://github.com/elastic/kibana/blob/master/src/plugins/dashboard/public/plugin.tsx#L247
https://github.com/elastic/kibana/blob/master/x-pack/plugins/lens/public/plugin.tsx#L90
This helper is useful in closing the gap directly in the plugin class in cases where start services have to be accessed in a sync fashion: #63720
To avoid these problems, existing code should be refactored to avoid services modules. This can happen incrementally over time.
input_control_vis
vis_type_markdown
vis_type_metric
vis_type_table
vis_type_tagcloud
vis_type_timelion
vis_type_timeseries
vis_type_vega
vis_type_vislib
discover
dashboard
visualize
home
The text was updated successfully, but these errors were encountered: