snappymail/dev/Component/Abstract.js
djmaze ea48f5060b isArray to native Array.isArray
isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
2020-07-29 21:49:41 +02:00

47 lines
1 KiB
JavaScript

import $ from '$';
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 = $(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 };