Skip to content

Commit

Permalink
lazy load React components + VegaParser
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Apr 29, 2020
1 parent ad89b1e commit d05e9ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/plugins/vis_type_vega/public/vega_request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import { Filter, esQuery, TimeRange, Query } from '../../data/public';

// @ts-ignore
import { VegaParser } from './data_model/vega_parser';
// @ts-ignore
import { SearchCache } from './data_model/search_cache';
// @ts-ignore
Expand All @@ -46,7 +44,12 @@ export function createVegaRequestHandler({
const { timefilter } = data.query.timefilter;
const timeCache = new TimeCache(timefilter, 3 * 1000);

return ({ timeRange, filters, query, visParams }: VegaRequestHandlerParams) => {
return async function vegaRequestHandler({
timeRange,
filters,
query,
visParams,
}: VegaRequestHandlerParams) {
if (!searchCache) {
searchCache = new SearchCache(getData().search.__LEGACY.esClient, {
max: 10,
Expand All @@ -58,8 +61,10 @@ export function createVegaRequestHandler({

const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);
const filtersDsl = esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs);
// @ts-ignore
const { VegaParser } = await import('./data_model/vega_parser');
const vp = new VegaParser(visParams.spec, searchCache, timeCache, filtersDsl, serviceSettings);

return vp.parseAsync();
return await vp.parseAsync();
};
}
4 changes: 2 additions & 2 deletions src/plugins/vis_type_vega/public/vega_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { VegaView } from './vega_view/vega_view';
import { VegaMapView } from './vega_view/vega_map_view';
import { getNotifications, getData, getSavedObjects } from './services';

export const createVegaVisualization = ({ serviceSettings }) =>
Expand Down Expand Up @@ -117,8 +115,10 @@ export const createVegaVisualization = ({ serviceSettings }) =>

if (vegaParser.useMap) {
const services = { toastService: getNotifications().toasts };
const { VegaMapView } = await import('./vega_view/vega_map_view');
this._vegaView = new VegaMapView(vegaViewParams, services);
} else {
const { VegaView } = await import('./vega_view/vega_view');
this._vegaView = new VegaView(vegaViewParams);
}
await this._vegaView.init();
Expand Down

0 comments on commit d05e9ef

Please sign in to comment.