-
Notifications
You must be signed in to change notification settings - Fork 0
/
component.js
61 lines (46 loc) · 1.12 KB
/
component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const DEEP_KEYS = new Set(['class', 'attr', 'prop', 'data', 'css', 'on', 'onCapture', 'keydown', 'keyup']);
class SatoriComponent {
constructor(view, state) {
this.view = view;
const defaultState = this.getDefaultState();
this.state = view.proxy(defaultState ? Object.assign(defaultState, state) : state);
this.initialize();
}
initialize() {
}
render() {
}
getDefaultState() {
}
mount(container) {
this.view.content(container, this);
return this;
}
el(name, mods) {
return this.mods(mods, this.constructor.name + '_' + name);
}
mods(mods, className) {
className = className || this.constructor.name;
const classes = {[className]: true};
if (mods) {
for (let mod in mods) {
classes[className + '-' + mod] = mods[mod];
}
}
return classes;
}
defaults(defaults, options) {
const result = Object.assign({}, defaults, options);
for (let key in defaults) {
if (!DEEP_KEYS.has(key)) {
continue;
}
result[key] = Object.assign({}, defaults[key], options[key]);
}
return result;
}
}
if (typeof module !== 'undefined') {
module.exports = SatoriComponent;
}