Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

feat: pre-registration hook in extension manager #48

Merged
merged 11 commits into from
Jun 27, 2019
19 changes: 17 additions & 2 deletions src/extensions/ExtensionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ export default class ExtensionManager {
}

/**
* An array of extensions, or an array of arrays that contains extension
* configuration pairs.
*
* @param {Object[]} extensions - Array of extensions
*/
registerExtensions(extensions) {
extensions.forEach(extension => {
this.registerExtension(extension);
const hasConfiguration = Array.isArray(extension);

if (hasConfiguration) {
const [ohifExtension, configuration] = extensions;
this.registerExtension(ohifExtension, configuration);
} else {
this.registerExtension(extension);
}
});
}

/**
*
* TODO: Id Management: SopClassHandlers currently refer to viewport module by id; setting the extension id as viewport module id is a workaround for now
* @param {Object} extension
* @param {Object} configuration
*/
registerExtension(extension) {
registerExtension(extension, configuration = {}) {
if (!extension) {
log.warn(
'Attempting to register a null/undefined extension. Exiting early.'
Expand All @@ -54,6 +64,11 @@ export default class ExtensionManager {
return;
}

// preRegistrationHook
if (extension.preRegistration) {
extension.preRegistration(configuration);
}

// Register Modules
this.moduleTypeNames.forEach(moduleType => {
const extensionModule = this._getExtensionModule(
Expand Down