snappymail/dev/Component/Abstract.js
djmaze e7180a86ce Made eslint using 'browser' environment and added globals, because RainLoop is used in browsers.
This also allowed to remove all webpack 'externals' overhead.
2020-08-12 00:25:36 +02:00

45 lines
1,010 B
JavaScript

import ko from 'ko';
import { i18nToNodes } from 'Common/Translator';
class AbstractComponent {
disposable = [];
dispose() {
this.disposable.forEach((funcToDispose) => {
if (funcToDispose && funcToDispose.dispose) {
funcToDispose.dispose();
}
});
}
}
/**
* @param {*} ClassObject
* @param {string} templateID = ''
* @returns {Object}
*/
const componentExportHelper = (ClassObject, templateID = '') => ({
template: templateID ? { element: templateID } : '<b></b>',
viewModel: {
createViewModel: (params, componentInfo) => {
params = params || {};
params.element = null;
if (componentInfo && componentInfo.element) {
params.component = componentInfo;
params.element = jQuery(componentInfo.element);
i18nToNodes(params.element);
if (undefined !== params.inline && ko.unwrap(params.inline)) {
params.element.css('display', 'inline-block');
}
}
return new ClassObject(params);
}
}
});
export { AbstractComponent, componentExportHelper };