Skip to content

Commit 952d0c8

Browse files
committed
Revert "Fix eslint errors"
This reverts commit 3bdd72a.
1 parent c13d3d5 commit 952d0c8

File tree

2 files changed

+57
-50
lines changed

2 files changed

+57
-50
lines changed

.eslintrc.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@
22
"extends": [
33
"plugin:github/es6",
44
"plugin:github/browser"
5-
],
6-
"parserOptions": {
7-
"ecmaVersion": 2017
8-
}
5+
]
96
}

include-fragment-element.js

+56-46
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,28 @@ export class IncludeFragmentElement extends HTMLElement {
88
})
99
}
1010

11-
_fire(name) {
12-
setTimeout(
13-
function() {
14-
const event = this.ownerDocument.createEvent('Event')
15-
event.initEvent(name, false, false)
16-
this.dispatchEvent(event)
17-
}.bind(this),
18-
0
19-
)
11+
_fire(name, target) {
12+
setTimeout(function() {
13+
const event = target.ownerDocument.createEvent('Event')
14+
event.initEvent(name, false, false)
15+
target.dispatchEvent(event)
16+
}, 0)
2017
}
2118

22-
async _handleData(data) {
23-
try {
24-
const html = await data
25-
const parentNode = this.parentNode
26-
if (parentNode) {
27-
this.insertAdjacentHTML('afterend', html)
28-
parentNode.removeChild(this)
29-
}
30-
} catch (err) {
31-
// eslint-disable-next-line no-console
32-
console.log(err)
33-
this.classList.add('is-error')
34-
}
19+
_handleData(data) {
20+
return data.then(
21+
function(html) {
22+
const parentNode = this.parentNode
23+
if (parentNode) {
24+
this.insertAdjacentHTML('afterend', html)
25+
parentNode.removeChild(this)
26+
}
27+
}.bind(this),
28+
function(err) {
29+
console.log(err)
30+
this.classList.add('is-error')
31+
}.bind(this)
32+
)
3533
}
3634

3735
static get observedAttributes() {
@@ -115,30 +113,42 @@ export class IncludeFragmentElement extends HTMLElement {
115113
})
116114
}
117115

118-
async _load() {
119-
const request = this._request()
120-
this._fire('loadstart')
121-
const response = await this._fetch(request)
122-
123-
if (response.status !== 200) {
124-
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
125-
}
126-
127-
const ct = response.headers.get('Content-Type')
128-
if (!ct || !ct.match(/^text\/html/)) {
129-
throw new Error(`Failed to load resource: expected text/html but was ${ct}`)
130-
}
131-
132-
try {
133-
const data = await response.text()
134-
this._fire('load')
135-
this._fire('loadend')
136-
return data
137-
} catch (error) {
138-
this._fire('error')
139-
this._fire('loadend')
140-
throw error
141-
}
116+
_load() {
117+
const self = this
118+
119+
return Promise.resolve()
120+
.then(function() {
121+
const request = self._request()
122+
self._fire('loadstart', self)
123+
return self._fetch(request)
124+
})
125+
.then(function(response) {
126+
if (response.status !== 200) {
127+
throw new Error(`Failed to load resource: the server responded with a status of ${response.status}`)
128+
}
129+
130+
const ct = response.headers.get('Content-Type')
131+
if (!ct || !ct.match(/^text\/html/)) {
132+
throw new Error(`Failed to load resource: expected text/html but was ${ct}`)
133+
}
134+
135+
return response
136+
})
137+
.then(function(response) {
138+
return response.text()
139+
})
140+
.then(
141+
function(data) {
142+
self._fire('load', self)
143+
self._fire('loadend', self)
144+
return data
145+
},
146+
function(error) {
147+
self._fire('error', self)
148+
self._fire('loadend', self)
149+
throw error
150+
}
151+
)
142152
}
143153

144154
_fetch(request) {

0 commit comments

Comments
 (0)