-
Notifications
You must be signed in to change notification settings - Fork 0
/
wso-settings-builder.js
66 lines (59 loc) · 1.6 KB
/
wso-settings-builder.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
62
63
64
65
66
(function () {
var eventsList;
class ObserverEvent {
constructor(name, initialAttrs) {
this.name = name;
this.init(Object.assign({}, initialAttrs));
}
init(attrs) {
if (attrs.alias) {
this.setAlias(attrs.alias);
}
if (attrs.target) {
this.setTarget(attrs.target);
}
if (attrs.attrs) {
this.setAttrs(attrs.attrs);
}
}
setAlias(alias) {
this.alias = alias;
return this;
}
setTarget(target) {
this.target = target;
return this;
}
setAttrs(attrs) {
this.attrs = attrs;
return this;
}
toString() {
var pureObj = Object.assign({}, this);
var mapper = {};
mapper[pureObj.name] = pureObj;
return JSON.stringify(mapper);
}
}
class EventsList {
constructor() {
this.events = [];
}
push(item) {
this.events.push(item);
}
toString() {
return '[' + this.events.map(function (item) {
return item.toString();
}).join(', ') + ']';
}
}
eventsList = new EventsList();
eventsList.push(new ObserverEvent('pageload'));
eventsList.push(new ObserverEvent('url_change'));
eventsList.push(new ObserverEvent('click', {
target: 'h1',
attrs: ['data-id', 'data-tags']
}));
console.log('eventsList', eventsList.toString());
})();