2020-06-15 08:46:36 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2020-06-15 08:46:36 +02:00
|
|
|
*/
|
|
|
|
|
2020-11-23 11:58:49 +01:00
|
|
|
import { DataHandler, ObservabilityFetchDataPlugins } from './typings/fetch_overview_data';
|
2020-06-15 08:46:36 +02:00
|
|
|
|
2020-09-23 15:44:40 +02:00
|
|
|
const dataHandlers: Partial<Record<ObservabilityFetchDataPlugins, DataHandler>> = {};
|
2020-06-15 08:46:36 +02:00
|
|
|
|
2020-09-23 15:44:40 +02:00
|
|
|
export function registerDataHandler<T extends ObservabilityFetchDataPlugins>({
|
2020-06-25 17:19:38 +02:00
|
|
|
appName,
|
|
|
|
fetchData,
|
|
|
|
hasData,
|
|
|
|
}: { appName: T } & DataHandler<T>) {
|
2020-06-15 08:46:36 +02:00
|
|
|
dataHandlers[appName] = { fetchData, hasData };
|
2020-06-25 17:19:38 +02:00
|
|
|
}
|
2020-06-15 08:46:36 +02:00
|
|
|
|
2020-09-23 15:44:40 +02:00
|
|
|
export function unregisterDataHandler<T extends ObservabilityFetchDataPlugins>({
|
|
|
|
appName,
|
|
|
|
}: {
|
|
|
|
appName: T;
|
|
|
|
}) {
|
2020-07-08 21:52:16 +02:00
|
|
|
delete dataHandlers[appName];
|
|
|
|
}
|
|
|
|
|
2020-09-23 15:44:40 +02:00
|
|
|
export function getDataHandler<T extends ObservabilityFetchDataPlugins>(appName: T) {
|
2020-06-25 17:19:38 +02:00
|
|
|
const dataHandler = dataHandlers[appName];
|
|
|
|
if (dataHandler) {
|
|
|
|
return dataHandler as DataHandler<T>;
|
|
|
|
}
|
2020-06-15 08:46:36 +02:00
|
|
|
}
|