-
Notifications
You must be signed in to change notification settings - Fork 0
/
editdom.js
60 lines (54 loc) · 1.55 KB
/
editdom.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
function CreateEle(tag, options = {}) {
let element = document.createElement(tag)
Object.keys(options).forEach((key) => {
element[key] = options[key]
});
element.InsertEle = function(innerElement) {
this.appendChild(innerElement)
return this
}
element.InsertEles = function(innerElements = []) {
innerElements.forEach(innerElement => this.appendChild(innerElement))
return this
}
element.Empty = function() {
while(element.firstElementChild) {
element.firstElementChild.remove();
}
}
return element
}
function InsertEle(outerElement, innerElement) {
outerElement.appendChild(innerElement)
return outerElement
}
function InsertEles(outerElement, innerElements = []) {
innerElements.forEach(innerElement => outerElement.appendChild(innerElement))
return outerElement
}
function LoadScript(url)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);
}
function Observer(intailData) {
obersver = {
data: intailData,
Subscribe: function (lambda) {
this.subscribers.push(lambda)
},
subscribers: [],
Update: function(data) {
this.data = data
this.Publish()
},
Publish: function() {
//make async
this.subscribers.forEach((subscriber) => subscriber(this.data))
}
}
return obersver
}