initialize methods for app configs
This commit is contained in:
parent
62cba34b0c
commit
a5e3f27cfd
83
platform/viewer/src/appInit.js
Normal file
83
platform/viewer/src/appInit.js
Normal file
@ -0,0 +1,83 @@
|
||||
import {
|
||||
CommandsManager,
|
||||
ExtensionManager,
|
||||
ServicesManager,
|
||||
// HotkeysManager,
|
||||
UINotificationService,
|
||||
UIModalService,
|
||||
UIDialogService,
|
||||
// MeasurementService,
|
||||
// utils,
|
||||
// redux as reduxOHIF,
|
||||
} from '@ohif/core';
|
||||
|
||||
import buildModeRoutes from './routes/buildModeRoutes';
|
||||
|
||||
/**
|
||||
* @param {object|func} appConfigOrFunc - application configuration, or a function that returns application configuration
|
||||
* @param {object[]} defaultExtensions - array of extension objects
|
||||
*/
|
||||
function appInit(appConfigOrFunc, defaultExtensions) {
|
||||
const appConfig = {
|
||||
...(typeof appConfigOrFunc === 'function'
|
||||
? config({ servicesManager })
|
||||
: appConfigOrFunc),
|
||||
};
|
||||
|
||||
const commandsManagerConfig = {
|
||||
/** Used by commands to inject `viewports` from "redux" */
|
||||
getAppState: () => store.getState(),
|
||||
/** Used by commands to determine active context */
|
||||
getActiveContexts: () => getActiveContexts(store.getState()),
|
||||
};
|
||||
const commandsManager = new CommandsManager(commandsManagerConfig);
|
||||
const servicesManager = new ServicesManager();
|
||||
// const hotkeysManager = new HotkeysManager(commandsManager, servicesManager);
|
||||
const extensionManager = new ExtensionManager({
|
||||
commandsManager,
|
||||
servicesManager,
|
||||
appConfig,
|
||||
api: {
|
||||
contexts: CONTEXTS,
|
||||
hooks: {
|
||||
useAppContext,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
servicesManager.registerServices([
|
||||
UINotificationService,
|
||||
UIModalService,
|
||||
UIDialogService,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Example: [ext1, ext2, ext3]
|
||||
* Example2: [[ext1, config], ext2, [ext3, config]]
|
||||
*/
|
||||
extensionManager.registerExtensions([
|
||||
...defaultExtensions,
|
||||
...appConfig.extensions,
|
||||
]);
|
||||
|
||||
// TODO: Init global hotkeys, or the hotkeys manager?
|
||||
// TODO: We no longer use `utils.addServer`
|
||||
// TODO: We no longer init webWorkers at app level
|
||||
// TODO: We no longer init the user Manager
|
||||
|
||||
// TODO: After extensions are registered, add modes and datasources to buildModeRoutes.js
|
||||
|
||||
const { modes } = appConfig;
|
||||
|
||||
const routes = buildModeRoutes(modes, extensionManager);
|
||||
|
||||
return {
|
||||
appConfig,
|
||||
commandsManager,
|
||||
extensionManager,
|
||||
servicesManager,
|
||||
routes,
|
||||
};
|
||||
}
|
||||
|
||||
export default appInit;
|
||||
Loading…
Reference in New Issue
Block a user