mirror of https://github.com/grafana/grafana
Plugins: Support es5 plugins extending es6 core classes (#32664)
* Plugins: Support es5 plugins extending es6 core classes * Make all base classes backward compatiblepull/32721/head
parent
7374f380bd
commit
693985a6ba
@ -0,0 +1,16 @@ |
||||
/** |
||||
* @beta |
||||
* Proxies a ES6 class so that it can be used as a base class for an ES5 class |
||||
*/ |
||||
export function makeClassES5Compatible<T>(ES6Class: T): T { |
||||
return (new Proxy(ES6Class as any, { |
||||
// ES5 code will call it like a function using super
|
||||
apply(target, self, argumentsList) { |
||||
if (typeof Reflect === 'undefined' || !Reflect.construct) { |
||||
alert('Browser is too old'); |
||||
} |
||||
|
||||
return Reflect.construct(target, argumentsList, self.constructor); |
||||
}, |
||||
}) as unknown) as T; |
||||
} |
@ -1,7 +1,12 @@ |
||||
import { PanelCtrl } from 'app/features/panel/panel_ctrl'; |
||||
import { MetricsPanelCtrl } from 'app/features/panel/metrics_panel_ctrl'; |
||||
import { QueryCtrl } from 'app/features/panel/query_ctrl'; |
||||
import { alertTab } from 'app/features/alerting/AlertTabCtrl'; |
||||
import { makeClassES5Compatible } from '@grafana/data'; |
||||
import { loadPluginCss } from '@grafana/runtime'; |
||||
import { PanelCtrl as PanelCtrlES6 } from 'app/features/panel/panel_ctrl'; |
||||
import { MetricsPanelCtrl as MetricsPanelCtrlES6 } from 'app/features/panel/metrics_panel_ctrl'; |
||||
import { QueryCtrl as QueryCtrlES6 } from 'app/features/panel/query_ctrl'; |
||||
import { alertTab } from 'app/features/alerting/AlertTabCtrl'; |
||||
|
||||
const PanelCtrl = makeClassES5Compatible(PanelCtrlES6); |
||||
const MetricsPanelCtrl = makeClassES5Compatible(MetricsPanelCtrlES6); |
||||
const QueryCtrl = makeClassES5Compatible(QueryCtrlES6); |
||||
|
||||
export { PanelCtrl, MetricsPanelCtrl, QueryCtrl, alertTab, loadPluginCss }; |
||||
|
Loading…
Reference in new issue