Completed
Push — master ( 2f8415...e6e0b0 )
by Rain
02:22
created

dev/Component/Abstract.js   A

Size

Lines of Code 52

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 52
rs 10
noi 0
1
2
import $ from '$';
3
import ko from 'ko';
4
import {isUnd} from 'Common/Utils';
5
6
class AbstractComponent
7
{
8
	disposable = [];
9
10
	dispose() {
11
		this.disposable.forEach((funcToDispose) => {
12
			if (funcToDispose && funcToDispose.dispose)
13
			{
14
				funcToDispose.dispose();
15
			}
16
		});
17
	}
18
}
19
20
/**
21
 * @param {*} ClassObject
22
 * @param {string} templateID = ''
23
 * @returns {Object}
24
 */
25
const componentExportHelper = (ClassObject, templateID = '') => ({
26
	template: templateID ? {element: templateID} : '<b></b>',
27
	viewModel: {
28
		createViewModel: (params, componentInfo) => {
29
30
			params = params || {};
31
			params.element = null;
32
33
			if (componentInfo && componentInfo.element)
34
			{
35
				params.component = componentInfo;
36
				params.element = $(componentInfo.element);
37
38
				require('Common/Translator').i18nToNodes(params.element);
39
40
				if (!isUnd(params.inline) && ko.unwrap(params.inline))
41
				{
42
					params.element.css('display', 'inline-block');
43
				}
44
			}
45
46
			return new ClassObject(params);
47
		}
48
	}
49
});
50
51
export {AbstractComponent, componentExportHelper};
52