Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New platform]Expose NP core services to the legacy UI #32480

Merged
merged 4 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}