Skip to content

Commit

Permalink
feat: add config for engines
Browse files Browse the repository at this point in the history
  • Loading branch information
jarekdanielak committed Dec 6, 2024
1 parent c585fd4 commit 71b86f9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
25 changes: 23 additions & 2 deletions src/cloud-element-templates/ElementTemplates.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
isArray,
isFunction
} from 'min-dash';

import {
getTemplateId,
getTemplateVersion
Expand All @@ -9,10 +14,17 @@ import { default as DefaultElementTemplates } from '../element-templates/Element
* Registry for element templates.
*/
export default class ElementTemplates extends DefaultElementTemplates {
constructor(templateElementFactory, commandStack, eventBus, modeling, injector) {
constructor(templateElementFactory, commandStack, eventBus, modeling, injector, config) {
super(commandStack, eventBus, modeling, injector);

this._templateElementFactory = templateElementFactory;
this._config = {};

This comment has been minimized.

Copy link
@barmac

barmac Dec 6, 2024

Member

Notice that if will always be truthy because the test checks this._config which is always assigned {}.
I'd suggest to write the tests for this change as they need to be provided anyway.

this._engines = {};

if (!(isArray(this._config) || isFunction(this._config))) {
this._config = config || {};
this._engines = this._config.engines;
}
}

_getTemplateId(element) {
Expand Down Expand Up @@ -75,12 +87,21 @@ export default class ElementTemplates extends DefaultElementTemplates {

return context.element;
}

getEngines() {
return this._engines;
}

setEngines(engines) {
this._engines = engines;
}
}

ElementTemplates.$inject = [
'templateElementFactory',
'commandStack',
'eventBus',
'modeling',
'injector'
'injector',
'config.elementTemplates',
];
10 changes: 8 additions & 2 deletions src/cloud-element-templates/ElementTemplatesLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { Validator } from './Validator';

import { default as TemplatesLoader } from '../element-templates/ElementTemplatesLoader';

/**
* @param {Object|Array<TemplateDescriptor>|Function} config
* @param {EventBus} eventBus
* @param {ElementTemplates} elementTemplates
* @param {Moddle} moddle
*/
export default class ElementTemplatesLoader extends TemplatesLoader {
constructor(loadTemplates, eventBus, elementTemplates, moddle) {
constructor(config, eventBus, elementTemplates, moddle) {

super(loadTemplates, eventBus, elementTemplates, moddle);
super(config, eventBus, elementTemplates, moddle);

this._elementTemplates = elementTemplates;
}
Expand Down
15 changes: 12 additions & 3 deletions src/element-templates/ElementTemplatesLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
isFunction,
isUndefined
isUndefined,
isArray,
} from 'min-dash';

import { Validator } from './Validator';
Expand All @@ -20,12 +21,20 @@ import { Validator } from './Validator';
* @param {Moddle} moddle
*/
export default class ElementTemplatesLoader {
constructor(loadTemplates, eventBus, elementTemplates, moddle) {
this._loadTemplates = loadTemplates;
constructor(config, eventBus, elementTemplates, moddle) {
this._loadTemplates;
this._eventBus = eventBus;
this._elementTemplates = elementTemplates;
this._moddle = moddle;

if (isArray(config) || isFunction(config)) {
this._loadTemplates = config;
}

if (config && config.loadTemplates) {
this._loadTemplates = config.loadTemplates;
}

eventBus.on('diagram.init', () => {
this.reload();
});
Expand Down

0 comments on commit 71b86f9

Please sign in to comment.