-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromiseWrapperExample.js
More file actions
43 lines (41 loc) · 1.13 KB
/
PromiseWrapperExample.js
File metadata and controls
43 lines (41 loc) · 1.13 KB
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
const finishedLoadingDom = new Promise((resolve, reject) => {
const includeHTML = () => {
const tag = document.getElementsByTagName("include")
for (let i = 0; i < tag.length; i++) {
const node = tag[i]
const file = node.getAttribute("DS-Template")
if (file) {
console.log('1st load :', file);
fetch(file).then(resp => resp.text())
.then(data => {
// throw 'Reject Promise Test'
node.innerHTML = data
})
.then( () => {
node.removeAttribute("DS-Template")
includeHTML()
}).catch(error => reject(error))
return
}
}
resolve()
};console.time();includeHTML()
})
finishedLoadingDom
.then(() => {
[
'./js/populate.js',
'./js/DS-Paginate.js',
'./js/DS-SideBar.js'
].forEach((src) => {
const script = document.createElement('script')
script.src = src
console.log('2nd Append head :', src);
document.head.appendChild(script)
})
})
.then(() => {
console.log('3rd : your code here!')
console.timeEnd()
})
.catch(error => console.error('includeHTML Error : ', error))