Skip to content

Commit

Permalink
[ML] Fixing app clean up (#60853) (#60894)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jgowdyelastic and elasticmachine authored Mar 23, 2020
1 parent f85bfd6 commit e7d8010
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions x-pack/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,16 @@ type MlDependencies = MlSetupDependencies & MlStartDependencies;
interface AppProps {
coreStart: CoreStart;
deps: MlDependencies;
appMountParams: AppMountParameters;
}

const localStorage = new Storage(window.localStorage);

const App: FC<AppProps> = ({ coreStart, deps, appMountParams }) => {
setDependencyCache({
indexPatterns: deps.data.indexPatterns,
timefilter: deps.data.query.timefilter,
fieldFormats: deps.data.fieldFormats,
autocomplete: deps.data.autocomplete,
config: coreStart.uiSettings!,
chrome: coreStart.chrome!,
docLinks: coreStart.docLinks!,
toastNotifications: coreStart.notifications.toasts,
overlays: coreStart.overlays,
recentlyAccessed: coreStart.chrome!.recentlyAccessed,
basePath: coreStart.http.basePath,
savedObjectsClient: coreStart.savedObjects.client,
application: coreStart.application,
http: coreStart.http,
security: deps.security,
urlGenerators: deps.share.urlGenerators,
});

const mlLicense = setLicenseCache(deps.licensing);

appMountParams.onAppLeave(actions => {
mlLicense.unsubscribe();
clearCache();
return actions.default();
});

const App: FC<AppProps> = ({ coreStart, deps }) => {
const pageDeps = {
indexPatterns: deps.data.indexPatterns,
config: coreStart.uiSettings!,
setBreadcrumbs: coreStart.chrome!.setBreadcrumbs,
};

const services = {
appName: 'ML',
data: deps.data,
Expand All @@ -85,10 +56,34 @@ export const renderApp = (
deps: MlDependencies,
appMountParams: AppMountParameters
) => {
ReactDOM.render(
<App coreStart={coreStart} deps={deps} appMountParams={appMountParams} />,
appMountParams.element
);
setDependencyCache({
indexPatterns: deps.data.indexPatterns,
timefilter: deps.data.query.timefilter,
fieldFormats: deps.data.fieldFormats,
autocomplete: deps.data.autocomplete,
config: coreStart.uiSettings!,
chrome: coreStart.chrome!,
docLinks: coreStart.docLinks!,
toastNotifications: coreStart.notifications.toasts,
overlays: coreStart.overlays,
recentlyAccessed: coreStart.chrome!.recentlyAccessed,
basePath: coreStart.http.basePath,
savedObjectsClient: coreStart.savedObjects.client,
application: coreStart.application,
http: coreStart.http,
security: deps.security,
urlGenerators: deps.share.urlGenerators,
});

return () => ReactDOM.unmountComponentAtNode(appMountParams.element);
const mlLicense = setLicenseCache(deps.licensing);

appMountParams.onAppLeave(actions => actions.default());

ReactDOM.render(<App coreStart={coreStart} deps={deps} />, appMountParams.element);

return () => {
mlLicense.unsubscribe();
clearCache();
ReactDOM.unmountComponentAtNode(appMountParams.element);
};
};

0 comments on commit e7d8010

Please sign in to comment.