Skip to content

Commit

Permalink
[New platform]Expose NP core services to the legacy UI (#32480)
Browse files Browse the repository at this point in the history
* Expose NP core services to the legacy UI

* declare start/stop explicitly

* simplify typings + renaming
  • Loading branch information
mshustov authored Mar 7, 2019
1 parent a188f53 commit d98538b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/core/public/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ export interface LegacyPlatformParams {
export class LegacyPlatformService {
constructor(private readonly params: LegacyPlatformParams) {}

public start({
i18n,
injectedMetadata,
fatalErrors,
notifications,
http,
basePath,
uiSettings,
chrome,
}: Deps) {
public start(deps: Deps) {
const {
i18n,
injectedMetadata,
fatalErrors,
notifications,
http,
basePath,
uiSettings,
chrome,
} = deps;
// Inject parts of the new platform into parts of the legacy platform
// so that legacy APIs/modules can mimic their new platform counterparts
require('ui/new_platform').__newPlatformInit__(deps);
require('ui/metadata').__newPlatformInit__(injectedMetadata.getLegacyMetadata());
require('ui/i18n').__newPlatformInit__(i18n.Context);
require('ui/notify/fatal_error').__newPlatformInit__(fatalErrors);
Expand Down
19 changes: 19 additions & 0 deletions src/legacy/ui/public/new_platform/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export { __newPlatformInit__, getNewPlatform } from './new_platform';
57 changes: 57 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { BasePathStart } from '../../../../core/public/base_path';
import { ChromeStart } from '../../../../core/public/chrome';
import { FatalErrorsStart } from '../../../../core/public/fatal_errors';
import { HttpStart } from '../../../../core/public/http';
import { I18nStart } from '../../../../core/public/i18n';
import { InjectedMetadataStart } from '../../../../core/public/injected_metadata';
import { NotificationsStart } from '../../../../core/public/notifications';
import { UiSettingsClient } from '../../../../core/public/ui_settings';

interface CoreStart {
i18n: I18nStart;
injectedMetadata: InjectedMetadataStart;
fatalErrors: FatalErrorsStart;
notifications: NotificationsStart;
http: HttpStart;
basePath: BasePathStart;
uiSettings: UiSettingsClient;
chrome: ChromeStart;
}

const runtimeContext = {
start: {
core: null as CoreStart | null,
plugins: {},
},
};

export function __newPlatformInit__(core: CoreStart) {
if (runtimeContext.start.core) {
throw new Error('New platform core api was already initialized');
}

runtimeContext.start.core = core;
}

export function getNewPlatform() {
return runtimeContext;
}

0 comments on commit d98538b

Please sign in to comment.