From c05058a0f57b1c6513546be84985a6912e9e2986 Mon Sep 17 00:00:00 2001 From: dannyrb Date: Tue, 9 Jul 2019 12:56:08 -0400 Subject: [PATCH] Better entrypoint for extensions --- lerna.json | 2 +- platform/viewer/src/App.js | 15 ++++----------- platform/viewer/src/index.js | 33 +++++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lerna.json b/lerna.json index bcdca0415..583f0544c 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "packages": ["packages/*"], + "packages": ["extensions/*", "platform/*"], "npmClient": "yarn", "useWorkspaces": true, "version": "independent" diff --git a/platform/viewer/src/App.js b/platform/viewer/src/App.js index 306276590..b689362d8 100644 --- a/platform/viewer/src/App.js +++ b/platform/viewer/src/App.js @@ -1,5 +1,5 @@ import './config'; -// Imported flat feature since is not transpiled for old browser versions +// Polyfills import 'core-js/features/array/flat'; import 'core-js/stable'; import 'regenerator-runtime/runtime'; @@ -23,7 +23,6 @@ import initCornerstoneTools from './initCornerstoneTools.js'; import { GenericViewerCommands, MeasurementsPanel } from './appExtensions'; import OHIFCornerstoneExtension from '@ohif/extension-cornerstone'; import OHIFStandaloneViewer from './OHIFStandaloneViewer'; -// ~~ EXTENSIONS import { OidcProvider } from 'redux-oidc'; import PropTypes from 'prop-types'; import { Provider } from 'react-redux'; @@ -131,6 +130,9 @@ class App extends Component { } } +/** + * @param + */ function _initExtensions(extensions) { const defaultExtensions = [ GenericViewerCommands, @@ -140,13 +142,6 @@ function _initExtensions(extensions) { const mergedExtensions = defaultExtensions.concat(extensions); extensionManager.registerExtensions(mergedExtensions); - // [ - // OHIFVTKExtension, - // OHIFDicomPDFExtension, - // OHIFDicomHtmlExtension, - // OHIFDicomMicroscopyExtension, - // ] - // Must run after extension commands are registered if (window.config.hotkeys) { hotkeysManager.setHotkeys(window.config.hotkeys, true); @@ -160,6 +155,4 @@ function _initServers(servers) { } export default App; - -// Make our managers accessible export { commandsManager, extensionManager, hotkeysManager }; diff --git a/platform/viewer/src/index.js b/platform/viewer/src/index.js index 4999f23e9..810ac0876 100644 --- a/platform/viewer/src/index.js +++ b/platform/viewer/src/index.js @@ -1,26 +1,47 @@ /** * Entry point for development and production PWA builds. - * Packaged (NPM) builds go through `index_publish.js` + * Packaged (NPM) builds go through `index-umd.js` */ import App from './App.js'; import React from 'react'; import ReactDOM from 'react-dom'; -// EXTENSIONS +/** + * EXTENSIONS + * ================= + * + * Importing and modifying the extensions our app uses HERE allows us to leverage + * tree shaking and a few other niceties. However, by including them here they become + * "baked in" to the published application. + * + * Depending on your use case/needs, you may want to consider not adding any extensions + * by default HERE, and instead provide them via the configuration specified at + * `window.config.extensions`, or by using the exported `App` component, and passing + * in your extensions as props. + */ import OHIFVTKExtension from '@ohif/extension-vtk'; import OHIFDicomHtmlExtension from '@ohif/extension-dicom-html'; import OHIFDicomMicroscopyExtension from '@ohif/extension-dicom-microscopy'; import OHIFDicomPDFExtension from '@ohif/extension-dicom-pdf'; // Default Settings -window.config = window.config || {}; -window.config.extensions = [OHIFVTKExtension]; - +let config = {}; const appDefaults = { routerBasename: '/', relativeWebWorkerScriptsPath: '', }; -const appProps = Object.assign({}, appDefaults, window.config); + +if (window) { + config = window.config || {}; + config.extensions = [ + OHIFVTKExtension, + OHIFDicomHtmlExtension, + OHIFDicomMicroscopyExtension, + OHIFDicomPDFExtension, + ]; +} + +const appProps = Object.assign({}, appDefaults, config); // Create App const app = React.createElement(App, appProps, null);