From 072d0793d29805a42c4d9e2cacbe57701dd486b4 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 10 Nov 2023 11:32:50 +0100 Subject: [PATCH] chore(compass-shell): convert to new plugin interface COMPASS-7399 (#5086) Co-authored-by: Sergey Petushkov --- package-lock.json | 16 ++-- packages/compass-home/package.json | 2 + .../compass-home/src/components/home.spec.tsx | 22 ++++- .../compass-home/src/components/workspace.tsx | 4 +- packages/compass-shell/package.json | 13 +-- .../compass-shell/compass-shell.tsx | 4 +- packages/compass-shell/src/index.ts | 46 +++++----- packages/compass-shell/src/modules/index.ts | 7 -- .../src/{plugin.spec.jsx => plugin.spec.tsx} | 55 ++++++++---- packages/compass-shell/src/plugin.tsx | 88 +++++++++++-------- .../compass-shell/src/stores/store.spec.ts | 52 ++++------- packages/compass-shell/src/stores/store.ts | 46 +++++----- 12 files changed, 196 insertions(+), 159 deletions(-) rename packages/compass-shell/src/{plugin.spec.jsx => plugin.spec.tsx} (55%) diff --git a/package-lock.json b/package-lock.json index ecdcd4db5f2..7b2615a2f8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46018,6 +46018,7 @@ "@mongodb-js/compass-import-export": "^7.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-settings": "^0.21.1", + "@mongodb-js/compass-shell": "^3.19.1", "@mongodb-js/compass-welcome": "^0.18.1", "@mongodb-js/connection-storage": "^0.6.6", "compass-preferences-model": "^2.15.6", @@ -46060,6 +46061,7 @@ "@mongodb-js/compass-import-export": "^7.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-settings": "^0.21.1", + "@mongodb-js/compass-shell": "^3.19.1", "@mongodb-js/compass-welcome": "^0.18.1", "@mongodb-js/connection-storage": "^0.6.6", "compass-preferences-model": "^2.15.6", @@ -47089,9 +47091,10 @@ "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-user-data": "^0.1.9", "@mongodb-js/compass-utils": "^0.5.5", - "@mongodb-js/mongodb-redux-common": "^2.0.15", "@mongosh/node-runtime-worker-thread": "^2.0.2", - "compass-preferences-model": "^2.15.6" + "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1" }, "devDependencies": { "@mongodb-js/eslint-config-compass": "^1.0.11", @@ -47106,9 +47109,7 @@ "electron": "^25.9.3", "enzyme": "^3.11.0", "eslint": "^7.25.0", - "hadron-app-registry": "^9.0.14", "mocha": "^10.2.0", - "mongodb-data-service": "^22.15.0", "nyc": "^15.1.0", "prop-types": "^15.7.2", "react-dom": "^17.0.2", @@ -47121,9 +47122,10 @@ "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-user-data": "^0.1.9", "@mongodb-js/compass-utils": "^0.5.5", - "@mongodb-js/mongodb-redux-common": "^2.0.15", "@mongosh/node-runtime-worker-thread": "^2.0.2", "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1", "react": "^17.0.2" } }, @@ -59179,6 +59181,7 @@ "@mongodb-js/compass-import-export": "^7.19.1", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-settings": "^0.21.1", + "@mongodb-js/compass-shell": "^3.19.1", "@mongodb-js/compass-welcome": "^0.18.1", "@mongodb-js/connection-storage": "^0.6.6", "@mongodb-js/eslint-config-compass": "^1.0.11", @@ -60163,7 +60166,6 @@ "@mongodb-js/compass-utils": "^0.5.5", "@mongodb-js/eslint-config-compass": "^1.0.11", "@mongodb-js/mocha-config-compass": "^1.3.2", - "@mongodb-js/mongodb-redux-common": "^2.0.15", "@mongodb-js/prettier-config-compass": "^1.0.1", "@mongodb-js/tsconfig-compass": "^1.0.3", "@mongodb-js/webpack-config-compass": "^1.2.5", @@ -60178,7 +60180,7 @@ "eslint": "^7.25.0", "hadron-app-registry": "^9.0.14", "mocha": "^10.2.0", - "mongodb-data-service": "^22.15.0", + "mongodb-data-service": "^22.15.1", "nyc": "^15.1.0", "prop-types": "^15.7.2", "react-dom": "^17.0.2", diff --git a/packages/compass-home/package.json b/packages/compass-home/package.json index ea5d7fab2c0..291f570dbe3 100644 --- a/packages/compass-home/package.json +++ b/packages/compass-home/package.json @@ -45,6 +45,7 @@ "@mongodb-js/compass-databases-collections": "^1.19.1", "@mongodb-js/compass-find-in-page": "^4.19.1", "@mongodb-js/compass-import-export": "^7.19.1", + "@mongodb-js/compass-shell": "^3.19.1", "compass-preferences-model": "^2.15.6", "hadron-app-registry": "^9.0.14", "hadron-ipc": "^3.2.4", @@ -62,6 +63,7 @@ "@mongodb-js/compass-databases-collections": "^1.19.1", "@mongodb-js/compass-find-in-page": "^4.19.1", "@mongodb-js/compass-import-export": "^7.19.1", + "@mongodb-js/compass-shell": "^3.19.1", "compass-preferences-model": "^2.15.6", "hadron-app-registry": "^9.0.14", "hadron-ipc": "^3.2.4", diff --git a/packages/compass-home/src/components/home.spec.tsx b/packages/compass-home/src/components/home.spec.tsx index fd60553ecc8..040320fa101 100644 --- a/packages/compass-home/src/components/home.spec.tsx +++ b/packages/compass-home/src/components/home.spec.tsx @@ -22,7 +22,26 @@ const getComponent = (name: string) => { return TestComponent; }; -const createDataService = () => ({}); +const createDataService = () => ({ + getConnectionString() { + return { hosts: ['localhost:27020'] }; + }, + getConnectionOptions() { + return {}; + }, + getMongoClientConnectionOptions() { + return {}; + }, + getLastSeenTopology() { + return { + type: 'Unknown', + servers: [], + setName: 'foo', + }; + }, + on() {}, + off() {}, +}); describe('Home [Component]', function () { before(function () { @@ -112,6 +131,7 @@ describe('Home [Component]', function () { ); dataServiceDisconnectedSpy = sinon.fake.resolves(true); const dataService = { + ...createDataService(), disconnect: dataServiceDisconnectedSpy, addReauthenticationHandler: sinon.stub(), }; diff --git a/packages/compass-home/src/components/workspace.tsx b/packages/compass-home/src/components/workspace.tsx index 63a0b79970f..517546d70f7 100644 --- a/packages/compass-home/src/components/workspace.tsx +++ b/packages/compass-home/src/components/workspace.tsx @@ -4,6 +4,7 @@ import { css } from '@mongodb-js/compass-components'; import WorkspaceContent from './workspace-content'; import type Namespace from '../types/namespace'; import { useAppRegistryComponent } from 'hadron-app-registry'; +import { CompassShellPlugin } from '@mongodb-js/compass-shell'; const verticalSplitStyles = css({ width: '100vw', @@ -40,7 +41,6 @@ export default function Workspace({ namespace: Namespace; }): React.ReactElement { const SidebarComponent = useAppRegistryComponent('Sidebar.Component'); - const GlobalShellComponent = useAppRegistryComponent('Global.Shell'); return ( <> @@ -54,7 +54,7 @@ export default function Workspace({
- {GlobalShellComponent && } +
diff --git a/packages/compass-shell/package.json b/packages/compass-shell/package.json index c006cfd2222..dc2791e3106 100644 --- a/packages/compass-shell/package.json +++ b/packages/compass-shell/package.json @@ -25,6 +25,7 @@ ], "main": "dist/index.js", "compass:main": "src/index.ts", + "types": "dist/src/index.d.ts", "exports": { "browser": "./dist/browser.js", "require": "./dist/index.js" @@ -33,9 +34,11 @@ ".": "./src/index.ts" }, "scripts": { + "bootstrap": "npm run postcompile", "prepublishOnly": "npm run compile && compass-scripts check-exports-exist", "compile": "npm run webpack -- --mode production", "webpack": "webpack-compass", + "postcompile": "tsc --emitDeclarationOnly", "start": "npm run webpack serve -- --mode development", "analyze": "npm run webpack -- --mode production --analyze", "typecheck": "tsc --noEmit", @@ -58,18 +61,20 @@ "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-utils": "^0.5.5", - "@mongodb-js/mongodb-redux-common": "^2.0.15", "@mongosh/node-runtime-worker-thread": "^2.0.2", - "compass-preferences-model": "^2.15.6" + "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1" }, "peerDependencies": { "@mongodb-js/compass-user-data": "^0.1.9", "@mongodb-js/compass-components": "^1.19.0", "@mongodb-js/compass-logging": "^1.2.6", "@mongodb-js/compass-utils": "^0.5.5", - "@mongodb-js/mongodb-redux-common": "^2.0.15", "@mongosh/node-runtime-worker-thread": "^2.0.2", "compass-preferences-model": "^2.15.6", + "hadron-app-registry": "^9.0.14", + "mongodb-data-service": "^22.15.1", "react": "^17.0.2" }, "devDependencies": { @@ -85,9 +90,7 @@ "electron": "^25.9.3", "enzyme": "^3.11.0", "eslint": "^7.25.0", - "hadron-app-registry": "^9.0.14", "mocha": "^10.2.0", - "mongodb-data-service": "^22.15.0", "nyc": "^15.1.0", "prop-types": "^15.7.2", "react-dom": "^17.0.2", diff --git a/packages/compass-shell/src/components/compass-shell/compass-shell.tsx b/packages/compass-shell/src/components/compass-shell/compass-shell.tsx index 77109122a59..25b5a4a0ab2 100644 --- a/packages/compass-shell/src/components/compass-shell/compass-shell.tsx +++ b/packages/compass-shell/src/components/compass-shell/compass-shell.tsx @@ -304,9 +304,7 @@ export class CompassShell extends Component< export default connect((state: RootState) => ({ emitShellPluginOpened: () => { - if (state.appRegistry && state.appRegistry.globalAppRegistry) { - state.appRegistry.globalAppRegistry.emit('compass:compass-shell:opened'); - } + state.runtime.appRegistry?.emit('compass:compass-shell:opened'); }, runtime: state.runtime ? state.runtime.runtime : null, }))(withPreferences(CompassShell, ['enableShell'], React)); diff --git a/packages/compass-shell/src/index.ts b/packages/compass-shell/src/index.ts index fe0ad990d85..d2588801330 100644 --- a/packages/compass-shell/src/index.ts +++ b/packages/compass-shell/src/index.ts @@ -1,28 +1,32 @@ -import type AppRegistry from 'hadron-app-registry'; +import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; +import { createLoggerAndTelemetryLocator } from '@mongodb-js/compass-logging/provider'; +import { ShellPlugin, onActivated } from './plugin'; +import { registerHadronPlugin } from 'hadron-app-registry'; +import { dataServiceLocator } from 'mongodb-data-service/provider'; +import type { DataService } from 'mongodb-data-service'; -import createPlugin from './plugin'; - -const { store, Plugin } = createPlugin(); - -/** - * Activate all the components in the Compass Shell package. - * @param {Object} appRegistry - The appRegistry to activate this plugin with. - **/ -function activate(appRegistry: AppRegistry): void { - // Register the shell plugin's role in Compass. - appRegistry.registerComponent('Global.Shell', Plugin); - appRegistry.registerStore('CompassShell.Store', store); +function activate(): void { + // noop } -/** - * Deactivate all the components in the Compass Shell package. - * @param {Object} appRegistry - The appRegistry to deactivate this plugin with. - **/ -function deactivate(appRegistry: AppRegistry): void { - appRegistry.registerComponent('Global.Shell', Plugin); - appRegistry.deregisterStore('CompassShell.Store'); +function deactivate(): void { + // noop } -export default Plugin; +export const CompassShellPlugin = registerHadronPlugin< + unknown, + { logger: () => LoggerAndTelemetry; dataService: () => DataService } +>( + { + name: 'CompassShell', + component: ShellPlugin, + activate: onActivated, + }, + { + logger: createLoggerAndTelemetryLocator('COMPASS-SHELL'), + dataService: dataServiceLocator, + } +); + export { activate, deactivate }; export { default as metadata } from '../package.json'; diff --git a/packages/compass-shell/src/modules/index.ts b/packages/compass-shell/src/modules/index.ts index a45bfff591f..ee9ea4560d2 100644 --- a/packages/compass-shell/src/modules/index.ts +++ b/packages/compass-shell/src/modules/index.ts @@ -1,21 +1,14 @@ import { combineReducers } from 'redux'; -import appRegistry from '@mongodb-js/mongodb-redux-common/app-registry'; -import type { AppRegistry } from 'hadron-app-registry'; import type { RuntimeAction, RuntimeState } from './runtime'; import runtime from './runtime'; export interface RootState { - appRegistry: { - globalAppRegistry: AppRegistry | null; - localAppRegistry: AppRegistry | null; - }; runtime: RuntimeState; } export type RootAction = RuntimeAction; const reducer = combineReducers({ - appRegistry, runtime, }); diff --git a/packages/compass-shell/src/plugin.spec.jsx b/packages/compass-shell/src/plugin.spec.tsx similarity index 55% rename from packages/compass-shell/src/plugin.spec.jsx rename to packages/compass-shell/src/plugin.spec.tsx index 71bc148c474..35a8c094dd1 100644 --- a/packages/compass-shell/src/plugin.spec.jsx +++ b/packages/compass-shell/src/plugin.spec.tsx @@ -1,11 +1,12 @@ import React from 'react'; +import type { ReactWrapper } from 'enzyme'; import { mount } from 'enzyme'; -import { EventEmitter } from 'events'; import { expect } from 'chai'; import { CompassShell } from './components/compass-shell'; -import createPlugin from './plugin'; -import CompassShellStore from './stores'; +import { CompassShellPlugin } from './index'; +import { AppRegistryProvider, globalAppRegistry } from 'hadron-app-registry'; +import { DataServiceProvider } from 'mongodb-data-service/provider'; // Wait until a component is present that is rendered in a limited number // of microtask queue iterations. In particular, this does *not* wait for the @@ -26,35 +27,51 @@ async function waitForAsyncComponent(wrapper, Component, attempts = 10) { } describe('CompassShellPlugin', function () { - it('returns a renderable plugin', async function () { - const { Plugin } = createPlugin(); + const fakeDataService = { + getMongoClientConnectionOptions() {}, + } as any; + let wrapper: ReactWrapper | null; - const wrapper = mount(); + afterEach(() => { + wrapper?.unmount(); + wrapper = null; + }); + it('returns a renderable plugin', async function () { + wrapper = mount( + + {/* global */} + + {/* local */} + + + + + + ); const component = await waitForAsyncComponent(wrapper, CompassShell); expect(component.exists()).to.equal(true); }); - it('returns a CompassShellStore store', function () { - const { store } = createPlugin(); - const appRegistry = new EventEmitter(); - store.onActivated(appRegistry); - expect(store).to.be.instanceOf(CompassShellStore); - }); - it('emits an event on the app registry when it is expanded', async function () { - const { store, Plugin } = createPlugin(); - - const appRegistry = new EventEmitter(); let eventOccured = false; - appRegistry.on('compass:compass-shell:opened', () => { + globalAppRegistry.on('compass:compass-shell:opened', () => { eventOccured = true; }); - store.onActivated(appRegistry); + wrapper = mount( + + {/* global */} + + {/* local */} + + + + + + ); - const wrapper = mount(); const shellComponentWrapper = await waitForAsyncComponent( wrapper, CompassShell diff --git a/packages/compass-shell/src/plugin.tsx b/packages/compass-shell/src/plugin.tsx index a8731971f91..992440c407a 100644 --- a/packages/compass-shell/src/plugin.tsx +++ b/packages/compass-shell/src/plugin.tsx @@ -1,50 +1,64 @@ import React, { useState, useRef, useEffect } from 'react'; -import { Provider } from 'react-redux'; import CompassShellStore from './stores'; import { HistoryStorage } from './modules/history-storage'; import type CompassShellComponentType from './components/compass-shell'; +import type AppRegistry from 'hadron-app-registry'; +import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging'; +import type { DataService } from 'mongodb-data-service'; -function createPlugin() { - const store = new CompassShellStore(); - - function CompassShellPlugin() { - const [ShellComponent, setShellComponent] = useState< - typeof CompassShellComponentType | null - >(null); - const historyStorage = useRef(null); +export function ShellPlugin() { + const [ShellComponent, setShellComponent] = useState< + typeof CompassShellComponentType | null + >(null); + const historyStorage = useRef(null); - if (!historyStorage.current) { - historyStorage.current = new HistoryStorage(); - } + if (!historyStorage.current) { + historyStorage.current = new HistoryStorage(); + } - useEffect(() => { - let mounted = true; + useEffect(() => { + let mounted = true; - void import(/* webpackPreload: true */ './components/compass-shell').then( - ({ default: Component }) => { - if (mounted) { - setShellComponent(Component); - } + void import(/* webpackPreload: true */ './components/compass-shell').then( + ({ default: Component }) => { + if (mounted) { + setShellComponent(Component); } - ); - - return () => { - mounted = false; - }; - }, []); - - if (ShellComponent) { - return ( - - - - ); - } - - return null; + } + ); + + return () => { + mounted = false; + }; + }, []); + + if (ShellComponent) { + return ; } - return { store, Plugin: CompassShellPlugin }; + return null; } -export default createPlugin; +export function onActivated( + _: unknown, + { + globalAppRegistry, + logger, + dataService, + }: { + globalAppRegistry: AppRegistry; + logger: LoggerAndTelemetry; + dataService: DataService; + } +) { + const store = new CompassShellStore(); + const deactivate = store.onActivated({ + globalAppRegistry, + logger, + dataService, + }); + return { + store: store.reduxStore, + deactivate, + }; +} diff --git a/packages/compass-shell/src/stores/store.spec.ts b/packages/compass-shell/src/stores/store.spec.ts index e4177eb15b6..40eff278246 100644 --- a/packages/compass-shell/src/stores/store.spec.ts +++ b/packages/compass-shell/src/stores/store.spec.ts @@ -3,6 +3,7 @@ import { expect } from 'chai'; import { WorkerRuntime } from '../modules/worker-runtime'; import CompassShellStore from './'; +import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging'; function createMockDataService() { return { @@ -17,45 +18,41 @@ function createMockDataService() { } describe('CompassShellStore [Store]', function () { - let store; - let appRegistry; + let store: CompassShellStore; + let appRegistry: EventEmitter; + let deactivate: () => void; const getRuntimeState = () => store.reduxStore.getState().runtime; beforeEach(function () { store = new CompassShellStore(); appRegistry = new EventEmitter(); - store.onActivated(appRegistry); + deactivate = store.onActivated({ + globalAppRegistry: appRegistry, + logger: createLoggerAndTelemetry('COMPASS-SHELL'), + dataService: createMockDataService(), + } as any); }); afterEach(async function () { const { runtime } = getRuntimeState(); - if (runtime && runtime.terminate) { - await runtime.terminate(); - } + await runtime?.terminate(); }); describe('appRegistry', function () { it('sets the global appRegistry', function () { - expect(store.reduxStore.getState().appRegistry).to.not.equal(null); - expect( - store.reduxStore.getState().appRegistry.globalAppRegistry - ).to.be.instanceOf(EventEmitter); + expect(store.reduxStore.getState().runtime.appRegistry).to.not.equal( + null + ); + expect(store.reduxStore.getState().runtime.appRegistry).to.be.instanceOf( + EventEmitter + ); }); }); describe('runtime', function () { - it('has initialized runtime state', function () { - const runtimeState = getRuntimeState(); - - expect(runtimeState.error).to.equal(null); - expect(runtimeState.runtime).to.equal(null); - }); - it('sets runtime on data-service-connected', function () { - appRegistry.emit('data-service-connected', null, createMockDataService()); - let runtimeState = getRuntimeState(); expect(runtimeState.error).to.equal(null); @@ -69,7 +66,6 @@ describe('CompassShellStore [Store]', function () { }); it('emits mongosh events to the appRegistry', async function () { - appRegistry.emit('data-service-connected', null, createMockDataService()); store.onEnableShellChanged(true); let eventReceived = false; appRegistry.on('mongosh:setCtx', () => { @@ -80,21 +76,11 @@ describe('CompassShellStore [Store]', function () { // Any command will do, just making sure we waited for the runtime to // become available - await runtimeState.runtime.evaluate('help'); + await runtimeState.runtime?.evaluate('help'); expect(eventReceived).to.equal(true); }); - it('sets error if data-service-connected has one', function () { - const error = new Error(); - appRegistry.emit('data-service-connected', error, null); - - const runtimeState = getRuntimeState(); - - expect(runtimeState.error).to.equal(error); - expect(runtimeState.runtime).to.equal(null); - }); - it('does not change state if dataService is the same', function () { const fakeDataService = createMockDataService(); @@ -107,8 +93,8 @@ describe('CompassShellStore [Store]', function () { expect(runtimeState1).to.deep.equal(runtimeState2); }); - it('resets the runtime on data-service-disconnected', function () { - appRegistry.emit('data-service-disconnected'); + it('resets the runtime on deactivate', function () { + deactivate(); const runtimeState = getRuntimeState(); expect(runtimeState.runtime).to.equal(null); diff --git a/packages/compass-shell/src/stores/store.ts b/packages/compass-shell/src/stores/store.ts index 6e64e4cc565..f37a8d2db7f 100644 --- a/packages/compass-shell/src/stores/store.ts +++ b/packages/compass-shell/src/stores/store.ts @@ -3,15 +3,12 @@ import { createStore } from 'redux'; import type { RootAction, RootState } from '../modules'; import reducer from '../modules'; import { changeEnableShell, setupRuntime } from '../modules/runtime'; -import { globalAppRegistryActivated } from '@mongodb-js/mongodb-redux-common/app-registry'; import { setupLoggerAndTelemetry } from '@mongosh/logging'; -import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging'; +import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging'; import preferences from 'compass-preferences-model'; import type AppRegistry from 'hadron-app-registry'; import type { DataService } from 'mongodb-data-service'; -const { log, debug, track } = createLoggerAndTelemetry('COMPASS-SHELL'); - export default class CompassShellStore { reduxStore: Store; @@ -21,23 +18,27 @@ export default class CompassShellStore { globalAppRegistry: AppRegistry | null = null; - onActivated(appRegistry: AppRegistry) { + onActivated({ + globalAppRegistry, + logger: { log, track, debug }, + dataService, + }: { + globalAppRegistry: AppRegistry; + logger: LoggerAndTelemetry; + dataService: DataService; + }): () => void { debug('activated'); - this.globalAppRegistry = appRegistry; - - appRegistry.on('data-service-connected', this.onDataServiceConnected); - - appRegistry.on('data-service-disconnected', this.onDataServiceDisconnected); + this.globalAppRegistry = globalAppRegistry; - preferences.onPreferenceValueChanged( + const unsubscribePreference = preferences.onPreferenceValueChanged( 'enableShell', this.onEnableShellChanged ); this.onEnableShellChanged(preferences.getPreferences().enableShell); setupLoggerAndTelemetry( - appRegistry, + globalAppRegistry, log.unbound, { identify: () => { @@ -60,23 +61,20 @@ export default class CompassShellStore { ); // We also don't need to pass a proper user id, since that is // handled by the Compass tracking code. - appRegistry.emit('mongosh:new-user', ''); + globalAppRegistry.emit('mongosh:new-user', ''); // Set the global app registry in the store. - this.reduxStore.dispatch(globalAppRegistryActivated(appRegistry)); + this.reduxStore.dispatch( + setupRuntime(null, dataService, this.globalAppRegistry) + ); + + return () => { + unsubscribePreference(); + this.reduxStore.dispatch(setupRuntime(null, null, null)); + }; } onEnableShellChanged = (value: boolean) => { this.reduxStore.dispatch(changeEnableShell(value)); }; - - onDataServiceConnected = (error: null | Error, dataService: DataService) => { - this.reduxStore.dispatch( - setupRuntime(error, dataService, this.globalAppRegistry) - ); - }; - - onDataServiceDisconnected = () => { - this.reduxStore.dispatch(setupRuntime(null, null, null)); - }; }